Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Why do I keep getting the error get_weather_report(2017-10-12T11:30:00-04:00,weather) returned a report with code='201712310156Z', not code='201710121356Z'. ? My variables seem to show what I expect them

Why do I keep getting the error "get_weather_report(2017-10-12T11:30:00-04:00,weather) returned a report with code='201712310156Z', not code='201710121356Z'. "?

My variables seem to show what I expect them to. I am assuming that something is wrong with my logic of comparing temptime and takeoff but I am not sure.

Here is my code:

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

isotakeoff = takeoff.isoformat()

if isotakeoff in weather.keys():

return weather[str(isotakeoff)]

for k in weather.keys():

stringweather = k

temptime = utils.str_to_time(stringweather,takeoff.tzinfo)

if temptime < takeoff:

return weather[k]

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

Expert Oracle Database Architecture

Authors: Thomas Kyte, Darl Kuhn

3rd Edition

1430262990, 9781430262992

More Books

Students also viewed these Databases questions

Question

The (perfect) solution is d.

Answered: 1 week ago

Question

Of the two products, this one has the (great) potential.

Answered: 1 week ago