generated from CambridgeEngineering/PartIA-Flood-Warning-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Task1B.py
52 lines (33 loc) · 1.91 KB
/
Task1B.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from floodsystem.geo import stations_by_distance
from floodsystem.stationdata import build_station_list
def run():
"""Requirements for task 1B"""
stations = build_station_list() # Make a list of stations
p = 52.2053, 0.1218 # Insert coordinates
station_names = [] # Make empty lists for the station names, towns they are nearest to,
# and their distances from the coordinates
towns = []
distances_from_p = []
x = 0 # Set counting variable to go through list
for station in stations_by_distance(stations, p)[:10]: # Goes through the list created by the stations_by_distance
# command and takes data to add to the 3 lists created previously
station_names.append(stations_by_distance(stations, p)[x][0].name)
towns.append(stations_by_distance(stations, p)[x][0].town)
distances_from_p.append(stations_by_distance(stations, p)[x][1])
x += 1 # Counting variable increases with each loop
nearest = list(zip(station_names, towns, distances_from_p)) # Create list of tuples for nearest stations
print(x, "nearest are:", nearest) # Print list
# Second half of the code is similar to the first half, but displays data for the furthest stations
station_names.clear() # Clear previous lists
towns.clear()
distances_from_p.clear()
y = 0 # Set new counting variable
furthest_stations = stations_by_distance(stations, p)[-10:] # Create list of 10 furthest stations
for station in furthest_stations: # Take data from this list as before to add to the 3 lists.
station_names.append(furthest_stations[y][0].name)
towns.append(furthest_stations[y][0].town)
distances_from_p.append(furthest_stations[y][1])
y += 1
furthest = list(zip(station_names, towns, distances_from_p)) # Create list of tuples for furthest stations
print(y, "furthest are:", furthest) # Print furthest stations
run()