Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -106,6 +106,7 @@ def process_excel(file, places_column):
|
|
106 |
geocoder = SafeGeocoder()
|
107 |
coords = []
|
108 |
processed_count = 0
|
|
|
109 |
|
110 |
# Process each row
|
111 |
for idx, row in df.iterrows():
|
@@ -126,7 +127,14 @@ def process_excel(file, places_column):
|
|
126 |
# Process each location in the comma-separated list
|
127 |
location_rows_added = False
|
128 |
for loc in locations:
|
129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
if point:
|
131 |
# Create a new row for this location
|
132 |
new_row = row.copy()
|
@@ -170,10 +178,24 @@ def process_excel(file, places_column):
|
|
170 |
# Add markers directly here
|
171 |
marker_cluster = MarkerCluster(name="Locations").add_to(m)
|
172 |
|
|
|
|
|
|
|
173 |
for idx, row in expanded_df.iterrows():
|
174 |
if 'latitude' in row and 'longitude' in row and not pd.isna(row['latitude']) and not pd.isna(row['longitude']):
|
175 |
location = row[places_column] if not pd.isna(row[places_column]) else "Unknown"
|
176 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
additional_info = ""
|
178 |
for col in expanded_df.columns:
|
179 |
if col not in [places_column, 'latitude', 'longitude'] and not pd.isna(row[col]):
|
|
|
106 |
geocoder = SafeGeocoder()
|
107 |
coords = []
|
108 |
processed_count = 0
|
109 |
+
location_cache = {} # Cache to ensure consistent coordinates
|
110 |
|
111 |
# Process each row
|
112 |
for idx, row in df.iterrows():
|
|
|
127 |
# Process each location in the comma-separated list
|
128 |
location_rows_added = False
|
129 |
for loc in locations:
|
130 |
+
# Use cached coordinates if available
|
131 |
+
if loc in location_cache:
|
132 |
+
point = location_cache[loc]
|
133 |
+
else:
|
134 |
+
point = geocoder.get_coords(loc)
|
135 |
+
if point:
|
136 |
+
location_cache[loc] = point # Cache the result
|
137 |
+
|
138 |
if point:
|
139 |
# Create a new row for this location
|
140 |
new_row = row.copy()
|
|
|
178 |
# Add markers directly here
|
179 |
marker_cluster = MarkerCluster(name="Locations").add_to(m)
|
180 |
|
181 |
+
# Track which coordinates we've already placed on the map
|
182 |
+
seen_coords = {}
|
183 |
+
|
184 |
for idx, row in expanded_df.iterrows():
|
185 |
if 'latitude' in row and 'longitude' in row and not pd.isna(row['latitude']) and not pd.isna(row['longitude']):
|
186 |
location = row[places_column] if not pd.isna(row[places_column]) else "Unknown"
|
187 |
|
188 |
+
# Round coordinates to reduce small differences
|
189 |
+
rounded_lat = round(row['latitude'], 5)
|
190 |
+
rounded_lng = round(row['longitude'], 5)
|
191 |
+
coord_key = f"{rounded_lat},{rounded_lng}"
|
192 |
+
|
193 |
+
# Skip if we've already added a marker at this location
|
194 |
+
if coord_key in seen_coords:
|
195 |
+
continue
|
196 |
+
|
197 |
+
seen_coords[coord_key] = True
|
198 |
+
|
199 |
additional_info = ""
|
200 |
for col in expanded_df.columns:
|
201 |
if col not in [places_column, 'latitude', 'longitude'] and not pd.isna(row[col]):
|