I am struggling to implement the following function: def list_weather_violations(directory): Returns the (annotated) list of flight
Question:
I am struggling to implement the following function:
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
S00687 548QR I061 2017-01-08T14:00:00-05:00 2017-01-08T16:00:00-05:00 VFR Pattern
S00758 548QR I072 2017-01-08T09:00:00-05:00 2017-01-08T11:00:00-05:00 VFR Pattern
S00971 426JQ I072 2017-01-12T13:00:00-05:00 2017-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'
""" 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
S00687 548QR I061 2017-01-08T14:00:00-05:00 2017-01-08T16:00:00-05:00 VFR Pattern
S00758 548QR I072 2017-01-08T09:00:00-05:00 2017-01-08T11:00:00-05:00 VFR Pattern
S00971 426JQ I072 2017-01-12T13:00:00-05:00 2017-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'
"""
I am trying to call this helper function: def get_weather_report(takeoff,weather):
"""
Returns the most recent weather report at or before take-off.
The weather is a dictionary whose keys are ISO formatted timestamps and whose values
are weather reports. For example, here is an example of a (small portion of) a
weather dictionary:
{
"2017-04-21T08:00:00-04:00": {
"visibility": {
"prevailing": 10.0,
"units": "SM"
},
"wind": {
"speed": 13.0,
"crosswind": 2.0,
"units": "KT"
},
"temperature": {
"value": 13.9,
"units": "C"
},
"sky": [
{
"cover": "clouds",
"type": "broken",
"height": 700.0,
"units": "FT"
}
],
"code": "201704211056Z"
},
"2017-04-21T07:00:00-04:00": {
"visibility": {
"prevailing": 10.0,
"units": "SM"
},
"wind": {
"speed": 13.0,
"crosswind": 2.0,
"units": "KT"
},
"temperature": {
"value": 13.9,
"units": "C"
},
"sky": [
{
"type": "overcast",
"height": 700.0,
"units": "FT"
}
],
"code": "201704210956Z"
}
...
},
If there is a report whose timestamp matches the ISO representation of takeoff,
this function uses that report. Otherwise it searches the dictionary for the most
recent report before (but not equal to) takeoff. If there is no such report, it
returns None.
Example: If takeoff was as 8 am on April 21, 2017 (Eastern), this function returns
the value for key '2017-04-21T08:00:00-04:00'. If there is no additional report at
9 am, a 9 am takeoff would use this value as well.
Parameter takeoff: The takeoff time
Precondition: takeoff is a datetime object
Paramater weather: The weather report dictionary
Precondition: weather is a dictionary formatted as described above
"""
# HINT: Looping through the dictionary is VERY slow because it is so large
# You should convert the takeoff time to an ISO string and search for that first.
# Only loop through the dictionary as a back-up if that fails.
# Search for time in dictionary
# As fall back, find the closest time before takeoff
takeoff_iso = takeoff.isoformat()
if takeoff_iso in weather:
return weather[takeoff_iso]
for time in weather.keys():
if time < takeoff_iso:
return weather[time]
return None and receiving the error i've posted in the picture
Human Resources In Healthcare Managing For Success
ISBN: 9781567932997
3rd Edition
Authors: Bruce Fried, Myron D. Fottler