Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need a lord and saviour please T-T.....I want to learn but no one seems to do it so i cant learn it....Ive been trying

I need a lord and saviour please T-T.....I want to learn but no one seems to do it so i cant learn it....Ive been trying for so long too ;-;

The data used for this assignment is a subset of the data found in: https://www.ontario.ca/data/bridge-conditions

import csv import math from typing import List, TextIO

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

####### BEGIN HELPER FUNCTIONS ####################

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. """

lines = csv.reader(csv_file) data = list(lines)[2:] return data

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)

####### END HELPER FUNCTIONS ####################

Please create these following python programs:

def get_total_length_on_highway(bridge_data: List[list], highway: str) -> float: """Return the total length of bridges in bridge_data on highway. Use zero for the length of bridges that do not have a length provided. If there are no bridges on highway, return 0.0. >>> get_total_length_on_highway(THREE_BRIDGES, '403') 126.0 >>> get_total_length_on_highway(THREE_BRIDGES, '401') 0.0 """

def get_distance_between(bridge1: list, bridge2: list) -> float: """Return the distance in kilometres, rounded to the nearest metre (i.e., 3 decimal places), between the two bridges bridge1 and bridge2. >>> get_distance_between(get_bridge(THREE_BRIDGES, 1), \ get_bridge(THREE_BRIDGES, 2)) 1.968 """ # Hint: use the provided helper function calculate_distance.

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.

def find_bridges_in_radius(bridge_data: List[list], lat: float, long: float, distance: float) -> List[int]: """Return the IDs of the bridges that are within radius distance from (lat, long). >>> find_bridges_in_radius(THREE_BRIDGES, 43.10, -80.15, 50) [1, 2] """

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] >>> get_bridges_containing(THREE_BRIDGES, 'Highway') [1] """ Precondition: a bridge with bridge_id is in bridge_data, and there are at least two bridges in bridge_data >>> find_closest_bridge(THREE_BRIDGES, 2) 1 """

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

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

More Books

Students also viewed these Databases questions

Question

=+ Outline intrinsic and extrinsic sources of employee motivation.

Answered: 1 week ago