コード例 #1
0
def test_rivers_with_station():

    # Build list of stations
    stations = build_station_list()

    ans = geo.rivers_with_station(stations)
    assert len(ans) == len(set(ans))  # All elements should be unique
コード例 #2
0
def run():
    '''Requrements for Task 1D'''

    # Builds Stations List
    stations = build_station_list()

    # Compiles a list of rivers. prints the length and first ten
    riversWithStation = rivers_with_station(stations)
    print(len(riversWithStation))
    sortedList = sorted(riversWithStation)
    print(sortedList[:10])

    # Compiles a list of stations sorted by river and prints a list of stations on three rivers in particular
    stationsByRiver = stations_by_river(stations)
    riverAire = list()
    riverCam = list()
    riverThames = list()
    for station in stationsByRiver['River Aire']:
        riverAire.append(station.name)
        riverAire.sort()

    for station in stationsByRiver['River Cam']:
        riverCam.append(station.name)
        riverCam.sort()

    for station in stationsByRiver['River Thames']:
        riverThames.append(station.name)
        riverThames.sort()

    print(riverAire, '\n', riverCam, '\n', riverThames)
コード例 #3
0
def run():
    #builds a list of stations
    stations = stationdata.build_station_list(use_cache=True)
    #builds a list of rivers that have at least one monitoring station
    rivers = geo.rivers_with_station(stations)
    #builds a dictionary of rivers matched with their monitoring stations
    rivers_stations = geo.stations_by_river(stations)

    #counts the number of rivers that have at least one monitoring station
    number_rivers = len(rivers)
    print(number_rivers)

    #orders the list of rivers with monitoring stations alphabetically
    order_rivers = sorted(rivers)
    #creates an empty list
    rivers_first = list()
    #adds the first 10 rivers alphabetically to the empty list
    for i in range(0, 10):
        rivers_first.append(order_rivers[i])

    print(rivers_first)

    #returns the monitoring stations for River Aire in alphabetical order
    river_aire = rivers_stations["River Aire"]
    print("RIVER AIRE:", sorted(river_aire))

    #returns the monitoring stations for River Cam in alphabetical order
    river_cam = rivers_stations["River Cam"]
    print("RIVER CAM:", sorted(river_cam))

    #returns the monitoring stations for River Thames in alphabetical order
    river_thames = rivers_stations["River Thames"]
    print("RIVER THAMES", sorted(river_thames))
コード例 #4
0
ファイル: test_geo.py プロジェクト: j-m-nash/Past-Projects
def test_geo_3():

    stations = build_station_list()
    rivers_with_station_list = sorted(rivers_with_station(stations))
    assert rivers_with_station_list[0] == 'Addlestone Bourne'
    for i in range(100, 200):
        assert rivers_with_station_list[i] != rivers_with_station_list[i + 1]
コード例 #5
0
def test_rivers_with_station():
    # 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)

    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)

    k = rivers_with_station(Example_build_list)

    assert len(k) == 2
コード例 #6
0
ファイル: Task1D.py プロジェクト: j-m-nash/Past-Projects
def run():
    """Requirements for Task 1D"""

    print("*** Task 1D: CUED Part IA Flood Warning System ***")

    #Build list of stations
    stations = build_station_list()
    rivers_with_station_list = rivers_with_station(stations)

    # Count number of unique rivers
    print("Number of unique rivers:")
    print(len(rivers_with_station_list))

    #List the first ten alphabetically
    print("First ten rivers alphabetically:")
    print(rivers_with_station_list[:10])

    #List the stations on the specified rivers
    stations_by_river_dict = stations_by_river(stations)
    print("Stations on the River Aire:")
    print(stations_by_river_dict['River Aire'])
    print("Stations on the River Cam:")
    print(stations_by_river_dict['River Cam'])
    print("Stations on the River Thames:")
    print(stations_by_river_dict['River Thames'])
コード例 #7
0
def run():
    stations = build_station_list()
    """ Part 1 of Task 1D
    """

    a = rivers_with_station(stations)
    """ Sorting the list of rivers
    """

    b = sorted(a)
    print(len(a), '\n')
    """Getting the first 10 entries
    """

    print(b[:10], '\n')
    """ Part 2 of Task 1D
    """
    riverdict = stations_by_rivers(stations)

    c = riverdict["River Aire"]
    d = riverdict["River Cam"]
    e = riverdict["Thames"]

    print(sorted(c), '\n')
    print(sorted(d), '\n')
    print(sorted(e))
コード例 #8
0
def run():

    #build station list
    stations = build_station_list()

    #creates sorted set of rivers monitored
    rivers_monitored = rivers_with_station(stations)

    #prints the first 10 entries in the set
    print("\n", "First 10 stations with Monitoring Stations:")
    for i in range(10):
        print(rivers_monitored[i])

    #generates dictionary
    stations_by_river_dict = stations_by_river(stations)

    #prints dictionary entries for 3 rivers
    print("\n", "Stations on the River Aire:")
    riveraire = stations_by_river_dict['River Aire']
    for i in riveraire:
        print(i)

    print("\n", "Stations on the River Cam:")
    rivercam = stations_by_river_dict['River Cam']
    for i in rivercam:
        print(i)

    print("\n", "Stations on the Thames:")
    thames = stations_by_river_dict['Thames']
    for i in thames:
        print(i)
コード例 #9
0
def run():
    """Requrement for Task 1D"""

    stations = build_station_list()
    rivers=rivers_with_station(stations)

    def test_first_x_rivers_with_station(x):
        """Calls the <<rivers_with_station>> function and prints the
        total number of rivers and the first x rivers with a station"""
        #Prints the total number of rivers
        print("Total rivers with stations: {}\n".format(str(len(rivers))))
        #Converts the set into a sorted list
        rivers_in_order=sorted(rivers)
        #Creates empty list of first x rivers
        test_rivers=[]
        #Adds first x rivers to list
        for river in rivers_in_order[:x]:
            test_rivers.append(river)
        print("First {} rivers with stations: {}\n".format(x, test_rivers))
            
    def test_stations_by_river(rivers):
        """Calls the <<stations_by_river>> function and prints a list of
        stations for each river in a list"""
        stationsbyriver=stations_by_river(stations)
        for river in rivers:
            #Calls list of stations on a river
            test_stations=stationsbyriver.get(river)
            #Sorts list of stations
            stations_in_order=sorted(test_stations)
            print("Stations on {}: {}\n".format(river, stations_in_order))
    
    test_first_x_rivers_with_station(10)
    test_stations_by_river(["River Aire", "River Cam", "Thames"])
コード例 #10
0
def test_river_with_station():

    # builds stations and list of rivers
    s_id = "test-s-id"
    m_id = "test-m-id"
    label = "some station"
    coord = (6.0, 4.0)
    trange = None
    river = "River X"
    town = "My Town"
    s = MonitoringStation(s_id, m_id, label, coord, trange, river, town)
    river = "River X"
    s1 = MonitoringStation(s_id, m_id, label, coord, trange, river, town)
    river = "River Y"
    s2 = MonitoringStation(s_id, m_id, label, coord, trange, river, town)
    river = "River Y"
    s3 = MonitoringStation(s_id, m_id, label, coord, trange, river, town)
    river = "River Z"
    s4 = MonitoringStation(s_id, m_id, label, coord, trange, river, town)
    stations = [s, s1, s2, s3, s4]
    rivers = geo.rivers_with_station(stations)

    #Makes sure that data processing is valid
    assert rivers is not None
    assert len(rivers) == 3
    assert "River X" in rivers
    assert "River Y" in rivers
    assert "River Z" in rivers
コード例 #11
0
def test_rivers_with_station():

    stations = build_station_list()
    l = rivers_with_station(stations)

    assert type(l) == list
    for item in l:
        assert type(item) == str
コード例 #12
0
def test_rivers_with_station():
  stations = build_station_list()
  riverswithstation=rivers_with_station(stations)
  #check that there are no duplicates
  assert len(riverswithstation)==len(set(riverswithstation))
  #check that it is a list
  assert isinstance(riverswithstation,list)
  #check that it returns demonstration prog result
  assert riverswithstation[:1]==['Addlestone Bourne']
コード例 #13
0
def test_rivers_with_station():
    stations = build_station_list()
    r = rivers_with_station(stations)
    assert len(r) == 857
    for i in stations:
        for j in r:
            a = 0
            if i.river == j:
                a = a + 1
                assert a >= 1
def run():
    """1st Requirement for Task 1D"""
    stations = build_station_list()
    # Build set of rivers
    rivers = rivers_with_station(stations)
    sorted_rivers = sorted(rivers)
    print("First 10 rivers in alphabetical order:", sorted_rivers[:10])
    # print
    print("\n")
    print("Number of rivers with at least one station:", len(rivers))
コード例 #15
0
def run():

    # Build list of stations
    stations = build_station_list()

    rivers = rivers_with_station(stations)
    d = stations_by_river(stations)
    print(rivers[:10])
    print(d['River Aire'])
    print(d['River Cam'])
    print(d['Thames'])
コード例 #16
0
def run():
    stations = build_station_list()
    rivers = rivers_with_station(stations)
    print("Number of rivers: {}".format(len(rivers)))
    print("First ten rivers: {}".format(sorted(rivers)[:10]))

    rivers_dict = stations_by_river(stations)
    test_rivers = ("River Aire", "River Cam", "River Thames")
    for river in test_rivers:
        stations_on_river = rivers_dict.get(river)
        station_names = [s.name for s in stations_on_river]
        print("Stations on {}: {}".format(river, station_names))
コード例 #17
0
def run():
    """Requirements for Task 1D"""

    # Build list of stations
    stations = build_station_list()
    riverswithstation = rivers_with_station(stations)
    print(len(riverswithstation))
    riverswithstation = (riverswithstation)
    print(riverswithstation[:10])

    stationsbyriver = stations_by_river(stations)
    print(stationsbyriver["River Thames"])
コード例 #18
0
def test_rivers_with_station():
    #Initialise variables
    stations = build_station_list()
    rivers = geo.rivers_with_station(stations)
    test_river = "River Cam"
    if len(rivers) < 100:
        raise ValueError(
            "Less than 100 rivers in set - data may be incomplete")
        #Checks of test_river is present in list of rivers
    if test_river not in rivers:
        raise ValueError(
            "{} not present - data may be incomplete".format(test_river))
コード例 #19
0
def run():
    stations = build_station_list()
    rivers = rivers_with_station(stations)

    rivers_sorted = sorted(rivers)
    print(rivers_sorted[:10])
    print()
    dict = stations_by_river(stations)

    check_rivers = ['River Aire', 'River Cam', 'River Thames']
    for check_river in check_rivers:
        list1 = dict[check_river]
        station_names = [x.name for x in list1]
        station_names = sorted(station_names)
        print(station_names)
コード例 #20
0
def run():
    """Requirements for Task 1D"""
    # Build list of stations
    stations = build_station_list()

    # Sort the stations by distance from cambridge centre
    rivers = rivers_with_station(stations)

    # Print the first 10 rivers
    print("{} stations. First 10 - {}".format(len(rivers), sorted(rivers)[:10]))

    # Get the dictionary of stations by river
    by_rivers = stations_by_river(stations)

    # Print the 3 entries
    print(sorted([station.name for station in by_rivers["River Aire"]]))
    print(sorted([station.name for station in by_rivers["River Cam"]]))
    print(sorted([station.name for station in by_rivers["River Thames"]]))
コード例 #21
0
def test_rivers_with_station_returns_all_rivers():
    stations = []
    rivers = ["A", "B", "C", "A", "B", "D", "E"]
    for i in range(len(rivers)):
        # Create stations
        s_id = "test-s-id-" + str(i)
        m_id = "test-m-id-" + str(i)
        label = "some station " + str(i)
        coord = (0.0, 0.0)
        trange = (-2.3, 3.4445)
        river = rivers[i]
        town = "My Town " + str(i)
        stations.append(
            MonitoringStation(s_id, m_id, label, coord, trange, river, town))

    actual_rivers = geo.rivers_with_station(stations)
    expected_rivers = {"A", "B", "C", "D", "E"}

    assert actual_rivers == expected_rivers
コード例 #22
0
def run():
    """
    * Print how many rivers have at least one monitoring station
    * Prints the first 10 of these rivers in alphabetical order
    * Print the names of the stations located on the following rivers in alphabetical order:
        - 'River Aire'
        - 'River Cam'
        - 'River Thames'
    """
    stations = build_station_list()
    rivers = rivers_with_station(stations)
    print(len(rivers))
    print(sorted(rivers)[:10])

    print()

    stations_on_river = stations_by_river(stations)
    for river in ['River Aire', 'River Cam', 'River Thames']:
        print(river + ':')
        print(sorted([i.name for i in stations_on_river[river]]))
コード例 #23
0
def test_rivers_by_station_number():

    stations = build_station_list()
    l = rivers_with_station(stations)
    N = len(l)
    output = rivers_by_station_number(stations, N)

    assert type(output) == list

    for t in output:
        assert type(t) == tuple
        assert len(t) == 2
        assert type(t[0]) == str
        assert type(t[1]) == int

        # Check if list of river tuples is in descending order
        list_of_lists = []
        # Convert list of tuples to list of lists
        list_of_lists.append(list(t))
        for n in range(len(list_of_lists) - 1):
            assert list_of_lists[n][1] <= list_of_lists[n + 1][1]
コード例 #24
0
def run():
    """Requirements for Task1D"""

    # Build a list of stations
    stations = build_station_list()
    # Get a list of rivers with stations
    RiverWithStation = list(geo.rivers_with_station(stations))
    RiverWithStation.sort()
    # Get first 10
    print(RiverWithStation[:10])

    # Get a dict of river->stations on this river
    RiverByStation = geo.stations_by_river(stations)
    # Get required things
    RiverByStation['River Aire'].sort()
    print(RiverByStation['River Aire'])

    RiverByStation['River Cam'].sort()
    print(RiverByStation['River Cam'])

    RiverByStation['Thames'].sort()
    print(RiverByStation['Thames'])
コード例 #25
0
from floodsystem.geo import rivers_with_station
from floodsystem.geo import stations_on_rivers
from floodsystem.stationdata import build_station_list

stations = build_station_list()
"""rivers have at least one monitoring station"""
set_of_rivers = rivers_with_station(stations)
list_of_rivers = list(set_of_rivers)
"""prints the first 10 of these rivers in alphabetical order"""
print(sorted(list_of_rivers)[:10])
"""dictionary that maps river names to a list of stations on a given river"""
dictionary_of_rivers = stations_on_rivers(set_of_rivers, stations)
"""print the names of the stations located on some rivers in alphabetical order"""
print(sorted(dictionary_of_rivers['River Aire']))
print(sorted(dictionary_of_rivers['River Cam']))
print(sorted(dictionary_of_rivers['Thames']))
コード例 #26
0
    for i in unique_labels:
        if i != -1:  # not noise
            for coord in X[labels == i]:
                location_map3.circle(x=coord[1], y=coord[0], size=10, color=cluster_pallet[i], fill_alpha=0.8)
                label_to_stations[i].append(coord_to_station[(coord[0], coord[1])])
                # find the station from its coordinates and append it to the dictionary

    location_map3.plot_width = 700
    location_map3.plot_height = 500
    location_map3.sizing_mode = 'scale_width'

    # Risky rivers
    warning_text2 = Div(
        text="""<p><b>{}</b> rivers with stations at risk, the top 5 is tabulated below.</p>""".format(
            len(rivers_with_station(risky_stations))),
        width=600
    )
    warning_text2.sizing_mode = 'scale_width'

    risky_rivers = rivers_by_station_number(risky_stations, 5)
    risky_rivers_source = ColumnDataSource(
        data=dict(name=[i[0] for i in risky_rivers], num=[i[1] for i in risky_rivers])
    )
    risky_river_table_columns = [
        TableColumn(field="name", title="River Name"),
        TableColumn(field="num", title="Number of Risky Stations"),
    ]
    risky_river_table = DataTable(source=risky_rivers_source, columns=risky_river_table_columns, width=500, height=140)
    risky_river_table.sizing_mode = 'scale_width'
コード例 #27
0
def test_rivers_with_station():
    """Test that the function returns the correct data without duplicates"""

    stations = generate_test_station()

    assert rivers_with_station(stations) == {"River X", "River Y", "River Z"}
コード例 #28
0
from floodsystem.geo import rivers_with_station
from floodsystem.geo import stations_by_river
from floodsystem.stationdata import build_station_list
stations = build_station_list()
list_of_all_rivers = sorted(rivers_with_station(stations))
print(len(list_of_all_rivers))
print(list_of_all_rivers[0:10])

dic_of_rivers = stations_by_river()

riv = str(input("What is the river?"))
print(sorted(dic_of_rivers[riv]))

"River Aire, River Cam, Thames"
コード例 #29
0
def test_rivers_with_station():
    stations = build_station_list()
    x = rivers_with_station(stations)
    sorted_stations = sorted(x)

    assert 'Adur' in sorted_stations
コード例 #30
0
def test_rivers_with_station():
    b = rivers_with_station(stations)
    for i in range(len(b)):
        assert type(b[i]) == str
    assert len(b) > 0