def test_stations_by_river(): #the third lock on the Thames should be Benson Lock assert stations_by_river(stations)['Thames'][2] == 'Benson Lock' #the second lock on the Cam should be Cambridge assert stations_by_river(stations)['River Cam'][1] == 'Cambridge'
def test_geo_4(): stations = build_station_list() stations_by_river_dict = stations_by_river(stations) assert stations_by_river_dict['River Wallington'] == [ 'Denmead', 'North Fareham weir' ]
def test_stations_by_river(): stations = build_station_list() x = stations_by_river(stations) assert type(x) == dict assert len(x) > 0 for item in x: assert type(item) == str
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'])
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)
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))
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)
def test_stations_by_river(): # make a station list - since we are comparing to a known output, use the test data station_list = stationdata.build_station_list(use_cache=False, test=True) stations_by_river = geo.stations_by_river(station_list) assert (len(stations_by_river['River Avon']) == 32) assert (len(stations_by_river['Baguley Brook']) == 1) assert (len(stations_by_river['River Thames']) == 55)
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))
def test_stations_by_river(): stations = gen_stations() rivers = geo.stations_by_river(stations) example_rivers = { "River Glen": stations[0:2], "River Parrett": stations[2:4], "Smestow Brook": [stations[4]] } assert rivers == example_rivers
def run2(): """2nd Requirement for Task 1D""" print('\033[1m'+ 'Stations by River') print("\n") stations = build_station_list() rivers = stations_by_river(stations) print("River Aire: ", sorted(rivers["River Aire"])) print("\n") print("River Cam: ", sorted(rivers["River Cam"])) print("\n") print("Thames: ", sorted(rivers["Thames"]))
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'])
def test_stations_by_river(): #Initialise variables stations = build_station_list() stationsbyriver = geo.stations_by_river(stations) test_river = "River Cam" test_station = "Cam" #Checks if test_station is present on test_river if test_station not in stationsbyriver[test_river]: raise ValueError( "Station \"{}\" not present on {} - data may be incomplete".format( test_station, test_river))
def test_stations_by_river(): """Test that the function returns the correct data""" stations = generate_test_station() s1, s2, s3, s4, s5, s6, s7 = stations assert stations_by_river(stations) == { 'River X': [s1, s3], 'River Y': [s2, s4, s5], 'River Z': [s6, s7] }
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))
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"])
def test_stations_by_river(): # Build a list of stations stations = build_station_list() ans = geo.stations_by_river(stations) assert 'Apperley Bridge' in ans['River Aire'] assert 'Cam' in ans['River Cam'] assert 'Cambridge' in ans['River Cam'] assert 'Benson Lock' in ans['Thames'] assert 'Kings Lock' in ans['Thames']
def test_stations_by_river(): stations = build_station_list() d = stations_by_river(stations) assert type(d) == dict for name, station_list in d.items(): assert type(name) == str assert type(station_list) == list for item in station_list: assert type(item) == str
def run(): """Requirements for Task 1D""" # Build list of stations stations = build_station_list() test_case_1 = rivers_with_stations(stations) print(len(test_case_1)) for i in range(10): print(test_case_1[i]) test_case_2 = stations_by_river(stations) print(test_case_2["Thames"])
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)
def test_stations_by_river(): 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 Y" s1 = MonitoringStation(s_id, m_id, label, coord, trange, river, town) stations = [s, s1] dict = geo.stations_by_river(stations) assert len(dict["River X"]) == 1 assert len(dict["River Y"]) == 1
def test_stations_by_river(): stations = build_station_list() r1 = stations_by_river(stations) g1 = r1["River Aire"] g2 = r1['River Cam'] g3 = r1['River Thames'] for i in stations: for j in g1: if i.name == g1: assert i.river == "River Aire" for k in g2: if i.name == g2: assert i.river == "River Cam" for l in g3: if i.name == g3: assert i.river == "River Thames"
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"]]))
def run(): """Requirements for Task 1D""" # print first 10 rivers with at least one monitoring station station_list = build_station_list() river_set = rivers_with_stations(station_list) print("Number of rivets with at least one monitoring station: {}".format( river_set)) print( "First 10 rivers with monitoring stations, in alphabetical order: \n {}" .format(sorted(river_set)[:10])) # print the stations which are near specific rivers, in alphabetical order station_river_dict = stations_by_river(station_list) rivers = ['River Aire', 'River Cam', 'River Thames'] for river in rivers: # make a list of station names for each river station_names = [s.name for s in station_river_dict[river]] print("Stations near {}: \n {}".format(river, sorted(station_names)))
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]]))
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'])
def test_stations_by_river_returns_a_dictionary_of_stations_by_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_stations_by_rivers = geo.stations_by_river(stations) expected_stations_by_rivers = dict() expected_stations_by_rivers["A"] = [stations[0], stations[3]] expected_stations_by_rivers["B"] = [stations[1], stations[4]] expected_stations_by_rivers["C"] = [stations[2]] expected_stations_by_rivers["D"] = [stations[5]] expected_stations_by_rivers["E"] = [stations[6]] assert actual_stations_by_rivers == expected_stations_by_rivers
else: high.append((station, in_top_twenty)) elif 1.25 >= station_level > 1: if in_top_twenty is True: high.append((station, in_top_twenty)) else: moderate.append((station, in_top_twenty)) else: low.append((station, in_top_twenty)) #ALERT LOCAL TOWNS (within 10km) OF FLOOD WARNING #ALSO ALERT ALL STATIONS ALSO ON SAME RIVER AS FLOODED STATION stations_on_same_rivers = stations_by_river(stations) print() print('STATIONS IN SEVERE CONDITION ARE:') if severe: for station in severe: name = station[0].name river = station[0].river relative_water_level = round(station[0].relative_water_level(), 3) print() print('Station: {}, River: {}, Relative water level: {}'.format( name, river, relative_water_level)) if station[1] == True: print('{} is on a river with the top twenty number of stations'. format(name)) print()
def test_stations_by_river(): stations = build_station_list() x = stations_by_river(stations) y = sorted(x['River Aire']) assert 'Airmyn' in y
def test_stations_by_river(): #check that it retirns demo prg result stations = build_station_list() stationsbyriver=stations_by_river(stations) assert stationsbyriver['River Thames']==['Abingdon Lock', 'Bell Weir', 'Benson Lock', 'Boulters Lock', 'Bray Lock', 'Buscot Lock', 'Caversham Lock', 'Chertsey Lock', 'Cleeve Lock', 'Clifton Lock', 'Cookham Lock', 'Cricklade', 'Culham Lock', 'Days Lock', 'Ewen', 'Eynsham Lock', 'Farmoor', 'Godstow Lock', 'Goring Lock', 'Grafton Lock', 'Hannington Bridge', 'Hurley Lock', 'Iffley Lock', 'Kings Lock', 'Kingston', 'Maidenhead', 'Mapledurham Lock', 'Marlow Lock', 'Marsh Lock', 'Molesey Lock', 'Northmoor Lock', 'Old Windsor Lock', 'Osney Lock', 'Penton Hook', 'Pinkhill Lock', 'Radcot Lock', 'Reading', 'Romney Lock', 'Rushey Lock', 'Sandford-on-Thames', 'Shepperton Lock', 'Shifford Lock', 'Shiplake Lock', 'Somerford Keynes', 'Sonning Lock', 'St Johns Lock', 'Staines', 'Sunbury Lock', 'Sutton Courtenay', 'Teddington Lock', 'Thames Ditton Island', 'Trowlock Island', 'Walton', 'Whitchurch Lock', 'Windsor Park']