Exemple #1
0
def test_geo():

    # Build list of stations
    stations = build_station_list()

    # Create list of tuples of station name and distance from Cambridge
    stations_from_cambridge = []
    for i in range(len(stations_by_distance(stations, (52.2053, 0.1218)))):
        stations_from_cambridge.append(
            stations_by_distance(stations, (52.2053, 0.1218))[i])
    closest = stations_from_cambridge[0]
    assert closest[0] == "Cambridge Jesus Lock"
Exemple #2
0
def test_stations_by_distance():
    result = stations_by_distance(build_station_list(), (52.2053, 0.1218))
    result_1 = result[0]
    result_2 = result[-1]
    assert len(stations_by_distance(build_station_list(),
                                    (52.2053, 0.1218))) > 0
    assert result_1[1] == 0.840237595667494
    assert result_2[1] == 467.53431870130544
    assert type(result) == list
    assert type(result_1) == tuple
    assert type(result_2) == tuple
    assert type(result_1[1]) == float
    assert type(result_2[1]) == float
Exemple #3
0
def test_stations_by_distance():
    m = stations_by_distance(stations, (52.2053, 0.1218))
    assert type(m) == list
    for i in range(len(m)):
        assert type(m[i][1]) == float
        assert type(m[i]) == tuple
        assert m[i][1] > 0
Exemple #4
0
def run():
    """Requirements for Task 1B"""
    cam_coord = (52.2053, 0.1218)  #coordinates of Cambridge city centre

    #build station list
    stations = build_station_list()

    #calculate the distances to coordinates
    distances_to_cam = stations_by_distance(stations, cam_coord)

    #10 closest will be the first 10 items in the list
    close10 = distances_to_cam[:10]

    #reverse the order and take the first 10 items of the re-orderd list
    distances_to_cam = sorted_by_key(distances_to_cam, 1, reverse=True)
    far10 = distances_to_cam[:10]

    #format outputs
    close10formatted = []
    far10formatted = []
    for i in close10:
        close10formatted.append((i[0].name, i[0].town, i[1]))
    for i in far10:
        far10formatted.append((i[0].name, i[0].town, i[1]))

    print("Closest 10 stations to Cambride:")
    for i in close10formatted:
        print(i)
    print("")
    print("Furthest 10 stations from Cambridge:")
    for i in far10formatted:
        print(i)
def run():
    """
    Prints a list of tuples (station name, town, distance) for the 10 closest and the 10 furthest stations from the Cambridge city centre, (52.2053, 0.1218).
    """
    stations = build_station_list()
    sorted_stations = stations_by_distance(stations, (52.2053, 0.1218))
    print("The closest 10 stations are: {}".format(sorted_stations[:10]))
    print("The furthest 10 stations are: {}".format(sorted_stations[-10:]))
Exemple #6
0
def test_stations_by_distance():
    """Uses the generated stations, and checks to see if it was correctly sorted by distance """
    stations = generate_test_station()
    stations_list = stations_by_distance(stations, (0, 0))
    """The coordinates of the generated stations are such that the distance from (0,0)
        is incresing with the station number"""

    for i in range(len(stations_list)):
        assert stations_list[i][0].name == f"Station {i+1}"
def test_stations_by_distance():
    stations = gen_stations()
    distances = geo.stations_by_distance(stations, (0, 0))

    assert distances[0][0] == stations[2]
    assert round(distances[0][1] - 5674.419005723288) == 0

    assert distances[4][0] == stations[1]
    assert round(distances[4][1] - 5876.221687663879) == 0
Exemple #8
0
def run():
    """ Requirement for Task 1B"""
    
    
    stations = build_station_list()
    stations_distance = stations_by_distance(stations, (52.2053, 0.1218))
    print("10 Closest Entries: ", stations_distance[:10])
    print("\n")
    print("10 Furthest Entries", stations_distance[-10:])
def test_geo_stations_by_distance():

    # Build list of stations
    stations = build_station_list()

    # Use Cambridge City Centre (52.2053, 0.1218)
    distance_sorted = geo.stations_by_distance(stations, (52.2053, 0.1218))

    assert distance_sorted[0][0].town == "Cambridge"
def test_stations_by_distance():
    #Builds station list
    stations = build_station_list()
    centre = (0, 0)
    sorted_stations = geo.stations_by_distance(stations, centre)

    #Checks that list exists and in order
    assert len(sorted_stations) > 0
    for i in range(1, len(sorted_stations)):
        assert sorted_stations[i][1] >= sorted_stations[i - 1][1]
def test_stations_by_distance():
    s = build_station_list()
    p = (0.0, 0.0)
    a = stations_by_distance(s, p)

    assert a[0][2] <= a[-1][2]
    for item in a:
        assert type(item) == tuple
        assert type(item[0]) == str
        assert type(item[2]) == float
Exemple #12
0
def run():

    # Build list of stations
    stations = build_station_list()
    #state coordinate
    p=(52.2053, 0.1218)
    x=stations_by_distance(stations,p)
    #print nearest 10 stations
    print (x[:10])
    #print furthest 10 stations
    print (x[-10:])
Exemple #13
0
def run():

    stations = build_station_list()
    coord_camcity = (52.2053, 0.1218)
    stations_list = stations_by_distance(stations, coord_camcity)

    converted_list = convert(stations_list)

    closest_10 = converted_list[:10]
    furthest_10 = converted_list[-10:]

    print(f"{closest_10}\n{furthest_10}")
def run():
    """Requirements for Task 1B"""

    # Build list of stations
    stations = build_station_list()
    point = (52.2053, 0.1218)
    list_of_stations = stations_by_distance(stations, point)
    closest = list_of_stations[:10]
    furthest = list_of_stations[-10:]
    print("10 closest station to point P(52.2053, 0.1218): {}".format(closest))
    print(
        "10 furthest station to point P(52.2053, 0.1218): {}".format(furthest))
def run():
    # Build list of stations
    stations = build_station_list()
    p = (52.2053, 0.1218)
    distances = stations_by_distance(stations, p)
    station_names = []
    for (station, distance) in distances:
        details = (station.name, station.town, distance)
        station_names.append(details)

    print(station_names[:10])
    print(station_names[-10:])
def run():
    "Requirements for Task 1B"
    #Builds a list of stations 
    stations = stationdata.build_station_list(use_cache=True)

    #builds list of tuples of the stations with their distances from the coordinate
    stations_names_distances = geo.stations_by_distance(stations, (52.2053,0.1218))

    #prints the 10 stations that are closest to the coordinate
    print("CLOSEST 10 STATIONS:", stations_names_distances[:10])
    
    #prints the 10 stations that are furthest from the coordinate
    print("FURTHEST 10 STATIONS:", stations_names_distances[-10:])
Exemple #17
0
def test_stations_by_distance():

  # Build list of stations
    stations = build_station_list()
    p=(52.2053, 0.1218)
    x=stations_by_distance(stations,p)
    NoneType = type(None)
    #assert that the data types of each element in the tuples are correct and that they are sorted by distance
    for n in range(len(x)):
        assert isinstance(x[n][0],str)
        assert isinstance(x[n][1],str) or isinstance(x[n][1],NoneType)
        assert isinstance(x[n][2],float)
        if n!=(len(x)-1):
          assert x[n][2]<=x[n+1][2]
Exemple #18
0
def test_stations_by_distance():

     # Build list of stations
    stations = build_station_list()
    given_latitude=52.2053/180*(np.pi)
    given_longitude=0.1218/180*(np.pi)
    p=[given_latitude,given_longitude]
    distance=stations_by_distance(stations,p)
    test_list=[]
    for i in range (len(distance)):
        x=(distance[i][0].name, distance[i][0].town, distance[i][1])
        test_list.append(x)

    assert test_list[0]==('Cambridge Jesus Lock', 'Cambridge', 0.8402364350834995)
Exemple #19
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)
    p = [given_latitude, given_longitude]
    distance = stations_by_distance(stations, p)
    test_list = []
    for i in range(len(distance)):
        x = (distance[i][0].name, distance[i][0].town, distance[i][1])
        test_list.append(x)
    print(test_list[:10])
    print(test_list[-10:])
def run():
    """Requirements for Task 1B"""

    # Build list of stations
    stations = build_station_list()

    # Making station-distance list around Cambridge
    test_case = stations_by_distance(stations, (52.2053, 0.1218))
    x = [0]*len(test_case) #Creating a new list to store distances, names and towns of stations around Cambridge
    for i in range(len(test_case)):
        x[i] = (test_case[i][0].name, test_case[i][0].town, test_case[i][1])
    print("First Ten Entries")
    print(x[:10])
    print("Last Ten Entries")
    print(x[-10:])
Exemple #21
0
def run():
    #Input coordinates of Cambridge city centre
    Reference_coordinate = (52.2053, 0.1218)

    #Create list of tuples (station name, distance)
    TheList = stations_by_distance (build_station_list(), Reference_coordinate)
    
    #Create list of tuples (station name, town, distance) for the 10 closest and furthest stations
    closest = [(s.name, s.town, d) for s, d in TheList[:10]]
    furthest = [(s.name, s.town, d) for s, d in TheList[-10:]]
            
    print ("The closest 10 stations are:")
    print (closest)

    print ("The furthest 10 stations are:")
    print (furthest)
Exemple #22
0
def run():
    """Requirements for Task 1B"""
    print("*** Task 1B: CUED Part IA Flood Warning System ***")
    # Build list of stations
    stations = build_station_list()

    # Create list of tuples of station name and distance from Cambridge
    stations_from_cambridge = []
    stations_from_cambridge = stations_by_distance(stations, (52.2053, 0.1218))

    # Prints the 10 closest stations to Cambridge
    print("Closest 10 Stations to Cambridge:")
    print(stations_from_cambridge[:10])

    # Prints the 10 furthers stations from Cambridge
    print("Furthest 10 Stations from Cambridge:")
    print(stations_from_cambridge[-10:])
Exemple #23
0
def run():
    """Requirements for Task 1B"""

    # Build list of stations
    stations = build_station_list()

    # Sort the stations by distance from cambridge centre
    p = (52.2053, 0.1218)
    sorted_stations = stations_by_distance(stations, p)

    # Print the closest and furthest 10
    stations = []
    for station in sorted_stations:
        stations.append((station[0].name, station[0].town, station[1]))

    print(stations[:10])
    print(stations[-10:])
def run():
    """Requirements for Task 1B
    Prints a list of tuples (station name, town, distance)
    for the 10 closest and the 10 furthest stations from
    the Cambridge city centre, (52.2053, 0.1218)"""

    # Define the coordinates of Cambridge City Centre
    Cambridge_City_Centre = (52.2053, 0.1218)
    # Sort the stations by their distances to CCC
    stations_dis_order = stations_by_distance(
        build_station_list(), Cambridge_City_Centre)

    # Display the closest ten stations
    print([(station.name, station.town, dis)
           for station, dis in stations_dis_order[:10]])

    # Display the farthest ten stations
    print([(station.name, station.town, dis)
           for station, dis in stations_dis_order[-10:]])
def run():
    ''' Testing for stations_by_distance
    '''
    # generate stations list
    stations = build_station_list()

    # get distance
    p_cam_center = (52.2053, 0.1218)
    output = stations_by_distance(stations, p_cam_center)

    # change each element from (obj, dis) to (name, town, dis)
    output = [(station.name, station.town, distance)
              for station, distance in output]

    # do the output
    print(output[:10])
    print()
    print(output[-10:])
    return [output[:10], output[-10:]]
def run():
    """Requirements for Task 1B"""

    # Build list of stations and distances
    stations_distances = stations_by_distance(build_station_list(),
                                              (52.2053, 0.1218))

    # initialize output lists
    output_closest = []
    output_furthest = []

    # get name and town and distance of the ten closest stations
    for pair in stations_distances[:10]:
        output_closest.append((pair[0].name, pair[0].town, pair[1]))

    # get name and town and distance of the ten furthest stations
    for pair in stations_distances[-10:]:
        output_furthest.append((pair[0].name, pair[0].town, pair[1]))

    print(output_closest, output_furthest)
Exemple #27
0
def test_stations_by_distance():

    # Create a station
    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)

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

    #calling the function to be tested
    Example_list = stations_by_distance(Example_build_list, (2.0, -4.0))

    #testing the values of the 2 elements in the tuple in the list
    for s, d in Example_list[:]:
        assert s.name == "some station"
        assert d == 994.3960016965921
def test_stations_by_distance_returns_given_stations_in_order_of_distance_from_a_coordinate_p(
):
    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))

    p = (10.0, 10.0)
    actual_sorted_stations = geo.stations_by_distance(stations, p)
    expected_sorted_stations = [(stations[2], haversine(p, stations[2].coord)),
                                (stations[1], haversine(p, stations[1].coord)),
                                (stations[3], haversine(p, stations[3].coord)),
                                (stations[0], haversine(p, stations[0].coord))]

    assert expected_sorted_stations == actual_sorted_stations
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 23 18:22:24 2018

@author: Heisenberg
"""
from floodsystem.stationdata import build_station_list
from floodsystem.geo import stations_by_distance

stations = build_station_list()
p = (52.2053, 0.1218)

x = stations_by_distance(stations, p)

#Find first 10 stations
print("The closest 10 stations are:")
print()

for i in range(10):
    y = x[i][0]
    print(y.name)
    print(y.town)
    print(x[i][1])
    print()

#Find first 10 stations
print("The furthest 10 stations are:")
print()

for i in range(10):
Exemple #30
0
def test_stations_by_distance():
    result = stations_by_distance(stations, p=(0, 0))
    for i in range(1, len(result)):
        x = result[i]
        y = result[i - 1]
        assert x[2] >= y[2]