Example #1
0
def run():
    """Requirements for Task 1C"""

    # Build list of stations
    stations = build_station_list()

    # Ask user for input coordinates - suggested is for Cambridge
    centre_x = 52.2053 # input("Enter lattititude - eg. 52.2053 : ")
    centre_y = 0.1218  # input("Enter longitude - eg. 0.1218 : ")
    centre = (centre_x , centre_y)

    # Display stations in specified radius
    stations_within_radius(stations, centre, r = float(input("What is required radius? ")))
Example #2
0
def run():
    """
    Build a list of stations within 10 km of the Cambridge city centre. Print the names of the stations, listed in alphabetical order.
    """
    stations = build_station_list()
    sorted_stations = stations_within_radius(stations, (52.2053, 0.1218), 10)
    print(sorted([i.name for i in sorted_stations]))
Example #3
0
def test_stations_within_radius():
    # Build list of stations
    stations = build_station_list()
    centre=(52.2053, 0.1218)
    r=10
    x=stations_within_radius(stations, centre, r)
    assert len(x)==10
Example #4
0
def run():
    #Test sample of some station
    stations = build_station_list()
    # Running the function to get a list called result
    result = stations_within_radius(stations, (52.2053, 0.1218), 10)
    # Printing the result
    print(result)
Example #5
0
def test_stations_within_radius():
    stations = build_station_list()
    given_latitude = 52.2053 / 180 * (np.pi)
    given_longitude = 0.1218 / 180 * (np.pi)
    centre = [given_latitude, given_longitude]
    r = 1  #radius
    station_in_radius = stations_within_radius(stations, centre, r)
    assert station_in_radius == ['Cambridge Jesus Lock']
Example #6
0
def run():
    stations = build_station_list()
    coord_camcity = (52.2053, 0.1218)

    arr = stations_within_radius(stations, coord_camcity, 10)
    sorted_arr = sorted(arr)  # sort alphabetically

    print(sorted_arr)
Example #7
0
def run():
    # Build list of stations
    stations = build_station_list()
    given_latitude = 52.2053 / 180 * (np.pi)
    given_longitude = 0.1218 / 180 * (np.pi)
    centre = [given_latitude, given_longitude]
    r = 10  #radius
    print(stations_within_radius(stations, centre, r))
Example #8
0
def run():
    """Requirements for Task 1C"""
    reference_coordinate = (52.2053, 0.1218)
    r = 10
    stations = build_station_list()
    return stations_within_radius(
        stations, reference_coordinate,
        r)  #Prints the stations located within 10km of the desired coordinate
Example #9
0
def test_stations_within_radius():
    stations = build_station_list()
    reference_coordinate = (52.2053, 0.1218)
    lol = stations_within_radius(stations, reference_coordinate, 10)
    for i in stations:
        for a in lol:
            if i.name == a:
                assert haversine(reference_coordinate, i.coord) <= 10
Example #10
0
def run():
    #x is the coordinate of the centre
    x = (52.2053, 0.1218)

    #runs function station_within_radius
    StationsNearCentre = stations_within_radius(build_station_list(), x, 10)

    #sorts the list alphabetically and prints it
    print(sorted(StationsNearCentre))
Example #11
0
def run():
    """Requirements for Task 1C"""

    # Build list of stations
    stations = build_station_list()
    centre=(52.2053, 0.1218)
    r=10
    x=stations_within_radius(stations, centre, r)
    print (x)
Example #12
0
def test_stations_within_radius():
    """tests to see if the stations with 1000km of (0,0) are Station 1, Station 2, Station 3
    note :since the coordinates of the generated stations are such that the distance from (0,0)
    is incresing with the station number"""

    stations = generate_test_station()
    stations_list = stations_within_radius(stations, (0, 0), 1500)

    for i in range(len(stations_list)):
        assert stations_list[i] == f"Station {i+1}"
def test_stations_within_radius():

    # Build list of stations
    stations = build_station_list()

    # Use Cambridge City Centre (52.2053, 0.1218)
    centre = (52.2053, 0.1218)
    ans = geo.stations_within_radius(stations, centre, 10)

    assert haversine(centre, ans[0].coord) <= 10
Example #14
0
def test_geo_2():

    # Build list of stations
    stations = build_station_list()

    # Print stations within 10km of Cambridge
    stations_near_cambridge = []
    stations_near_cambridge = stations_within_radius(stations,
                                                     (52.2053, 0.1218), 10)
    assert stations_near_cambridge[0] == "Bin Brook"
Example #15
0
def run():
    """Requirements for Task 1C"""

    # Build list of stations within radius of coordinates
    stations = stations_within_radius(build_station_list(), (52.2053, 0.1218),
                                      10)

    # Get alphabetized list of station names
    stations_list = [station.name for station in stations]

    print(sorted(stations_list))
Example #16
0
def run():
    # Build list of stations
    stations = build_station_list()
    centre = (52.2053, 0.1218)
    r = 10
    stations_in_r = stations_within_radius(stations, centre, r)
    station_names = []
    for station in stations_in_r:
        station_names.append(station.name)
    station_names.sort()
    print(station_names)
Example #17
0
def test_stations_within_radius():

    #Initialise variables
    data = build_station_list()
    c = [52.2053, 0.1218]
    r = 20

    #Get list of stations within radius
    data = geo.stations_within_radius(data, c, r)

    #Check if list contains correct number of objects
    assert len(data) == 22
Example #18
0
def run():
    #builds list of stations
    stations = stationdata.build_station_list(use_cache=True)

    #gets a list of stations that are within a radius of a point
    radius_stations = geo.stations_within_radius(stations, (52.2053, 0.1218),
                                                 10)

    #sorts the list of stations alphabetically
    radius_stations.sort()

    print(radius_stations)
Example #19
0
def test_stations_within_radius():

    # Create 2 stations
    s_id = "test-s-id"
    m_id = "test-m-id"
    label = "some station"
    coord = (-2.0, 4.0)
    trange = (-2.3, 3.4445)
    river = "River X"
    town = "My Town"
    s = MonitoringStation(s_id, m_id, label, coord, trange, river, town)

    s_id = "test-s-id2"
    m_id = "test-m-id2"
    label = "A station"
    coord = (2.0, -4.05)
    trange = (-2.3, 3.4445)
    river = "River Y"
    town = "My Town B"
    t = MonitoringStation(s_id, m_id, label, coord, trange, river, town)

    #Build an empty list for storing tuples later
    Example_build_list = []
    Example_build_list.append(s)
    Example_build_list.append(t)

    #calling the function to be tested
    Example_list = stations_within_radius(Example_build_list, (2.0, -4.0), 10)
    Alphabetic_Example_List = sorted(Example_list)
    #tests that the list only shows statioins within radius
    assert Alphabetic_Example_List[0] == "A station"

    #calling the function to be tested
    Example_list = stations_within_radius(Example_build_list, (2.0, -4.0),
                                          1000)
    Alphabetic_Example_List = sorted(Example_list)
    #tests that the list sorts it alphabetically
    assert Alphabetic_Example_List[0] == "A station"
    assert Alphabetic_Example_List[1] == "some station"
Example #20
0
def run():
    """Requirements for Task 1C"""

    # Build list of stations
    stations = build_station_list()

    # Making station-distance list around Cambridge
    stations_around_cam = stations_within_radius(stations, (52.2053, 0.1218),
                                                 10)
    cam_station_names = []  #Creating a list of names
    for i in range(len(stations_around_cam)):
        cam_station_names.append(stations_around_cam[i].name)
    cam_station_names.sort()  #Sorting list of names
    print(cam_station_names)
Example #21
0
def run():
    """Requirements for Task 1C
    """
    
    print("*** Task 1C: CUED Part IA Flood Warning System ***")

    # Build list of stations
    stations = build_station_list()

    # Print stations within 10km of Cambridge
    stations_near_cambridge = []
    stations_near_cambridge = stations_within_radius(stations, (52.2053, 0.1218), 10)
    print("The 10 stations closest to Cambridge:")
    print(stations_near_cambridge)
Example #22
0
def test_stations_within_radius():

    #find a value of r that take only the first 2 items by sorting the
    #distances and taking the second one
    a = []
    for i in testout:
        a.append(i[1])

    a.sort

    #checking that the length of the output is correct length and that the
    #items are in range order
    testout2 = stations_within_radius(teststations, testpoint, a[1])
    assert len(testout2) == 2
    assert testout2[0][1] < testout2[1][1]
def run():
    """Requirements for Task 1C"""
    # Build list of stations
    stations = build_station_list()

    # Sort the stations by distance from cambridge centre
    centre = (52.2053, 0.1218)
    radius = 10.0
    within_radius = stations_within_radius(stations, centre, radius)

    # Print the stations
    stations = []
    for station in within_radius:
        stations.append(station.name)

    print(sorted(stations))
def test_stations_within_radius():
    s_id = "test-s-id"
    m_id = "test-m-id"
    label = "some station"
    trange = (-2.3, 3.4445)
    river = "River X"
    town = "My Town1"
    coord1 = (2.0, 4.0)
    coord2 = (2.01, 3.99)
    coord3 = (200.0, -250.0)
    s1 = MonitoringStation(s_id, m_id, label, coord1, trange, river, town)
    s2 = MonitoringStation(s_id, m_id, label, coord2, trange, river, town)
    s3 = MonitoringStation(s_id, m_id, label, coord3, trange, river, town)
    s = (s1, s2, s3)
    a = stations_within_radius(s, coord1, 10)
    assert type(a[0]) == str
    assert len(a) == 2
Example #25
0
def run():
    """Requirements for Task1C"""

    # Define the coordinates of Cambridge City Centre
    Centre = (52.2053, 0.1218)
    # Define target distance
    dis = 10
    # Build a list of stations
    stations = build_station_list()
    # Get a list of stations in the range
    stations_within_radius = geo.stations_within_radius(stations, Centre, dis)
    # Retrieve name list and sort in alphabetical order
    result = []
    for station in stations_within_radius:
        result.append(station.name)
    result.sort()
    # Output
    print(result)
def test_stations_within_radius():
    #Builds station list
    s_id = "test-s-id"
    m_id = "test-m-id"
    label = "some station"
    coord1 = (6.0, 4.0)
    trange = None
    river = "River X"
    town = "My Town"
    s = MonitoringStation(s_id, m_id, label, coord1, trange, river, town)
    coord2 = (1000, 1000)
    s1 = MonitoringStation(s_id, m_id, label, coord2, trange, river, town)
    stations = [s, s1]
    centre = (0, 0)
    radius = haversine.haversine(centre, coord1, haversine.Unit.KILOMETERS) + 1
    radius_stations = geo.stations_within_radius(stations, centre, radius)

    #Checks that list exists
    assert len(radius_stations) == 1
    assert radius_stations[0] == s
def test_stations_within_radius_returns_all_stations_within_given_radius():
    stations = []
    coords = [(-10.0, 0.0), (5.0, 5.0), (9.9, 9.9), (0.0, 0.0)]
    for i in range(len(coords)):
        # Create stations
        s_id = "test-s-id-" + str(i)
        m_id = "test-m-id-" + str(i)
        label = "some station " + str(i)
        coord = coords[i]
        trange = (-2.3, 3.4445)
        river = "River " + str(i)
        town = "My Town " + str(i)
        stations.append(
            MonitoringStation(s_id, m_id, label, coord, trange, river, town))

    centre = (10.0, 10.0)
    actual_stations = geo.stations_within_radius(stations, centre, 1000.0)
    expected_stations = [stations[1], stations[2]]

    assert expected_stations == actual_stations
Example #28
0
def run():
    """Requirement for Task 1C"""

    #Set station list, centre and radius
    ID = []
    data = build_station_list()
    c = [52.2053, 0.1218]
    r = 10

    #Get list of stations within radius
    data = stations_within_radius(data, c, r)

    #Add names of stations within radius to ID
    for station in data:
        ID.append(station.name)

    #Sort alphabetically
    ID.sort()

    print(ID)
Example #29
0
def run():
    """Requirements for Task 1C"""
    #build station list
    stations = build_station_list()

    cam_coord = (52.2053, 0.1218)  #coordinates of Cambridge city centre

    #create list of stations within 10km
    stations_within_10 = stations_within_radius(stations, cam_coord, 10)

    #create list of just station names
    names_within_10 = []
    for i in stations_within_10:
        names_within_10.append(i[0].name)

    #order the list
    names_within_10.sort

    print("Stations within 10km of Cambridge")
    for i in names_within_10:
        print(i)
Example #30
0
def run():
    '''
    Test for stations_within_radius
    '''
    # generate stations list
    stations = build_station_list()
    
    #get the distance
    center_cam = (52.2053, 0.1218)
    r_cam = 10
    list_st_within = stations_within_radius(stations, center_cam, r_cam)
    
    #generate the list of stations within the distance
    name_list = []
    for st in list_st_within:
        name_list.append(st.name)
    
    #sorted the list by alphabetic order
    sorted_list = sorted(name_list)
    print(sorted_list)
    return sorted_list