Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can't figure out how to write the body for these three functions: (The functions that i've finished and the helper functions and constants that would

Can't figure out how to write the body for these three functions: (The functions that i've finished and the helper functions and constants that would help and need to be incorporated are added below):

Thank you in advance!

def assign_inspectors(bridge_data: List[list], inspectors: List[List[float]], max_bridges: int) -> List[List[int]]: """Return a list of bridge IDs to be assigned to each inspector in inspectors. inspectors is a list containing (latitude, longitude) pairs representing each inspector's location. At most max_bridges bridges should be assigned to an inspector, and each bridge should only be assigned once (to the first inspector that can inspect that bridge). >>> assign_inspectors(THREE_BRIDGES, [[43.10, -80.15]], 1) [[1]] >>> assign_inspectors(THREE_BRIDGES, [[43.10, -80.15]], 2) [[1, 2]] >>> assign_inspectors(THREE_BRIDGES, [[43.10, -80.15]], 3) [[1, 2]] >>> assign_inspectors(THREE_BRIDGES, [[43.20, -80.35], [43.10, -80.15]], 1) [[1], [2]] >>> assign_inspectors(THREE_BRIDGES, [[43.20, -80.35], [43.10, -80.15]], 2) [[1, 2], []] >>> assign_inspectors(THREE_BRIDGES, [[43.20, -80.35], [45.0368, -81.34]], 2) [[1, 2], [3]] >>> assign_inspectors(THREE_BRIDGES, [[38.691, -80.85], [43.20, -80.35]], 2) [[], [1, 2]] """ # TODO

def inspect_bridges(bridge_data: List[list], bridge_ids: List[int], date: str, bci: float) -> None: """Update the bridges in bridge_data with id in bridge_ids with the new date and BCI score for a new inspection. >>> bridges = [[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, '04/13/2012', \ [72.3, 69.5, 70.0, 70.3, 70.5, 70.7, 72.9]], \ [2, 'WEST STREET UNDERPASS', '403', 43.164531, -80.251582, \ '1963', '2014', '2007', 4, [12.2, 18.0, 18.0, 12.2], 61, \ '04/13/2012', [71.5, 68.1, 69.0, 69.4, 69.4, 70.3,\ 73.3]], \ [3, 'STOKES RIVER BRIDGE', '6', 45.036739, -81.33579, '1958', \ '2013', '', 1, [16.0], 18.4, '08/28/2013', \ [85.1, 67.8, 67.4, 69.2, 70.0, 70.5, 75.1, 90.1]] \ ] >>> inspect_bridges(bridges, [1], '09/15/2018', 71.9) >>> bridges == [[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, '09/15/2018', \ [71.9, 72.3, 69.5, 70.0, 70.3, 70.5, 70.7, 72.9]], \ [2, 'WEST STREET UNDERPASS', '403', 43.164531, -80.251582, \ '1963', '2014', '2007', 4, [12.2, 18.0, 18.0, 12.2], \ 61, '04/13/2012', [71.5, 68.1, 69.0, 69.4, 69.4, \ 70.3, 73.3]], \ [3, 'STOKES RIVER BRIDGE', '6', 45.036739, -81.33579, \ '1958', '2013', '', 1, [16.0], 18.4, '08/28/2013', \ [85.1, 67.8, 67.4, 69.2, 70.0, 70.5, 75.1, 90.1]] \ ] True """ # TODO

def add_rehab(bridge_data: List[list], bridge_id: int, new_date: str, is_major: bool) -> None: """ Update the bridge with the id bridge_id to have its last rehab set to new_date. If is_major is True, update the major rehab date. Otherwise, update the minor rehab date. >>> bridges = [[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, '04/13/2012', \ [72.3, 69.5, 70.0, 70.3, 70.5, 70.7, 72.9]], \ [2, 'WEST STREET UNDERPASS', '403', 43.164531, -80.251582, \ '1963', '2014', '2007', 4, [12.2, 18.0, 18.0, 12.2], 61, \ '04/13/2012', [71.5, 68.1, 69.0, 69.4, 69.4, 70.3,\ 73.3]], \ [3, 'STOKES RIVER BRIDGE', '6', 45.036739, -81.33579, '1958', \ '2013', '', 1, [16.0], 18.4, '08/28/2013', \ [85.1, 67.8, 67.4, 69.2, 70.0, 70.5, 75.1, 90.1]] \ ] >>> add_rehab(bridges, 1, '2018', False) >>> bridges == [[1, 'Highway 24 Underpass at Highway 403', '403', \ 43.167233, -80.275567, '1965', '2014', '2018', 4, \ [12.0, 19.0, 21.0, 12.0], 65, '04/13/2012', \ [72.3, 69.5, 70.0, 70.3, 70.5, 70.7, 72.9]], \ [2, 'WEST STREET UNDERPASS', '403', 43.164531, -80.251582, \ '1963', '2014', '2007', 4, [12.2, 18.0, 18.0, 12.2], \ 61, '04/13/2012', [71.5, 68.1, 69.0, 69.4, 69.4, \ 70.3, 73.3]], \ [3, 'STOKES RIVER BRIDGE', '6', 45.036739, -81.33579, \ '1958', '2013', '', 1, [16.0], 18.4, '08/28/2013', \ [85.1, 67.8, 67.4, 69.2, 70.0, 70.5, 75.1, 90.1]] \ ] True """ # TODO

____________________________________________-

__________________________________________________________________________________

ID_INDEX = 0 NAME_INDEX = 1 HIGHWAY_INDEX = 2 LAT_INDEX = 3 LON_INDEX = 4 YEAR_INDEX = 5 LAST_MAJOR_INDEX = 6 LAST_MINOR_INDEX = 7 NUM_SPANS_INDEX = 8 SPAN_LENGTH_INDEX = 9 LENGTH_INDEX = 10 LAST_INSPECTED_INDEX = 11 BCIS_INDEX = 12

HIGH_PRIORITY_BCI = 60 MEDIUM_PRIORITY_BCI = 70 LOW_PRIORITY_BCI = 100

HIGH_PRIORITY_RADIUS = 500 MEDIUM_PRIORITY_RADIUS = 250 LOW_PRIORITY_RADIUS = 100

EARTH_RADIUS = 6371

def read_data(csv_file: TextIO) -> List[List[str]]: """Read and return the contents of the open CSV file csv_file as a list of lists, where each inner list contains the values from one line of csv_file.

Docstring examples not given since results depend on csv_file. """

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.

### SAMPLE DATA TO USE IN DOCSTRING EXAMPLES ####

THREE_BRIDGES_UNCLEANED = [ ['1 - 32/', 'Highway 24 Underpass at Highway 403', '403', '43.167233', '-80.275567', '1965', '2014', '2009', '4', 'Total=64 (1)=12;(2)=19;(3)=21;(4)=12;', '65', '04/13/2012', '72.3', '', '72.3', '', '69.5', '', '70', '', '70.3', '', '70.5', '', '70.7', '72.9', ''], ['1 - 43/', 'WEST STREET UNDERPASS', '403', '43.164531', '-80.251582', '1963', '2014', '2007', '4', 'Total=60.4 (1)=12.2;(2)=18;(3)=18;(4)=12.2;', '61', '04/13/2012', '71.5', '', '71.5', '', '68.1', '', '69', '', '69.4', '', '69.4', '', '70.3', '73.3', ''], ['2 - 4/', 'STOKES RIVER BRIDGE', '6', '45.036739', '-81.33579', '1958', '2013', '', '1', 'Total=16 (1)=16;', '18.4', '08/28/2013', '85.1', '85.1', '', '67.8', '', '67.4', '', '69.2', '70', '70.5', '', '75.1', '', '90.1', ''] ]

THREE_BRIDGES = [[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', [72.3, 69.5, 70.0, 70.3, 70.5, 70.7, 72.9]], [2, 'WEST STREET UNDERPASS', '403', 43.164531, -80.251582, '1963', '2014', '2007', 4, [12.2, 18.0, 18.0, 12.2], 61.0, '04/13/2012', [71.5, 68.1, 69.0, 69.4, 69.4, 70.3, 73.3]], [3, 'STOKES RIVER BRIDGE', '6', 45.036739, -81.33579, '1958', '2013', '', 1, [16.0], 18.4, '08/28/2013', [85.1, 67.8, 67.4, 69.2, 70.0, 70.5, 75.1, 90.1]] ]

################################################# def format_data(data: List[List[str]]) -> None: """Modify data so that it follows the format outlined in the 'Data formatting' section of the assignment handout. >>> d = THREE_BRIDGES_UNCLEANED >>> format_data(d) >>> d == THREE_BRIDGES True """

def get_bridge(bridge_data: List[list], bridge_id: int) -> list: """Return the data for the bridge with id bridge_id from bridge_data. If there is no bridge with the given id, return an empty list. >>> result = get_bridge(THREE_BRIDGES, 1) >>> result == [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, '04/13/2012', \ [72.3, 69.5, 70.0, 70.3, 70.5, 70.7, 72.9]]

def get_average_bci(bridge_data: List[list], bridge_id: int) -> float: """Return the average BCI for the bridge with bridge_id from bridge_data. If there is no bridge with the id bridge_id, return 0.0. If there are no BCIs for the bridge with id bridge_id, return 0.0.

def get_total_length_on_highway(bridge_data: List[list], highway: str) -> float:

def get_distance_between(bridge1: list, bridge2: list) -> float:

def find_closest_bridge(bridge_data: List[list], bridge_id: int) -> int: """Return the id of the bridge in bridge_data that has the shortest distance to the bridge with id bridge_id. Precondition: a bridge with bridge_id is in bridge_data, and there are at least two bridges in bridge_data

def get_bridges_with_bci_below(bridge_data: List[list], bridge_ids: List[int],

bci_limit: float) -> List[int]: """Return the IDs of the bridges with ids in bridge_ids whose most recent BCIs are less than or equal to bci_limit. >>> get_bridges_with_bci_below(THREE_BRIDGES, [1, 2], 72) [2] """

def get_bridges_containing(bridge_data: List[list], search: str) -> List[int]: """ Return a list of IDs of bridges whose names contain search (case insensitive) >>> get_bridges_containing(THREE_BRIDGES, 'underpass') [1, 2] """

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

From Herds To Insights Harnessing Data Analytics For Sustainable Livestock Farming

Authors: Prof Suresh Neethirajan

1st Edition

B0CFD6K6KK, 979-8857075487

More Books

Students also viewed these Databases questions

Question

1. Describe the factors that lead to productive conflict

Answered: 1 week ago