Question: Please help me implement the function def get_weather_violation(weather,minimums):. I have this code so far, but I keep getting the error get_weather_violation({'visibility': {'prevailing': 4.0, 'units':

Please help me implement the function def get_weather_violation(weather,minimums):. I have this code so far, but I keep getting the error "

get_weather_violation({'visibility': {'prevailing': 4.0, 'units': 'SM'}, 'wind': {'speed': 11.0, 'crosswind': 3.0, 'gusts': 28.0, 'units': 'KT'}, 'temperature': {'value': 6.7, 'units': 'C'}, 'sky': [{'cover': 'clouds', 'type': 'broken', 'height': 2800.0, 'units': 'FT'}, {'cover': 'clouds', 'type': 'broken', 'height': 5500.0, 'units': 'FT'}], 'weather': ['rain', 'mist', 'thunderstorm'], 'code': '201705142156Z'},[500, 0.75, 30, 20]) returned 'Unknown', not ''."

def get_weather_violation(weather,minimums):

"""

Returns a string representing the type of weather violation (empty string if flight is ok)

The weather reading is a dictionary with the keys: 'visibility', 'wind', and 'sky'.

These correspond to a visibility, wind, and ceiling measurement, respectively. It

may have other keys as well, but these can be ignored. For example, this is a possible

weather value.

{

"visibility": {

"prevailing": 21120.0,

"minimum": 1400.0,

"maximum": 21120.0,

"units": "FT"

},

"wind": {

"speed": 12.0,

"crosswind": 3.0,

"gusts": 18.0,

"units": "KT"

},

"temperature": {

"value": -15.6,

"units": "C"

},

"sky": [

{

"cover": "clouds",

"type": "broken",

"height": 2100.0,

"units": "FT"

}

],

"weather": [

"light snow"

]

}

The minimums is a list of the four minimums ceiling, visibility, and max windspeed,

and max crosswind speed in that order. Ceiling is in feet, visibility is in statute

miles, max wind and cross wind speed are both in knots. For example,

[3000.0,10.0,20.0,8.0] is a potential minimums list.

This function uses bad_visibility, bad_winds, and bad_ceiling as helpers. It returns

'Visibility' if the only problem is bad visibility, 'Winds' if the only problem is

wind, and 'Ceiling' if the only problem is the ceiling. If there are multiple

problems, it returns 'Weather', It returns 'Unknown' if no weather reading is

available (e.g. weather is None). Finally, it returns '' (the empty string) if

the weather is fine and there are no violations.

Parameter weather: The weather measure

Precondition: weather is dictionary containing a visibility, wind, and ceiling measurement,

or None if no weather reading is available.

Parameter minimums: The safety minimums for ceiling, visibility, wind, and crosswind

Precondition: minimums is a list of four floats

"""

try:

current_visibility = weather['visibility']['minimum']

current_wind_speed = weather['wind']['speed']

current_height = weather['sky'][0]['height']

except:

return('Unknown')

problems = list()

if(current_visibility < minimums[1]):

problems.append('Visibility')

if(current_wind_speed < minimums[2] ):

problems.append('Winds')

if(weather['sky'][0]['height'] < minimums[0]):

problems.append('Ceiling')

if(len(problems) > 1):

return('Weather')

elif(len(problems) == 0):

return('')

else:

return(problems)

It also requires the use of the helper functions bad_visibility, bad_winds, and bad_ceiling which I have already implemented. Here is the code for those functions:

def bad_visibility(visibility,minimum):

"""

Returns True if the visibility measurement violates the minimum, False otherwise

Parameter minimum: The minimum allowed visibility (in statute miles)

Precondition: minimum is a float or int

"""

if visibility == 'unavailable':

return True

if type(visibility) is dict:

if 'prevailing' not in visibility and 'units' not in visibility:

return True

else:

if visibility['units'] == 'FT':

minimum = minimum * 5280

if 'minimum' in visibility:

if minimum > visibility['minimum']:

return True

else:

return False

else:

if visibility['prevailing'] == 'unavailable' or minimum > visibility['prevailing']:

return True

else:

return False

return True

def bad_winds(winds,maxwind,maxcross):

"""

Returns True if the wind measurement violates the maximums, False otherwise

Parameter maxwind: The maximum allowable wind speed (in knots)

Precondition: maxwind is a float or int

Parameter maxcross: The maximum allowable crosswind speed (in knots)

Precondition: maxcross is a float or int

"""

MPS = 1.94384

k1 = {'speed', 'units', 'gusts', 'crosswind'}

k2 = {'speed', 'units', 'gusts'}

k3 = {'speed', 'units', 'crosswind'}

if winds == 'unavailable':

result = True

elif winds == 'calm':

result = False

else:

if winds['units'] == 'KT':

if (winds.keys()) == k1:

if winds['crosswind'] > maxcross or winds['speed'] > maxwind or winds['gusts'] > maxwind:

result = True

else:

result = False

elif (winds.keys()) == k2:

if winds['speed'] > maxwind or winds['gusts'] > maxwind:

result = True

else:

result = False

elif (winds.keys()) == k3:

if winds['crosswind'] > maxcross or winds['speed'] > maxwind:

result = True

else:

result = False

else:

speed = winds['speed'] * MPS

if (winds.keys()) == k1:

crosswind = winds['crosswind'] * MPS

gusts = winds['gusts'] * MPS

if speed > maxwind or crosswind > maxcross or gusts > maxwind:

result = True

else:

result = False

elif (winds.keys()) == k2:

gusts = winds['gusts'] * MPS

if speed > maxwind or gusts > maxwind:

result = True

else:

result = False

elif (winds.keys()) == k3:

crosswind = winds['crosswind'] * MPS

if speed > maxwind or crosswind > maxcross:

result = True

else:

result = False

return result

def bad_ceiling(ceiling,minimum):

"""

Returns True if the ceiling measurement violates the minimum, False otherwise

Parameter minimum: The minimum allowed ceiling (in feet)

Precondition: minimum is a float or int

"""

if(ceiling=='clear'):

return False

elif(ceiling=='unavailable'):

return True

minheight =100000000

for data in ceiling:

if data['type'] in [ 'broken', 'overcast', 'indefinite ceiling']:

minheight =min(minheight,data['height'])

return minheight

def get_weather_report(takeoff,weather):

"""

Returns the most recent weather report at or before take-off.

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

"""

takeofftime = takeoff.isoformat()

if takeofftime in weather.keys():

return weather[str(takeofftime)]

for x in weather.keys ():

time=x

timecheck=utils.str_to_time (time,takeoff.tzinfo)

if timecheck < takeoff:

return weather[x]

return None

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!