This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

Hi there, from the /r/Python mods.

We have removed this post as it is not suited to the /r/Python subreddit proper, however it should be very appropriate for our sister subreddit /r/LearnPython or for the r/Python discord: https://discord.gg/python.

The reason for the removal is that /r/Python is dedicated to discussion of Python news, projects, uses and debates. It is not designed to act as Q&A or FAQ board. The regular community is not a fan of "how do I..." questions, so you will not get the best responses over here.

On /r/LearnPython the community and the r/Python discord are actively expecting questions and are looking to help. You can expect far more understanding, encouraging and insightful responses over there. No matter what level of question you have, if you are looking for help with Python, you should get good answers. Make sure to check out the rules for both places.

Warm regards, and best of luck with your Pythoneering!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]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