David-Chew-HL commited on
Commit
eb9aa71
·
verified ·
1 Parent(s): e0a0166

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -14
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, postcode_groups):
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
- if coords_list:
68
- all_distances = []
69
- all_shortest_distances = []
70
- for coords in coords_list:
71
- distances, shortest_distances = calculate_distances(coords)
72
- all_distances.extend(distances)
73
- all_shortest_distances.extend(shortest_distances)
74
 
75
- if all_shortest_distances:
76
- shortest_distance = min(all_shortest_distances, key=lambda x: x[0])
77
- longest_shortest_distance = max(all_shortest_distances, key=lambda x: x[0])
78
- avg_distance = np.mean([dist[0] for dist in all_shortest_distances])
79
 
80
- map_object = plot_on_map(coords_list, shortest_distance, longest_shortest_distance, avg_distance, postcode_groups)
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)