Given information: # A set of constants, each representing a list index for station information. ID = 0 NAME = 1 LATITUDE = 2 LONGITUDE = 3 CAPACITY = 4 BIKES_AVAILABLE = 5 DOCKS_AVAILABLE = 6 NO_KIOSK = 'SMART' # For use in the get_lat_lon_distance helper function EARTH_RADIUS = 6371 # SAMPLE DATA TO USE IN DOCSTRING EXAMPLES SAMPLE_STATIONS = [

Np Ms Office 365/Excel 2016 I Ntermed
1st Edition
ISBN:9781337508841
Author:Carey
Publisher:Carey
Chapter8: Working With Advanced Functions
Section: Chapter Questions
Problem 4.4CP
icon
Related questions
Question
100%

Given information:

# A set of constants, each representing a list index for station information.
ID = 0
NAME = 1
LATITUDE = 2
LONGITUDE = 3
CAPACITY = 4
BIKES_AVAILABLE = 5
DOCKS_AVAILABLE = 6
NO_KIOSK = 'SMART'

# For use in the get_lat_lon_distance helper function
EARTH_RADIUS = 6371

# SAMPLE DATA TO USE IN DOCSTRING EXAMPLES

SAMPLE_STATIONS = [
    [7090, 'Danforth Ave / Lamb Ave',
     43.681991, -79.329455, 15, 4, 10],
    [7486, 'Gerrard St E / Ted Reeve Dr',
     43.684261, -79.299332, 24, 5, 19],
    [7571, 'Highfield Rd / Gerrard St E - SMART',
     43.671685, -79.325176, 19, 14, 5]]

HANDOUT_STATIONS = [
    [7000, 'Ft. York / Capreol Crt.',
     43.639832, -79.395954, 31, 20, 11],
    [7001, 'Lower Jarvis St SMART / The Esplanade',
     43.647992, -79.370907, 15, 5, 10]]


Given helper function: (Hint: this function is to be used to complete the docstring below)

def get_lat_lon_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 metre.

    >>> get_lat_lon_distance(43.659777, -79.397383, 43.657129, -79.399439)
    0.338
    >>> get_lat_lon_distance(43.67, -79.37, 55.15, -118.8)
    3072.872
    """

    # 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)


QUESTION: Complete the doctring using the information above.

def get_nearest_station(my_latitude: float, my_longitude: float,
                        stations: List['Station']) -> int:
    """Return the id of the station from stations that is nearest to the
    location given by my_latidute and my_longitude.

    In the case of a tie, return the ID of the last station in stations with
    that distance.

    Preconditions: len(stations) > 1

    >>> get_nearest_station(43.671134, -79.325164, SAMPLE_STATIONS)
    7571
    >>> get_nearest_station(43.674312, -79.299221, SAMPLE_STATIONS)
    7486
    """

Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Lists
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage