def test_build_station_list(): # Build list of stations stations = build_station_list() # Find station 'Cam' for station in stations: if station.name == 'Cam': station_cam = station break # Assert that station is found assert station_cam # Fetch data over past 2 days dt = 2 dates2, levels2 = fetch_measure_levels(station_cam.measure_id, dt=datetime.timedelta(days=dt)) assert len(dates2) == len(levels2) # Fetch data over past 10 days dt = 10 dates10, levels10 = fetch_measure_levels(station_cam.measure_id, dt=datetime.timedelta(days=dt)) assert len(dates10) == len(levels10) assert len(dates10) > len(levels2)
def run(): stations = build_station_list() nearby_stations = stations_within_radius(stations, CAMBRIDGE_COORDINATES, 10) nearby_stations_names = map(lambda w: w.name, nearby_stations) print(sorted(nearby_stations_names))
def run(): stations = build_station_list() rivers = rivers_with_station(stations) stations_to_rivers = stations_by_river(stations) print(stations_to_rivers["River Aire"]) print(stations_to_rivers["River Cam"]) print(stations_to_rivers["Thames"]) list_1 = list(stations_to_rivers) print(list_1[0:10])
def run(): """Requirements for Task 1A""" # Build list of stations stations = build_station_list() distances = stations_by_distance(stations, CAMBRIDGE_COORDINATES) sorted_distances = list( map(lambda d: (d[0].name, d[0].town, d[1]), distances)) print(sorted_distances[-10:])
def run(): stations = build_station_list() update_water_levels(stations) highest_stations = stations_highest_rel_level(stations, 5) dt = 10 for s in highest_stations: dates, levels = fetch_measure_levels(s[0].measure_id, dt=datetime.timedelta(days=dt)) # print(dates, levels) plot_water_level_with_fit(s[0], dates, levels, 4)
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 names = ['Bourton Dickler', 'Surfleet Sluice', 'Gaw Bridge', 'Hemingford','Swindon'] for station in stations: if station.name in names: print("Station name and current level: {}, {}".format(station.name, station.latest_level))
def run(): """Requirements for Task 1A""" # Build list of stations stations = build_station_list() # Print number of stations print("Number of stations: {}".format(len(stations))) # Display data from 3 stations: for station in stations: if station.name in [ 'Bourton Dickler', 'Surfleet Sluice', 'Gaw Bridge' ]: print(station)
def test_update_level(): """Test update to latest water level""" # Build list of stations stations = build_station_list() for station in stations: assert station.latest_level == None # Update latest level data for all stations update_water_levels(stations) counter = 0 for station in stations: if station.latest_level is not None: counter += 1 assert counter > 0
def run(): # Build list of stations stations = build_station_list() # Station name to find station_name = "Cam" # Find station station_cam = None for station in stations: if station.name == station_name: station_cam = station break # Check that station could be found. Return if not found. if not station_cam: print("Station {} could not be found".format(station_name)) return # Alternative find station 'Cam' using the Python 'next' function # (https://docs.python.org/3/library/functions.html#next). Raises # an exception if station is not found. # try: # station_cam = next(s for s in stations if s.name == station_name) # except StopIteration: # print("Station {} could not be found".format(station_name)) # return # Fetch data over past 2 days dt = 2 dates, levels = fetch_measure_levels(station_cam.measure_id, dt=datetime.timedelta(days=dt)) # Print level history for date, level in zip(dates, levels): print(date, level)
def test_rivers_with_station (): stations = build_station_list() test_set = analyse.geo.rivers_with_station(stations) assert type(test_set) == list
def run(): stations = build_station_list() update_water_levels(stations) output = analysis_station(stations, "severe") print(output)
def run(): stations = build_station_list() print(inconsistent_typical_range_stations(stations))
def test_stations_within_radius(): stations = build_station_list() test_list1 = analyse.geo.stations_within_radius(stations, (52.2053, 0.1218), 10) assert type(test_list1) == filter
def run(): stations = build_station_list() print(rivers_by_station_number(stations, 9))
def test_stations_by_river(): stations = build_station_list() test_dict = analyse.geo.stations_by_river(stations) assert type(test_dict) == dict
def test_rivers_by_station_number(): stations = build_station_list() test_object = analyse.geo.rivers_by_station_number(stations, 9) assert type(test_object) == list
def test_build_station_list(): """Test building list of stations""" station_list = build_station_list() assert len(station_list) > 0
def test_stations_by_distance(): stations = build_station_list() test_list2 = analyse.geo.stations_by_distance(stations, (52.2053, 0.1218)) assert type(test_list2) == list
def run(): stations = build_station_list() update_water_levels(stations) dangerous_stations = station_level_over_threshold(stations,0.8) print (list(map(lambda s: [s[0].name, s[1]], dangerous_stations)))