map now working

This commit is contained in:
Davide Scaini
2026-03-28 19:34:22 +01:00
parent 5d58126d2f
commit 3441079913
18 changed files with 1489 additions and 10 deletions
+27
View File
@@ -25,6 +25,33 @@ def simplify_track(
return [p for (p, _, _), keep in zip(gps_pts, mask) if keep]
def preview_coords(
points: list[DataPoint],
max_points: int = 20,
) -> list[list[float]] | None:
"""Return a small list of [lat, lon] pairs for card thumbnail rendering.
Uses a coarser RDP pass, then subsamples to at most max_points.
Returns None if there is no GPS data.
"""
gps = [(p.lat, p.lon) for p in points if p.lat is not None and p.lon is not None]
if len(gps) < 2:
return None
# Coarse RDP (larger epsilon = fewer points)
coords = [[lon, lat] for lat, lon in gps]
mask = rdp(coords, epsilon=0.001, return_mask=True)
reduced = [gps[i] for i, keep in enumerate(mask) if keep]
# Subsample if still too many
if len(reduced) > max_points:
step = len(reduced) / max_points
reduced = [reduced[int(i * step)] for i in range(max_points)]
reduced.append(gps[-1]) # always include the last point
return [[round(lat, 5), round(lon, 5)] for lat, lon in reduced]
def build_geojson(
points: list[DataPoint],
activity_id: str,
+3 -1
View File
@@ -7,7 +7,7 @@ from pathlib import Path
from bincio.extract.metrics import ComputedMetrics
from bincio.extract.models import LapData, ParsedActivity
from bincio.extract.simplify import build_geojson
from bincio.extract.simplify import build_geojson, preview_coords
from bincio.extract.timeseries import build_timeseries
@@ -119,6 +119,8 @@ def build_summary(
"privacy": privacy,
"detail_url": f"activities/{activity_id}.json",
"track_url": f"activities/{activity_id}.geojson" if has_gps else None,
# Small track preview for card thumbnails — no separate fetch needed
"preview_coords": preview_coords(activity.points) if has_gps else None,
}