Question: 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
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 ####################

USE THE AVOBE FUNCTION
TO WRITE
THIS FUNCTION

def calculate_distance(lat1: float, lon1: float, lat2: float, lon2: float)float: Return the distance in kilometers between the two locations defined by (latl, 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/JrPG41 # 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 = 1on2-1on1 lat difflat2- lati a-(math.sin(lat diff / 2) ** 2 + math.cos(lat1) math.cos (lat2) math.sin(lon_diff / 2) ** 2) c2 math.asin(math.sqrt (a)) return round (cEARTH RADIUS, 3) def calculate_distance(lat1: float, lon1: float, lat2: float, lon2: float)float: Return the distance in kilometers between the two locations defined by (latl, 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/JrPG41 # 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 = 1on2-1on1 lat difflat2- lati a-(math.sin(lat diff / 2) ** 2 + math.cos(lat1) math.cos (lat2) math.sin(lon_diff / 2) ** 2) c2 math.asin(math.sqrt (a)) return round (cEARTH RADIUS, 3)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
