Activity detail: layout refactor + GPS-derived speed for map coloring
Layout: map + charts stacked left, stats panel (2-col) on the right. Cadence moved to last stat. Charts sit directly below the map. Speed coloring: most FIT files don't record per-second speed, leaving timeseries speed_kmh all-null and the hover link dead. Fix: derive speed from consecutive GPS coordinates (haversine + 5-pt moving average) when the device didn't record it. Add --backfill-speed render flag to retrofit existing timeseries files.
This commit is contained in:
@@ -418,6 +418,40 @@ def _backfill_vam_summary(data: Path, handle: str | None = None) -> None:
|
||||
console.print(f" [cyan]{user_dir.name}[/cyan]: {updated} summary(ies) updated")
|
||||
|
||||
|
||||
def _backfill_speed(data: Path, handle: str | None = None) -> None:
|
||||
"""Compute GPS-derived speed for timeseries files where speed_kmh is all null.
|
||||
|
||||
Reads each *.timeseries.json, fills speed_kmh from haversine distances when
|
||||
the device did not record per-second speed, and writes the file back.
|
||||
"""
|
||||
import json
|
||||
from bincio.extract.timeseries import _gps_speed_kmh
|
||||
|
||||
targets = [data / handle] if handle else _user_dirs(data)
|
||||
for user_dir in targets:
|
||||
acts_dir = user_dir / "activities"
|
||||
if not acts_dir.exists():
|
||||
continue
|
||||
updated = 0
|
||||
for ts_path in sorted(acts_dir.glob("*.timeseries.json")):
|
||||
try:
|
||||
ts = json.loads(ts_path.read_text(encoding="utf-8"))
|
||||
except Exception:
|
||||
continue
|
||||
spd = ts.get("speed_kmh", [])
|
||||
if not spd or any(v is not None for v in spd):
|
||||
continue # already has speed data
|
||||
lat_vals = ts.get("lat") or []
|
||||
lon_vals = ts.get("lon") or []
|
||||
t_vals = ts.get("t") or []
|
||||
if not lat_vals or not lon_vals or not t_vals:
|
||||
continue
|
||||
ts["speed_kmh"] = _gps_speed_kmh(lat_vals, lon_vals, t_vals)
|
||||
ts_path.write_text(json.dumps(ts, indent=2, ensure_ascii=False), encoding="utf-8")
|
||||
updated += 1
|
||||
console.print(f" [cyan]{user_dir.name}[/cyan]: {updated} timeseries updated with GPS speed")
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.option("--config", "config_path", default=None,
|
||||
help="Path to extract_config.yaml (reads output.dir from it).")
|
||||
@@ -444,6 +478,9 @@ def _backfill_vam_summary(data: Path, handle: str | None = None) -> None:
|
||||
@click.option("--backfill-vam-summary", "backfill_vam_summary", is_flag=True,
|
||||
help="Copy climbing_vam_mh from detail JSONs into index.json summaries "
|
||||
"(run once after the VAM curve → summary migration).")
|
||||
@click.option("--backfill-speed", "backfill_speed", is_flag=True,
|
||||
help="Compute GPS-derived speed for timeseries where the device didn't record "
|
||||
"per-second speed (run once to enable speed map coloring on older activities).")
|
||||
def render(
|
||||
config_path: Optional[str],
|
||||
data_dir: Optional[str],
|
||||
@@ -456,6 +493,7 @@ def render(
|
||||
recompute_climbs: bool,
|
||||
recompute_elevation: bool,
|
||||
backfill_vam_summary: bool,
|
||||
backfill_speed: bool,
|
||||
) -> None:
|
||||
"""Build (or serve) the BincioActivity static site from a BAS data store."""
|
||||
|
||||
@@ -477,6 +515,10 @@ def render(
|
||||
console.print("Backfilling climbing_vam_mh into summaries…")
|
||||
_backfill_vam_summary(data, handle=handle)
|
||||
|
||||
if backfill_speed:
|
||||
console.print("Backfilling GPS-derived speed into timeseries…")
|
||||
_backfill_speed(data, handle=handle)
|
||||
|
||||
_merge_edits(data, handle=handle)
|
||||
_rebuild_athlete_json(data, handle=handle)
|
||||
_bake_tracks(data, handle=handle)
|
||||
|
||||
Reference in New Issue
Block a user