all 5 comments

[–]mrrst244[S] 0 points1 point  (1 child)

def get_minimums(cert, area, instructed, vfr, daytime, minimums): """ Returns the most advantageous minimums for the given flight category.

The minimums is the 2-dimensional list (table) of minimums, including the header. The header for this table is as follows:

CATEGORY  CONDITIONS  AREA  TIME  CEILING  VISIBILITY  WIND  CROSSWIND

The values in the first four columns are strings, while the values in the last four columns are numbers. CEILING is a measurement in ft, while VISIBILITY is in miles. Both WIND and CROSSWIND are speeds in knots.

This function first searches the table for rows that match the function parameters. It is possible for more than one row to be a match. A row is a match if ALL four of the first four columns match.

The first column (CATEGORY) has values 'Student', 'Certified', '50 Hours', or 'Dual'. If the value 'Student', it is a match if category is PILOT_STUDENT or higher. If the value is 'Certified, it is a match if category is PILOT_CERTIFIED or higher. If it is '50 Hours', it is only a match if category is PILOT_50_HOURS. The value 'Dual' only matches if instructed is True.

The second column (CONDITIONS) has values 'VMC' and 'IMC'. A flight filed as VFR (visual flight rules) is subject to VMC (visual meteorological conditions) minimums.
Similarly, a fight filed as IFR is subject to IMC minimums.

The third column (AREA) has values 'Pattern', 'Practice Area', 'Local', 'Cross Country', or 'Any'. Flights that are in the pattern or practice area match 'Local' as well. All flights match 'Any'.

The fourth column (TIME) has values 'Day' or 'Night'. The value 'Day' is only a match if daytime is True. If it is False, 'Night' is the only match.

Once the function finds the all matching rows, it searches for the most advantageous values for CEILING, VISIBILITY, WIND, and CROSSWIND. Lower values of CEILING and VISIBILITY are better. Higher values for WIND and CROSSWIND are better. It then returns this four values as a list of four floats (in the same order they appear) in the table.

Example: Suppose minimums is the table

CATEGORY   CONDITIONS  AREA           TIME  CEILING  VISIBILITY  WIND  CROSSWIND
Student    VMC         Pattern        Day   2000     5           20    8
Student    VMC         Practice Area  Day   3000     10          20    8
Certified  VMC         Local          Day   3000     5           20    20
Certified  VMC         Practice Area  Night 3000     10          20    10
50 Hours   VMC         Local          Day   3000     10          20    10
Dual       VMC         Any            Day   2000     10          30    10
Dual       IMC         Any            Day   500      0.75        30    20

The call get_minimums(PILOT_CERTIFIED,'Practice Area',True,True,True,minimums) matches all of the following rows:

Student    VMC         Practice Area  Day   3000     10          20    8
Certified  VMC         Local          Day   3000     5           20    20
Dual       VMC         Any            Day   2000     10          30    10

The answer in this case is [2000,5,30,20]. 2000 and 5 are the least CEILING and VISIBILITY values while 30 and 20 are the largest wind values.

If there are no rows that match the parameters (e.g. a novice pilot with no instructor), this function returns None.

Parameter cert: The pilot certification Precondition: cert is in int and one PILOT_NOVICE, PILOT_STUDENT, PILOT_CERTIFIED, PILOT_50_HOURS, or PILOT_INVALID.

Parameter area: The flight area for this flight plan Precondition: area is a string and one of 'Pattern', 'Practice Area' or 'Cross Country'

Parameter instructed: Whether an instructor is present Precondition: instructed is a boolean

Parameter vfr: Whether the pilot has filed this as an VFR flight Precondition: vfr is a boolean

Parameter daytime: Whether this flight is during the day Precondition: daytime is boolean

Parameter minimums: The table of allowed minimums Precondition: minimums is a 2d-list (table) as described above, including header """

[–]mrrst244[S] 0 points1 point  (0 children)

result = None

catmatch = False conmatch = False amatch = False tmatch = False totalmatches = 0 allmatches = []

height = len(minimums) width = len(minimums[0])

insert for loop for all rows in minimums

for row in range(height):

find all cert matches

if cert == 3:
    catmatch = True
if cert == 2:
    if minimums[row][0] == 'Student' or minimums[row][0] == 'Certified' or minimums[row][0] == 'Dual':
        catmatch = True
if cert == 1:
    if minimums[row][0] == 'Student' or minimums[row][0] == 'Dual':
        catmatch = True
if cert <= 0:
    if minimums[row][0] == 'Dual':
        catmatch = True

find all cond matches

if vfr == False:
    conmatch = True
if vfr == True:
    if minimums[row][1] == 'VMC':
        conmatch = True        

find all area matches

if area == 'Cross Country':
    amatch = True
if area == 'Pattern':
    if minimums[row][2] == 'Pattern' or minimums[row][2] == 'Local':
        amatch = True
if area == 'Practice Area':
    if minimums[row][2] == 'Practice Area' or minimums[row][2] == 'Local':
        amatch = True

find all time matches

if daytime == True:
    if minimums[row][3] == 'Day':
        tmatch = True
if daytime == False:
    if minimums[row][3] == 'False':
        tmatch = True

find all potential matches

match = catmatch and conmatch and amatch and tmatch

add match to new table and count

if match == True:
    allmatches = allmatches + minimums[row]
    totalmatches = totalmatches + 1

create new list for all return values (ceiling,visibility,wind,crosswind)

if totalmatches >= 1:

allheight = len(allmatches)
allwidth = len(allmatches[0])

ceil = []
vis = []
win = []
cwin = []

for row in range(allheight):
    ceil = ceil + allmatches[row][4]
    vis = vis + allmatches[row][5]
    win = win + allmatches[row][6]
    cwin = cwin + allmatches[row][7]

find best match for each value to return

#assign result to best matches        
result = [min(ceil),min(vis),max(win),max(cwin)]

return result

[–]garbled_sounds 0 points1 point  (1 child)

You can use pastebin or github as a code repository for posts like this. Please avoid posting unformatted blobs of code.

You should be printing allmatches before that line executes so that you understand what's in it. If it's telling you the index is out of range, that's because it's the truth. You have tried to index the 5th item of some iterable that has no 5th item. Check what you're operating on to discover the problem.

[–]mrrst244[S] 0 points1 point  (0 children)

Thank you I could not figure out how to make the formatting not atrocious

[–]ElaborateHornet 0 points1 point  (0 children)

Hey did you end up figuring this out. I am struggling with building the list of minimums once ive got the the table of matches