Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I m trying to implement a function ( list _ weather _ violations ) but I m struggling with the check the weather portion. Here
Im trying to implement a function listweatherviolations but Im struggling with the check the weather portion. Here is the outline of the function were supposed to write and all the helper functions that go with it I have my code on there, but its not passing the check its giving me an error for the line if starttime.dateisoformat date: If you have any advice on how to make this code function properly, Id greatly appreciate it Im going to include all of the helper functions so you can see what tools Im working with. I know they work correctly because theyve already been graded.
What Im trying to code:
def listweatherviolationsdirectory:
Returns the annotated list of flight reservations that violate weather minimums.
This function reads the data files in the given directory the data files are all
identified by the constants defined above in this module It loops through the
list of flight lessons in lessons.csv identifying those takeoffs for which
getweatherviolation is not the empty string.
This function returns a list that contains a copy of each violating lesson, together
with the violation appended to the lesson.
Example: Suppose that the lessons
SQR IT:::T::: VFR Pattern
SQR IT:::T::: VFR Pattern
SJQ IT:::T::: VFR Pattern
violate for reasons of 'Winds', 'Visibility', and 'Ceiling', respectively and are the
only violations Then this function will return the d list
SQR IT:::T::: VFR Pattern, Winds
SQR IT:::T::: VFR Pattern, Visibility
SJQ IT:::T::: VFR Pattern, Ceiling
REMEMBER: VFR flights are subject to minimums with VMC in the row while IFR flights
are subject to minimums with IMC in the row. The examples above are all VFR flights.
If we changed the second lesson to
SQR IT:::T::: IFR, Pattern
then it is possible it is no longer a visibility violation because it is subject to
a different set of minimums.
Parameter directory: The directory of files to audit
Precondition: directory is the name of a directory containing the files 'daycycle.json',
'weather.json', 'minimums.csv 'students.csv and 'lessons.csv
# Load in all of the files
# For each of the lessons
# Get the takeoff time
# Get the pilot credentials
# Get the pilot minimums
# Get the weather conditions
# Check for a violation and add to result if so
DAYCYCLE utils.readjsonospath.joindirectory"daycycle.json"
WEATHER utils.readjsonospath.joindirectory"weather.json"
STUDENTS utils.readcsvospath.joindirectory"students.csv
MINIMUMS utils.readcsvospath.joindirectory"minimums.csv
LESSONS utils.readcsvospath.joindirectory"lessons.csv
result
for lesson in LESSONS:
lessonid aircraftid pilotid starttimestr endtimestr flighttype, flightpattern lesson
starttime utils.strtotimestarttimestr
endtime utils.strtotimeendtimestr
pilotmin None
for row in MINIMUMS:
if row pilotid:
pilotmin row
break
weatherconditions None
for date, conditions in WEATHER.items:
if starttime.dateisoformat date:
weatherconditions conditions
break
violation getweatherviolationweatherconditions, pilotmin
if violation:
result.appendlesson violation
return result
Helper functions I have available:
def getweatherviolationweatherminimums:
Returns a string representing the type of weather violation empty string if flight is ok
def getweatherreporttakeoffweather:
Returns the most recent weather report at or before takeoff.
def readcsvfilename:
Returns the contents read from the CSV file filename.
def writecsvdatafilename:
Writes the given data out as a CSV file filename.
def readjsonfilename:
Returns the contents read from the JSON file filename.
def strtotimetimestamptzsourceNone:
Returns the datetime object for the given timestamp or None if timestamp is
invalid
def daytimetimeImplement listweatherviolations
You have now reached the last function in the module and the hardest
functio
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started