Spaces:
Runtime error
Runtime error
Update services/map_service.py
Browse files- services/map_service.py +21 -6
services/map_service.py
CHANGED
@@ -7,7 +7,7 @@ def generate_map(gps_coordinates: List[List[float]], map_items: List[Dict[str, A
|
|
7 |
Generate a map showing issue locations based on GPS coordinates.
|
8 |
Args:
|
9 |
gps_coordinates: List of [latitude, longitude] coordinates.
|
10 |
-
map_items: List of detected items (cracks, holes, missing patches) to plot.
|
11 |
Returns:
|
12 |
Path to the generated map image, or None if generation fails.
|
13 |
"""
|
@@ -16,21 +16,36 @@ def generate_map(gps_coordinates: List[List[float]], map_items: List[Dict[str, A
|
|
16 |
|
17 |
if gps_coordinates:
|
18 |
lats, longs = zip(*gps_coordinates)
|
19 |
-
ax.plot(longs, lats, 'b-', label='Path')
|
20 |
|
21 |
for item in map_items:
|
22 |
gps = item.get('gps', [0, 0])
|
23 |
lat, lon = gps
|
24 |
# Use a default severity if the key is missing
|
25 |
severity = item.get('severity', 'Moderate') # Default to 'Moderate'
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
ax.set_xlabel('Longitude')
|
31 |
ax.set_ylabel('Latitude')
|
32 |
ax.set_title('Issue Locations')
|
33 |
-
ax.
|
|
|
|
|
34 |
ax.grid(True)
|
35 |
|
36 |
map_path = "map_temp.png"
|
|
|
7 |
Generate a map showing issue locations based on GPS coordinates.
|
8 |
Args:
|
9 |
gps_coordinates: List of [latitude, longitude] coordinates.
|
10 |
+
map_items: List of detected items (cracks, holes, potholes, missing patches) to plot.
|
11 |
Returns:
|
12 |
Path to the generated map image, or None if generation fails.
|
13 |
"""
|
|
|
16 |
|
17 |
if gps_coordinates:
|
18 |
lats, longs = zip(*gps_coordinates)
|
19 |
+
ax.plot(longs, lats, 'b-', label='Path') # Blue line for path
|
20 |
|
21 |
for item in map_items:
|
22 |
gps = item.get('gps', [0, 0])
|
23 |
lat, lon = gps
|
24 |
# Use a default severity if the key is missing
|
25 |
severity = item.get('severity', 'Moderate') # Default to 'Moderate'
|
26 |
+
dtype = item.get('type', '')
|
27 |
+
|
28 |
+
# Custom colors for holes as per requirement
|
29 |
+
if dtype in ['hole', 'pothole']:
|
30 |
+
if severity == 'Mild':
|
31 |
+
color = 'darkgreen' # Green dot for minor holes
|
32 |
+
elif severity == 'Moderate':
|
33 |
+
color = 'yellow' # Yellow dot for moderate holes
|
34 |
+
else:
|
35 |
+
color = 'darkred' # Severe holes remain dark red
|
36 |
+
else:
|
37 |
+
# Existing logic for other types
|
38 |
+
color = 'darkred' if severity == 'Severe' else 'yellow' if severity == 'Moderate' else 'darkgreen'
|
39 |
+
|
40 |
+
marker = 'x' if dtype == 'crack' else 'o' if dtype in ['hole', 'pothole'] else '^'
|
41 |
+
ax.scatter(lon, lat, c=color, marker=marker, label=dtype.capitalize(), s=100)
|
42 |
|
43 |
ax.set_xlabel('Longitude')
|
44 |
ax.set_ylabel('Latitude')
|
45 |
ax.set_title('Issue Locations')
|
46 |
+
handles, labels = ax.get_legend_handles_labels()
|
47 |
+
by_label = dict(zip(labels, handles))
|
48 |
+
ax.legend(by_label.values(), by_label.keys())
|
49 |
ax.grid(True)
|
50 |
|
51 |
map_path = "map_temp.png"
|