Spaces:
Sleeping
Sleeping
David-Chew-HL
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -25,7 +25,7 @@ def calculate_distances(coords):
|
|
25 |
|
26 |
return distances, shortest_distances
|
27 |
|
28 |
-
def plot_on_map(coords_list, shortest_distance, longest_shortest_distance, avg_distance
|
29 |
all_coords = [coord for coords in coords_list for coord in coords]
|
30 |
avg_lat = np.mean([coord[0] for coord in all_coords])
|
31 |
avg_lon = np.mean([coord[1] for coord in all_coords])
|
@@ -64,20 +64,18 @@ def generate_map_with_stats(postcode_groups_input):
|
|
64 |
coords = group['coords'].apply(lambda x: tuple(map(float, x.strip('()').split(',')))).tolist()
|
65 |
coords_list.append(coords)
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
all_distances.extend(distances)
|
73 |
-
all_shortest_distances.extend(shortest_distances)
|
74 |
|
75 |
-
if
|
76 |
-
shortest_distance = min(
|
77 |
-
longest_shortest_distance = max(
|
78 |
-
avg_distance = np.mean([dist[0] for dist in
|
79 |
|
80 |
-
map_object = plot_on_map(
|
81 |
|
82 |
statistics = []
|
83 |
for i, postcode_group in enumerate(postcode_groups):
|
@@ -100,5 +98,4 @@ iface = gr.Interface(
|
|
100 |
article="\n\n\n*Store location data was last updated in February 2024.",
|
101 |
)
|
102 |
|
103 |
-
|
104 |
iface.launch(share=True)
|
|
|
25 |
|
26 |
return distances, shortest_distances
|
27 |
|
28 |
+
def plot_on_map(coords_list, shortest_distance, longest_shortest_distance, avg_distance):
|
29 |
all_coords = [coord for coords in coords_list for coord in coords]
|
30 |
avg_lat = np.mean([coord[0] for coord in all_coords])
|
31 |
avg_lon = np.mean([coord[1] for coord in all_coords])
|
|
|
64 |
coords = group['coords'].apply(lambda x: tuple(map(float, x.strip('()').split(',')))).tolist()
|
65 |
coords_list.append(coords)
|
66 |
|
67 |
+
# Combine all coordinates into a single list
|
68 |
+
all_coords = [coord for coords in coords_list for coord in coords]
|
69 |
+
|
70 |
+
if all_coords:
|
71 |
+
distances, shortest_distances = calculate_distances(all_coords)
|
|
|
|
|
72 |
|
73 |
+
if shortest_distances:
|
74 |
+
shortest_distance = min(shortest_distances, key=lambda x: x[0])
|
75 |
+
longest_shortest_distance = max(shortest_distances, key=lambda x: x[0])
|
76 |
+
avg_distance = np.mean([dist[0] for dist in shortest_distances])
|
77 |
|
78 |
+
map_object = plot_on_map([all_coords], shortest_distance, longest_shortest_distance, avg_distance)
|
79 |
|
80 |
statistics = []
|
81 |
for i, postcode_group in enumerate(postcode_groups):
|
|
|
98 |
article="\n\n\n*Store location data was last updated in February 2024.",
|
99 |
)
|
100 |
|
|
|
101 |
iface.launch(share=True)
|