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]) [] """

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

I wanted help with writing the bodies of the functions.

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)

 

With the data above, please help me with the bodies of the 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
"""

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY