Question
The constants are: COLUMN_ID = 0 COLUMN_NAME = 1 COLUMN_HIGHWAY = 2 COLUMN_LAT = 3 COLUMN_LON = 4 COLUMN_YEAR_BUILT = 5 COLUMN_LAST_MAJOR_REHAB = 6 COLUMN_LAST_MINOR_REHAB
The constants are:
COLUMN_ID = 0 COLUMN_NAME = 1 COLUMN_HIGHWAY = 2 COLUMN_LAT = 3 COLUMN_LON = 4 COLUMN_YEAR_BUILT = 5 COLUMN_LAST_MAJOR_REHAB = 6 COLUMN_LAST_MINOR_REHAB = 7 COLUMN_NUM_SPANS = 8 COLUMN_SPAN_DETAILS = 9 COLUMN_DECK_LENGTH = 10 COLUMN_LAST_INSPECTED = 11 COLUMN_BCI = 12
INDEX_BCI_YEARS = 0 INDEX_BCI_SCORES = 1 MISSING_BCI = -1.0
EARTH_RADIUS = 6371
This is an example of one of the bridges which is a list.
def create_example_bridge_1() -> list: """Return a bridge in our list-format to use for doctest examples.
This bridge is the same as the bridge from row 3 of the dataset. """
return [ 1, 'Highway 24 Underpass at Highway 403', '403', 43.167233, -80.275567, '1965', '2014', '2009', 4, [12.0, 19.0, 21.0, 12.0], 65.0, '04/13/2012', [['2013', '2012', '2011', '2010', '2009', '2008', '2007', '2006', '2005', '2004', '2003', '2002', '2001', '2000'], [MISSING_BCI, 72.3, MISSING_BCI, 69.5, MISSING_BCI, 70.0, MISSING_BCI, 70.3, MISSING_BCI, 70.5, MISSING_BCI, 70.7, 72.9, MISSING_BCI]] ]
Here is a helper function:
def calculate_distance(lat1: float, lon1: float, lat2: float, lon2: float) -> float: """Return the distance in kilometers between the two locations defined by (lat1, lon1) and (lat2, lon2), rounded to the nearest meter.
>>> calculate_distance(43.659777, -79.397383, 43.657129, -79.399439) 0.338 >>> calculate_distance(43.42, -79.24, 53.32, -113.30) 2713.226 """
# This function uses the haversine function to find the # distance between two locations. You do NOT need to understand why it # works. You will just need to call on the function and work with what it # returns. # Based on code at goo.gl/JrPG4j
# convert decimal degrees to radians lon1, lat1, lon2, lat2 = (math.radians(lon1), math.radians(lat1), math.radians(lon2), math.radians(lat2))
# haversine formula t lon_diff = lon2 - lon1 lat_diff = lat2 - lat1 a = (math.sin(lat_diff / 2) ** 2 + math.cos(lat1) * math.cos(lat2) * math.sin(lon_diff / 2) ** 2) c = 2 * math.asin(math.sqrt(a))
return round(c * EARTH_RADIUS, 3)
I want to know the bodies of these functions:
def find_bridge_by_id(bridges: List[list], bridge_id: int) -> list: """Return the data for the bridge with id bridge_id from bridges.
If there is no bridge with the given id in bridges, then return an empty list.
>>> example_bridges = create_example_bridges() >>> find_bridge_by_id(example_bridges, 4) [] >>> find_bridge_by_id(example_bridges, 2) == create_example_bridge_2() True """
def find_bridges_in_radius(bridges: List[list], lat: float, lon: float, radius: int, exclusions: List[int]) -> List[int]: """Return the IDs of the bridges that are within radius kilometres from location (lat, lon). Include bridge IDs that are exactly radius kilometres away. The bridge IDs in exclusions are not included in the result.
Preconditions: - (lat, lon) is a valid location on Earth - radius > 0
>>> example_bridges = create_example_bridges() >>> find_bridges_in_radius(example_bridges, 43.10, -80.15, 50, []) [1, 2] >>> find_bridges_in_radius(example_bridges, 43.10, -80.15, 50, [1, 2]) [] """
def get_bridge_condition(bridges: List[list], bridge_id: int) -> float: """Return the most recent BCI score of the bridge in bridges with id bridge_id.
The most recent BCI score is the BCI score given to the bridge in the highest (i.e., most recent) year. If there is no score for every year, return MISSING_BCI.
>>> example_bridges = create_example_bridges() >>> get_bridge_condition(example_bridges, 1) 72.3 """
def find_worst_bci(bridges: List[list], bridge_ids: List[int]) -> int: """Return the bridge ID from bridge_ids of the bridge from bridges who has the lowest most recent BCI score.
If there is a tie, return the bridge with the smaller bridge ID in bridges.
Precondition: - bridges contains the bridges with the ids in bridge_ids - every bridge in bridges has at least one BCI score - the IDs in bridge_ids appear in increasing order
>>> example_bridges = create_example_bridges() >>> find_worst_bci(example_bridges, [1, 2]) 2 >>> find_worst_bci(example_bridges, [1, 3]) 1 """
def map_route(bridges: List[list], lat: float, lon: float, max_bridges: int, radius: int) -> List[int]: """Return the sequence of bridge IDs from bridges that must be visited by an inspector who initially starts at location (lat, lon). The sequence must contain at most max_bridges IDs. Every ID in the sequence must be unique; an inspector cannot inspect the same bridge twice.
The inspector visits the bridge within radius of their location that has the lowest most recent BCI score. The next bridge inspected is the bridge with the lowest most recent BCI score within radius radius of the last bridge's location. This step repeats until max_bridges bridges have been inspected, or there are no bridges to inspect within radius.
>>> example_bridges = create_example_bridges() >>> map_route(example_bridges, 43.10, -80.15, 3, 50) [2, 1] >>> map_route(example_bridges, 43.1, -80.5, 30, 10) [] """
def trim_from_end(raw_data: list, count: int) -> None: """Update raw_data so that count elements have been removed from the end.
Preconditions: - count >= 0 - len(raw_data) >= count
>>> my_lst = [[72.3, 69.5, 70.0, 70.3, 70.5, 70.7, 72.9], '', '72.3', '', '69.5', '', '70', '', '70.3', '', '70.5', '', '70.7', '72.9', ''] >>> trim_from_end(my_lst, 14) >>> my_lst [[72.3, 69.5, 70.0, 70.3, 70.5, 70.7, 72.9]] """
def clean_span_data(raw_spans: str) -> List[float]: """Return a list of span lengths from raw_spans, in the same order that they appear in raw_spans.
Precondition: - raw_spans is in the appropriate format (see handout for details)
>>> clean_span_data('Total=64 (1)=12;(2)=19;(3)=21;(4)=12;') [12.0, 19.0, 21.0, 12.0] """
def clean_bci_data(bci_years: List[str], start_year: int, bci_scores: list) -> None: """Update bci_years so that each element contains the year as a string, starting from start_year and decreasing by one for each subsequent element, until bci_years has the same length as bci_scores. Also update bci_scores so that all non-empty string values are float values, and all empty string values are MISSING_BCI.
Preconditions: - len(bci_years) == 0 - len(bci_scores) > 0 - start_year - len(bci_scores) >= 0 - every value in bci_scores is either an empty string or can be converted to a float
>>> years = [] >>> scores = ['', '72.3', '', '69.5', '', '70.0', '', '70.3', ''] >>> clean_bci_data(years, 2013, scores) >>> years ['2013', '2012', '2011', '2010', '2009', '2008', '2007', '2006', '2005'] >>> scores [-1.0, 72.3, -1.0, 69.5, -1.0, 70.0, -1.0, 70.3, -1.0] """
PLEASE DO THEM CAREFULLY. I will make my friends upvote as well.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
The question is incomplete as it doesnt provide complete details or enough context about certain aspects of the data structure for the functions you w...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started