Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Module to check violations for a flight lesson. import utils import pilots import os . path from datetime import datetime, timezone, timedelta

"""
Module to check violations for a flight lesson.
import utils
import pilots
import os.path
from datetime import datetime, timezone, timedelta
import pytz
# WEATHER FUNCTIONS
def bad_visibility(visibility,minimum):
"""
Returns True if the visibility measurement violates the minimum, False otherwise
if visibility == "unavailable":
return True
# Check if visibility is a dictionary with 'prevailing' and 'units' keys
if (
isinstance(visibility, dict)
and "prevailing" in visibility
and "units" in visibility
):
prevailing_visibility = visibility["prevailing"]
units = visibility["units"]
# Convert visibility to statute miles if the units are in 'FT'(feet)
if units =="FT":
prevailing_visibility =(
prevailing_visibility /5280
) # 1 statute mile =5280 feet
# Check if 'minimum' exists in the dictionary, if not, use 'prevailing' as minimum
if "minimum" in visibility:
minimum_visibility = visibility["minimum"]
if units =="FT":
minimum_visibility = minimum_visibility /5280
return minimum_visibility minimum
else:
return prevailing_visibility minimum
return False # Invalid visibility format
pass # Implement this function
def bad_winds(winds,maxwind,maxcross):
"""
Returns True if the wind measurement violates the maximums, False otherwise
if winds == "unavailable":
return True
if winds == "calm":
return False
if type(winds) is not dict: # Not what we were expecting, missing weather data
return True
# Only 'speed' and 'units' are required
if "speed" not in winds or "units" not in winds:
return True
# Declare speed variable
speed = winds["speed"]
if "gusts" in winds:
speed = max(speed, winds["gusts"])
# Declare crosswind variable
crosswind = None
if "crosswind" in winds:
crosswind = winds["crosswind"]
# If units are different
if winds["units"]=="MPS":
if crosswind != None:
crosswind = crosswind *1.944 # convert to KT
speed = speed *1.944
# This function returns True if speed is more than the maximum
if speed > maxwind:
return True
# This function should compare ths winds 'crosswind' (if it exists)
if crosswind != None and crosswind > maxcross:
return True
return False
pass # Implement this function
def bad_ceiling(ceiling,minimum):
"""
if ceiling == 'clear':
return False
if ceiling == 'unavailable':
return True
for x in ceiling:
if x['type']== 'broken':
if x['height'] minimum:
return True
else:
return False
if x['type']== 'overcast':
if x['height'] minimum:
return True
else:
return False
if x['type']== 'indefinite ceiling':
if x['height'] minimum:
return True
else:
return False
return False
pass # Implement this function
def get_weather_report(takeoff,weather):
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]
return None
pass
def get_weather_violation(weather,minimums):
"""
Returns a string representing the type of weather violation (empty string if flight is ok)
"""
if weather is None:
return 'Unknown'
current_visibility = weather.get('visibility',{}).get('minimum')
current_wind_speed = weather.get('wind',{}).get('speed')
current_height = weather.get('sky',[{}])[0].get('height')
problems =[]
if current_visibility is not None and bad_visibility(current_visibility, minimums[1]):
problems.append('Visibility')
if current_wind_speed is not None and bad_winds(weather.get('wind',{}), minimums[2], minimums[3]):
problems.append('Winds')
if current_height is not None and bad_ceiling(current_height, minimums[0]):
problems.append('Ceiling')
if len(problems)>1:
return 'Weather'
elif len(problems)==1:
return problems[0]
else:
return '' # if there is only one problemImplement get_weather_violation
violations.bad_wind passed all tests
violations.bad_ceiling passed all tests
violations.get_weather_report passed all tests
violations.get_weather_violation passed all tests
Again, you will notice that it will take several seconds to complete the test of
get_weather_report. This is a minor inconvenience for the rest
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

OCA Oracle Database SQL Exam Guide Exam 1Z0-071

Authors: Steve O'Hearn

1st Edition

1259585492, 978-1259585494

More Books

Students also viewed these Databases questions