def test_stations_level_over_threshold_and_stations_highest_rel_level():
    # two functions are very similar so tested together
    # 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)
    list_s = []
    list_s.append(s)
    list_s = list_s * 3
    for station in list_s:
        station.latest_level = 3.4445
    #disable the update water level function when using this test function
    list_of_stations = stations_level_over_threshold(list_s, 1)
    assert len(list_of_stations) == 3
    for station in list_s:
        station.latest_level = -2.3
    list_of_stations = stations_level_over_threshold(list_s, 0)
    assert len(list_of_stations) == 3
    list_of_stations = stations_highest_rel_level(list_s, 2)
    assert len(list_of_stations) == 2
Esempio n. 2
0
def test_stations_level_over_threshold():
    N = randint(0, 1000)
    n = N / 1000

    assert len(stations_level_over_threshold(stations, n)) > 0
    assert type(stations_level_over_threshold(stations, n)) == list
    for i in stations_level_over_threshold(stations, n):
        assert type(i) == tuple
        assert type(i[0]) == str
        assert type(i[1]) == float
Esempio n. 3
0
def run():

    stations = build_station_list()
    update_water_levels(stations)
    bad_stations = stations_level_over_threshold(stations, 0.8)
    for i in bad_stations:
        print(i[0].name, i[1])
Esempio n. 4
0
def run():
    # Build list of stations
    stations = build_station_list()
    update_water_levels(stations)
    stations_over_limit = stations_level_over_threshold(stations, 0.8)
    for station in stations_over_limit:
        print(station)
def run():
    # Build list of stations
    stations = build_station_list()
    update_water_levels(stations)
    output_list = stations_level_over_threshold(stations, 0.8)
    
    print(output_list)
def test_level_over_threshold_returns_an_ordered_list_of_stations_that_are_over_the_threshold_level():

    test_tol = 0.5
    s_id = "test-s-id"
    m_id = "test-m-id"
    label = "some station"
    coord = (-2.0, 4.0)
    river = "River X"
    town = "My Town"
    trange = (0, 1)
    s1 = MonitoringStation(s_id, m_id, label, coord, trange, river, town)
    s2 = MonitoringStation(s_id, m_id, label, coord, trange, river, town)
    s3 = MonitoringStation(s_id, m_id, label, coord, trange, river, town)
    s4 = MonitoringStation(s_id, m_id, label, coord, trange, river, town)
    s5 = MonitoringStation(s_id, m_id, label, coord, trange, river, town)
    s1.latest_level = 0.9
    s2.latest_level = 0.4
    s3.latest_level = 1.5
    s4.latest_level = -1.0
    s5.latest_level = None
    stations = [s1, s2, s3, s4, s5]

    expected_stations = [(s3, 1.5), (s1, 0.9)]
    actual_stations = stations_level_over_threshold(stations, test_tol)

    assert len(expected_stations) == len(actual_stations)
    for i in range(len(expected_stations)):
        assert expected_stations[i][0] == actual_stations[i][0]
        assert expected_stations[i][1] == round(actual_stations[i][1], 2)
Esempio n. 7
0
def run():

    stations = build_station_list()
    update_water_levels(stations)
    deliverables = stations_level_over_threshold(stations, tol=0.8)
    for a in deliverables:
        print(a[0].name)
def run():
    # Build list of stations
    stations = build_station_list()
    update_water_levels(stations)

    # Station names with the current relative level of 0.8
    for s in stations_level_over_threshold(stations, 0.9):
        print("{} {}".format(s[0].name, s[1]))
Esempio n. 9
0
def run():
    """ Requirement for Task 2B"""
    stations = build_station_list()
    update_water_levels(stations)
    tuplist = stations_level_over_threshold(stations, 0.8)

    for i in tuplist:
        print(i[0].name, " :", i[1])
Esempio n. 10
0
def test_stations_level_over_threshold():

    for i in stations_level_over_threshold(stations, 0.8):

        #ensures tuples returned
        assert type(i) == tuple

        #ensures that all the values are above the expected tolerance
        assert i[1] > 0.8
def test_stations_level_over_threshold():
    m = stations_level_over_threshold(stations,0.8,None)
    assert type(m) == list
    assert len(m) == 1
    assert m[0].name == 'Bourton Dickler'
    for i in range(len(m)):
        assert type(m[i][0])== str
        assert type(m[i][1])== float
        assert type(m[i])== tuple
def test_stations_level_over_threshold():
    tol = 0.8
    a = stations_level_over_threshold(stations, tol)
    for i in stations:
        for j in a:
            if j[0] == i.name:
                assert j[1] == i.relative_water_level(i.latest_level)
                assert j[1] > 0.8

    return
Esempio n. 13
0
def run():
    stations = build_station_list()

    update_water_levels(stations)

    stations_over_threshold = stations_level_over_threshold(stations, 0.7)

    for i in range(len(stations_over_threshold)):
        print(stations_over_threshold[i][0].name,
              stations_over_threshold[i][1])
Esempio n. 14
0
def run():

    stations = build_station_list()
    update_water_levels(stations)

    stations = stations_level_over_threshold(stations, 0.8)
    sorted_stations = sorted(stations, key=lambda tup: tup[1], reverse=True)

    for tuple in sorted_stations:
        print(f"{tuple[0].name} {tuple[1]}")
Esempio n. 15
0
def test_stations_level_over_threshold():
    stations = build_station_list()
    update_water_levels(stations)
    Aurimas = MonitoringStation(1234, 1234, "Aurimas", (1234, 1234), (0.5, 1),
                                "Sarva", "Vilnius", 1997 - 11 - 12, 1234)
    Aurimas.latest_level = 1
    stations.append(Aurimas)
    x = stations_level_over_threshold(stations, 0.9)

    assert (Aurimas, 1) in x
Esempio n. 16
0
def test_flood():
    disagree = 0
    stations = build_station_list()
    stations_level_over_threshold_list = []
    stations_level_over_threshold_list = stations_level_over_threshold(stations, 0.6)
    for i in range(len(stations_level_over_threshold_list)):
        if stations_level_over_threshold_list[i][1] < 0.6:
            disagree += 1
        else:
            pass
    assert disagree == 0
Esempio n. 17
0
def test_stations_level_over_threshold():

    # Build list of stations
    stations = build_station_list()
    update_water_levels(stations)

    present = flood.stations_level_over_threshold(stations, 0.8)
    assert present[0][1] > 0.8
    if len(present) > 1:
        # The returned list should be in descending order
        assert present[0][1] >= present[1][1]
Esempio n. 18
0
def test_stations_level_over_threshold():
    #Initialise variables
    stations = build_station_list()
    update_water_levels(stations)
    #Unrealistic tolerance value
    tol = 10
    #Checks no stations have an unrealistic relative water level
    slot = flood.stations_level_over_threshold(stations, tol)
    if slot != []:
        raise ValueError(
            "Stations present with relative water level greater than {}".
            format(tol))
    #Realistic tolerance value
    tol2 = 0.5
    #Checks stations are present with a realistic relative water level
    slot2 = flood.stations_level_over_threshold(stations, tol2)
    if slot2 == []:
        raise ValueError(
            "No stations present with relative water level greater than {}".
            format(tol2))
def run():
    """Requirements for task 2B"""
    # build the station list and update the current levels
    station_list = build_station_list()
    update_water_levels(station_list, use_cache=True)

    threshold = 0.8
    over_thresh = stations_level_over_threshold(station_list, threshold)

    for station, level in over_thresh:
        print(station.name, level)
Esempio n. 20
0
def run():
    """Requrement for Task 2B"""

    stations = build_station_list()
    update_water_levels(stations)

    #Creates list of stations with relative water level greater than 0.8
    #sorted by relative water level
    slot = stations_level_over_threshold(stations, 0.8)

    for station in slot:
        print("{} {}".format(station[0], station[1]))
Esempio n. 21
0
def run():

    # Build list of stations
    stations = build_station_list()

    # Update latest level data for all stations
    update_water_levels(stations)

    stations_over_threshold = stations_level_over_threshold(stations, 0.8)

    for i in stations_over_threshold:
        print(i[0], i[1])
def test_stations_level_over_threshold():
    # build the station list and update the current levels
    station_list = stationdata.build_station_list()
    stationdata.update_water_levels(station_list, use_cache=True)

    threshold = 0.8
    over_thresh = flood.stations_level_over_threshold(station_list, threshold)

    # ensure descending order
    assert (all(prev[1] >= this[1] for prev, this in zip(over_thresh, over_thresh[1:])))
    # ensure all levels are above the threshold
    assert (all(level > threshold for _, level in over_thresh))
Esempio n. 23
0
def run():
    """testing for station_level_over_threshold
    """

    # generate stations list
    stations = build_station_list()

    # output station with relative water level above 0.8
    output = stations_level_over_threshold(stations, 0.8)

    # print with format: name, relative level
    for station in output:
        print(station.name, station.rel_level)
Esempio n. 24
0
def test_stations_level_over_threshhold():
    """Assert that the function will only return the consistent stations that are about 0.5 tolerance
    Of the example data, only 2 are consistent, and only 1 is above the tolerance"""

    stations = gen_stations()
    # assign each level in turn to one of the stations
    latest_levels = [0.07, 0.21, 0.45, 0.1, 1.332]
    for i, station in enumerate(stations):
        station.latest_level = latest_levels[i]

    above_tol = stations_level_over_threshold(stations, 0.5)
    assert len(above_tol) == 1
    assert above_tol[0][0] == stations[4]
Esempio n. 25
0
def run():
    """Requirements for Task 2B
    """
    
    print("*** Task 2B: CUED Part IA Flood Warning System ***")

    # Build list of stations
    stations = build_station_list()
    stations_level_over_threshold_list = []
    stations_level_over_threshold_list = stations_level_over_threshold(stations, 0.8)

    print("List of stations with relative water level over the tolerance (0.8) and their relative water levels:")
    for i in range(len(stations_level_over_threshold_list)):
        print("Station name and current relative level: {}, {}".format(stations_level_over_threshold_list[i][0], stations_level_over_threshold_list[i][1]))
Esempio n. 26
0
def run():
    # Build list of stations
    stations = build_station_list()

    # Update latest level data for all stations
    update_water_levels(stations)

    # Print station and latest level for first 5 stations in list
    tol = 0.8
    x = stations_level_over_threshold(stations, tol)
    y = []
    for station, ratio in x:
        y.append((station.name, ratio))
    print(y)
def test_stations_level_over_threshold():
    stations = build_station_list()
    update_water_levels(stations)
    stations_water_levels = fl.stations_level_over_threshold(stations, 0.8)
    #Testing if the list is ordered
    assert all(stations_water_levels[i][1] >= stations_water_levels[i + 1][1]
               for i in range(len(stations_water_levels) - 1))
    #Testing if the output is a list of tuples and if the tuples have 2 elements each
    assert type(stations_water_levels) == list
    if len(stations_water_levels) >= 0:
        assert type(stations_water_levels[0]) == tuple
        assert len(stations_water_levels[0]) == 2
    #Testing that none of the water levels are None
    for item in stations_water_levels:
        assert item[1] != None
Esempio n. 28
0
def run():
    # Build list of stations
    stations = build_station_list()

    # Update latest level data for all stations
    update_water_levels(stations)

    water_level_stations = stations_level_over_threshold(stations, 0.8)

    station_names = []

    for station, water_level in water_level_stations:
        details = (station.name, water_level)
        station_names.append(details)

    print(station_names)
Esempio n. 29
0
def run():
    """Requirements for Task2B"""

    # Build list of stations
    stations = build_station_list()
    update_water_levels(stations)

    # Define tolerance
    tol = 0.8

    # Get the list of stations (tuples) whose water level is
    # over tol to present
    present = flood.stations_level_over_threshold(stations, tol)

    for station in present:
        print("{} {}".format(station[0], station[1]))
Esempio n. 30
0
def test_stations_level_over_thershold():
    stations = generate_test_station()
    stations[0].typical_range, stations[0].latest_level = (0,
                                                           5), 2.5  # Station 1
    stations[1].typical_range, stations[1].latest_level = (
        0, 2.5), 2.5  # Station 2
    stations[2].typical_range, stations[2].latest_level = (0,
                                                           1), 0  # Station 3

    # all other stations are inconsistant

    over_thers_stations = stations_level_over_threshold(stations, 0.2)
    # Station 3 lower that thershold

    assert over_thers_stations[0][1] == 0.5
    assert over_thers_stations[1][1] == 1