Answered step by step
Verified Expert Solution
Link Copied!

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 (list_weather_violations) 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 start_time.date().isoformat()== 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 list_weather_violations(directory):
"""
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
get_weather_violation() 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
S00687548QR I0612017-01-08T14:00:00-05:002017-01-08T16:00:00-05:00 VFR Pattern
S00758548QR I0722017-01-08T09:00:00-05:002017-01-08T11:00:00-05:00 VFR Pattern
S00971426JQ I0722017-01-12T13:00:00-05:002017-01-12T15:00:00-05:00 VFR Pattern
violate for reasons of 'Winds', 'Visibility', and 'Ceiling', respectively (and are the
only violations). Then this function will return the 2d list
[[S00687,548QR, I061,2017-01-08T14:00:00-05:00,2017-01-08T16:00:00-05:00, VFR, Pattern, Winds],
[S00758,548QR, I072,2017-01-08T09:00:00-05:00,2017-01-08T11:00:00-05:00, VFR, Pattern, Visibility],
[S00971,426JQ, I072,2017-01-12T13:00:00-05:00,2017-01-12T15:00:00-05:00, 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
S00758,548QR, I072,2017-01-08T09:00:00-05:00,2017-01-08T11:00:00-05:00, 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.read_json(os.path.join(directory,"daycycle.json"))
WEATHER = utils.read_json(os.path.join(directory,"weather.json"))
STUDENTS = utils.read_csv(os.path.join(directory,"students.csv"))
MINIMUMS = utils.read_csv(os.path.join(directory,"minimums.csv"))
LESSONS = utils.read_csv(os.path.join(directory,"lessons.csv"))
result =[]
for lesson in LESSONS:
lesson_id, aircraft_id, pilot_id, start_time_str, end_time_str, flight_type, flight_pattern = lesson
start_time = utils.str_to_time(start_time_str)
end_time = utils.str_to_time(end_time_str)
pilot_min = None
for row in MINIMUMS:
if row[0]== pilot_id:
pilot_min = row
break
weather_conditions = None
for date, conditions in WEATHER.items():
if start_time.date().isoformat()== date:
weather_conditions = conditions
break
violation = get_weather_violation(weather_conditions, pilot_min)
if violation:
result.append(lesson +[violation])
return result
Helper functions I have available:
def get_weather_violation(weather,minimums):
"""
Returns a string representing the type of weather violation (empty string if flight is ok)
def get_weather_report(takeoff,weather):
"""
Returns the most recent weather report at or before take-off.
def read_csv(filename):
"""
Returns the contents read from the CSV file filename.
def write_csv(data,filename):
"""
Writes the given data out as a CSV file filename.
def read_json(filename):
"""
Returns the contents read from the JSON file filename.
def str_to_time(timestamp,tzsource=None):
"""
Returns the datetime object for the given timestamp (or None if timestamp is
invalid).
def daytime(time,Implement list_weather_violations
You have now reached the last function in the module and the hardest
functio
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 2012 Proceedings Part 2 Lnai 7197

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284892, 978-3642284892

More Books

Students also viewed these Databases questions