Commit Graph

392 Commits

Author SHA1 Message Date
Davide Scaini 69571c1306 fix: pass wheel filename through extraction chain to fix micropip install
micropip requires the full PEP 427 wheel filename (name-version-py-abi-plat.whl)
— writing the file as bincio.whl caused InvalidWheelFilename. The wheel URL from
/api/wheel/version now provides the basename; it flows through fetchWheelBase64 →
extractFile → WebView where the file is written with the correct name and
_wheel_path is set as a Pyodide global before PY_INSTALL_WHEEL runs.
2026-04-25 09:29:33 +02:00
Davide Scaini ef45d4f4bb fix: move PyodideWebView into Import tab; fix micropip blob URL error
Layout fix: WebView as a sibling in the root layout breaks flex geometry even
with position:absolute. Moving it inside the Import tab screen (which Expo Router
keeps mounted after first visit) eliminates the issue entirely and restores the
original simple root layout.

micropip fix: blob: URLs are not a recognised scheme in micropip — they are parsed
as package requirement strings, producing InvalidRequirement. Write the wheel bytes
to Pyodide's Emscripten FS (/tmp/bincio.whl) and install via emfs:/// instead.
2026-04-24 23:26:39 +02:00
Davide Scaini fc814f5026 fix: replace Buffer.from().toString('base64') with btoa helper — Buffer not available in Expo RN 2026-04-24 23:16:50 +02:00
Davide Scaini 21b421fdc3 fix: wrap root layout in flex:1 View so Stack fills full screen alongside hidden WebView 2026-04-24 23:15:52 +02:00
Davide Scaini 84e5cead08 fix: pre-fetch bincio wheel via RN networking to avoid ATS blocking HTTP in WKWebView
WKWebView blocks HTTP requests (ATS) even when NSAllowsLocalNetworking is set for
the app's own networking — so fetch(http://192.168.x.x/api/wheel/download) inside
the WebView always fails with 'Load failed' on iOS.

- extractActivity.ts: rename wheelUrl param to wheelBase64; WebView now receives
  the wheel as pre-fetched base64 bytes rather than a URL to fetch itself
- PyodideWebView.tsx: decode wheelBase64 → Uint8Array → Blob → blob URL for
  micropip.install; fix baseUrl '' → 'https://localhost' (null origin blocks fetch
  on iOS)
- import.tsx: add fetchWheelBase64() that resolves the wheel URL via
  /api/wheel/version then fetches with native networking (HTTP works); caches
  result in memory so repeated imports in one session don't re-download
2026-04-24 23:13:24 +02:00
Davide Scaini 966528a0bf feat: Phase 1 — FIT/GPX/TCX extraction via Pyodide in hidden WebView
- extraction/PyodideWebView.tsx: hidden WebView (1×1 px, off-screen) that
  bootstraps Pyodide v0.26.4 from jsDelivr CDN on app startup; loads lxml,
  pyyaml, micropip, fitdecode, gpxpy automatically; installs the bincio wheel
  lazily on the first extraction call via a blob URL (avoids startup delay)
- extraction/extractActivity.ts: typed bridge — extractFile(filename, base64,
  wheelUrl, onStatus) injects JS into the WebView, tracks pending promises by
  request ID, resolves with { id, detail, timeseries, geojson, sourceHash }
- app/_layout.tsx: mounts <PyodideWebView> outside SQLiteProvider at root so
  the runtime warms up as soon as the app opens
- app/(tabs)/import.tsx: replaces the placeholder alert with real extraction;
  reads files as base64, calls extractFile with a progress callback, stores
  detail_json + timeseries_json + geojson + real SHA-256 source_hash; resolves
  wheel URL via GET /api/wheel/version with fallback to /api/wheel/download;
  falls back to bincio.org if no instance is configured
2026-04-24 22:54:59 +02:00
Davide Scaini ed738ffc97 docs: document current mobile app state — gaps, stubs, and missing plan items
- Mark Phase 1 as the critical unbuilt feature; note its prerequisite chain
  (SHA-256 dedup, re-extract button, Phase 2 auto-import all depend on it)
- Flag Phase 2 auto_import_path as stubbed in UI but unimplemented in background
- Add "Known gaps and technical debt" section covering:
  - source_hash stub (id+length, not SHA-256)
  - FIT/GPX/TCX import placeholder alert
  - auto_import_path field with no backend task
  - feed pagination (getAllSync with no LIMIT)
  - individual activity deletion (missing from plan)
  - feed search and filter (missing from plan)
  - token expiry / inline reconnect flow (missing from plan)
  - app icon and splash screen (Expo defaults)
  - upload skip behaviour for origin=remote rows
- Add Phase 5 items not previously in the plan: app icon, feed search/filter,
  individual deletion, token reconnect prompt
2026-04-24 22:42:20 +02:00
Davide Scaini c7c7fe9395 feat: bidirectional sync — upload local activities to remote instance
- Server: POST /api/upload/bas accepts pre-extracted BAS JSON (activity + optional timeseries/geojson), writes files and triggers merge_all
- sync.ts: uploadLocalActivities reads unsynced local activities by original_path, POSTs to /api/upload/bas, marks synced_at on success
- Settings: Upload toggle (Off / Upload local activities) in Sync section with subLabel dividers for Download / Upload groups
- Feed: sync message includes uploaded count when activities are pushed
2026-04-24 22:26:13 +02:00
Davide Scaini a1e56e5308 feat: tabbed metric charts — elevation, speed, HR, cadence, power 2026-04-24 22:03:51 +02:00
Davide Scaini 3ce365e439 feat: tap map thumbnail to open full-screen interactive map 2026-04-24 21:55:56 +02:00
Davide Scaini a306682b52 feat: add sync mode setting — summaries only vs full data download 2026-04-24 21:52:25 +02:00
Davide Scaini bb44b80e97 fix: upgrade react-native-svg to 15.15.4 to fix Fabric crash on RN 0.81 2026-04-24 18:20:36 +02:00
Davide Scaini c1e4ab5af7 feat: add reset synced data button to settings 2026-04-24 15:45:51 +02:00
Davide Scaini f054869b04 feat: add --api-host to bincio dev and --mobile to dev_test.py for local mobile testing 2026-04-24 15:43:30 +02:00
Davide Scaini 97c7fae9be feat: Phase 4 — MapLibre route map + SVG elevation chart on activity screen
- Add /api/activity/{id}/geojson and /api/activity/{id}/timeseries endpoints
  (bearer-token-gated, falls back from _merged to raw activities dir)
- Rewrite activity detail screen with MapLibreGL v11 API (Map, Camera,
  GeoJSONSource, Layer) and react-native-svg area chart with gradient fill
- On-demand fetch for remote activities that have no local geojson/timeseries
- Add react-native-svg dependency; requires dev build (npx expo run:android)
2026-04-24 15:40:10 +02:00
Davide Scaini 02726034c7 fix: read activity shards in GET /api/feed; improve sync feedback
_merged/index.json is a shard manifest with activities:[] when the user
has >FEED_PAGE_SIZE activities. The endpoint now collects from all
index-{year}.json shard files before returning.

SyncResult gains a `total` field (activities received from server) so the
feed screen can distinguish "server returned nothing" from "all already
stored locally". Messages: "No activities on instance" / "Up to date (N)"
/ "X of N activities synced".
2026-04-24 15:07:52 +02:00
Davide Scaini 44b2878b14 feat: Phase 0.5 — remote feed sync via Bearer token auth
Server (bincio/serve/server.py):
- Add _require_auth: accepts session cookie OR Authorization: Bearer token
- POST /api/auth/token: same as /api/auth/login but returns token in body
  (password used once, not stored; mobile stores only the session token)
- GET /api/feed: auth-gated; reads _merged/index.json for the user and
  returns the activities array as JSON

Mobile:
- db/sync.ts: syncFeed(db) fetches /api/feed, upserts each summary into
  local SQLite as origin='remote'; skips locally-imported activities
- db/queries.ts: add upsertRemoteActivity (INSERT ... ON CONFLICT DO UPDATE
  WHERE origin='remote' — never overwrites local imports); fix feed sort
  order to started_at DESC instead of insertion order
- settings.tsx: Connect section — password field (not persisted) + Connect
  button calls POST /api/auth/token and stores token; Disconnect clears it
- index.tsx: ↓ Sync button + pull-to-refresh both trigger syncFeed; cloud
  badge on remote activities; empty state updated
2026-04-24 12:07:49 +02:00
Davide Scaini 79c572bf8b fix: align expo packages to SDK 54 expected versions
Expo's version checker reported mismatches; update to exact expected versions:
  expo-sqlite ~16.0.10, expo-document-picker ~14.0.8,
  expo-file-system ~19.0.21, expo-background-fetch ~14.0.9,
  expo-task-manager ~14.0.9, react-native-webview 13.15.0,
  typescript ~5.9.2

expo-file-system v19 moved the legacy API (documentDirectory, copyAsync,
makeDirectoryAsync) to 'expo-file-system/legacy' — update import in import.tsx.
2026-04-24 11:45:23 +02:00
Davide Scaini 10b515f3bf fix: pin react-dom to 19.1.0 to prevent npm resolving 19.2.5
expo-router@6.0.23 declares react-dom as peerOptional; without an explicit
pin npm resolves react-dom@19.2.5 (latest) which conflicts with react@19.1.0.
The SDK 54 template pins both to 19.1.0 — mirroring that here.
2026-04-24 11:39:02 +02:00
Davide Scaini 6f5abf634d fix: downgrade to Expo SDK 54 for Expo Go compatibility
Expo Go 54 (latest available on device) cannot run SDK 55 projects.
Rewrite package.json with canonical SDK 54 versions from expo-template-tabs:
  expo ~54.0.33, expo-router ~6.0.23, react 19.1.0, react-native 0.81.5
  expo-sqlite ~15.0.6, expo-document-picker ~13.1.6,
  expo-file-system ~18.0.12, expo-background-fetch/task-manager ~13.1.6,
  expo-notifications ~0.32.16, expo-constants ~18.0.13,
  expo-linking ~8.0.11, expo-splash-screen ~31.0.13,
  expo-status-bar ~3.0.9, react-native-screens ~4.16.0,
  react-native-safe-area-context ~5.6.0
TypeScript compiles cleanly; npm install completes without errors.
2026-04-24 11:32:56 +02:00
Davide Scaini 6e0b619ad3 fix: pin react to 19.2.5 and @types/react to ~19.2.0
react-dom@19.2.5 (pulled by @expo/router-server) requires react@^19.2.5;
@react-native/virtualized-lists@0.85.2 requires @types/react@^19.2.0.
npm install now completes without errors or warnings.
2026-04-24 11:24:16 +02:00
Davide Scaini 18726699f1 fix: update react to 19.2.3 to satisfy react-native 0.85.2 peer dep
react-native@0.85.2 requires react@^19.2.3; package.json had 19.0.0.
Also update @types/react to ~19.1.0 to match.
2026-04-24 11:16:14 +02:00
Davide Scaini 02bb8a3dd7 feat: serve bincio wheel locally for mobile dev testing
- Add GET /api/wheel/download to serve/server.py and edit/server.py:
  serves dist/bincio-*.whl via FileResponse; in production nginx takes
  the request before FastAPI, so this is a no-op there but works locally
- wheel_version response now includes api_url: "/api/wheel/download"
  alongside the nginx-served url field
- Bundle mobile/assets/bincio.whl (built from dist/) as an offline
  fallback for Pyodide testing before the first instance sync
- docs/mobile-app.md: document dev setup — bundled asset, local server
  endpoint, and how to refresh the bundle with uv build + cp
2026-04-24 11:01:24 +02:00
Davide Scaini b37df88fe1 feat: Phase 0 mobile app scaffold — Expo 55, SQLite, Feed/Import/Settings screens 2026-04-24 10:39:06 +02:00
Davide Scaini 565f5a3ff1 docs: complete mobile app plan — phased roadmap, Android/iOS divergences, data model 2026-04-24 10:26:58 +02:00
Davide Scaini 61479fe554 docs: mobile app — Pyodide/hidden-WebView extraction model, algorithm-travels-to-data pattern 2026-04-24 10:18:49 +02:00
Davide Scaini e952d9bdc1 docs: expand mobile app design — hybrid extraction, Karoo integration, platform independence vision 2026-04-24 10:12:36 +02:00
Davide Scaini 81ed5e1b0b docs: add mobile app design document (local-first, Expo/React Native) 2026-04-24 10:04:13 +02:00
Davide Scaini 7329c8f5e8 Merge branch 'main' into mobile_app 2026-04-24 09:52:27 +02:00
Davide Scaini 0f1876a33c chore: untrack CLAUDE.md, publish.sh, docs/squash-for-github.md; gitignore dns/nginx scratch files 2026-04-22 17:22:31 +02:00
Davide Scaini 7c171c9e9d docs: replace VPS IP with placeholder in elevation.md 2026-04-22 17:14:10 +02:00
Davide Scaini a69a2f240a docs: mark changelog 0.1.0 public release (2026-04-22) 2026-04-22 17:09:44 +02:00
Davide Scaini 6dc1fb6f20 fix: prune dist/data before rsync in _trigger_rebuild and manual rebuild endpoint
Same fix as cea1dbc (post-receive hook) but missed in server.py: Astro resolves
the public/data symlink and copies all activity JSON into dist/; without pruning,
every Strava sync / upload / edit that triggers a full build + rsync duplicates
GBs of data into the nginx webroot.

Both rsync callsites now rm -rf dist/data + pass --exclude=data/ to rsync.
2026-04-22 11:01:01 +02:00
Davide Scaini df496a017f fix: refine hysteresis recalculation with MA pre-smoothing and lower thresholds
- dem.py: pre-smooth elevation with 30s moving average before hysteresis
  in recalculate_elevation_hysteresis(); thresholds drop from 5m/10m to
  1m (barometric) / 3m (GPS) — accurate after noise is smoothed out
- dem.py: widen DEM median-filter window 45s → 60s
- dem.py: rename response key source → altitude_source for consistency
- writer.py: write altitude_source into detail JSON at extract time
- tests/test_dem.py: 21 unit tests for pure functions and file-level hysteresis
- tests/test_edit_server.py: 11 TestClient API tests for both recalculate endpoints
- add httpx as dev dependency (required by FastAPI TestClient)
2026-04-22 10:57:28 +02:00
Davide Scaini 88b24a6274 docs: update elevation docs and changelog for two-button recalculation and DEM fix 2026-04-20 21:43:28 +02:00
Davide Scaini ebac3f50f4 fix: DEM elevation overcounting and add hysteresis-only recalculation button
- dem.py: apply 45s median filter before hysteresis to suppress SRTM
  tile-boundary steps that were accumulating through the 5m threshold;
  raise DEM hysteresis threshold from 5m to 10m
- dem.py: back up elevation_m as elevation_m_original in timeseries
  before the first DEM overwrite, so original sensor data is preserved
- dem.py: add recalculate_elevation_hysteresis() — recomputes gain/loss
  from original recorded elevation (reads elevation_m_original if a DEM
  run already replaced elevation_m) using source-aware thresholds
  (5m barometric, 10m GPS/unknown); does not touch the elevation array
- edit/server.py, serve/server.py: split /recalculate-elevation into
  two endpoints: /recalculate-elevation/dem and
  /recalculate-elevation/hysteresis
- EditDrawer.svelte: replace single DEM button with two side-by-side
  buttons — "Recalculate (hysteresis)" (fast, offline) and
  "Recalculate (DEM)" (SRTM lookup)
2026-04-20 21:41:23 +02:00
Davide Scaini 2b7a37ed41 docs: update changelog, CLI reference, user guide, and elevation notes
- CHANGELOG: document hysteresis elevation fix and DEM recalculation feature
- docs/reference/cli.md: add --dem-url to bincio edit and bincio serve tables
- docs/user-guide.md: document "Recalculate from terrain map" button in edit drawer
- docs/elevation.md: mark both short-term and medium-term fixes as implemented
2026-04-20 21:18:50 +02:00
Davide Scaini 0c659db6cb fix: default DEM URL to api.open-elevation.com
No configuration needed out of the box; --dem-url only required to
override the default with a self-hosted or alternative endpoint.
2026-04-20 21:17:03 +02:00
Davide Scaini 1940e2409b feat: DEM-based elevation recalculation via edit drawer button
Adds a "Recalculate from terrain map (DEM)" button to the activity edit
drawer. On click it queries an Open-Elevation-compatible API to replace
GPS altitude with SRTM terrain data, applies 5m hysteresis, and updates
the activity's elevation stats and timeseries chart in place.

- bincio/extract/dem.py: lookup_elevations() (batched HTTP POST) +
  recalculate_elevation() (subsample → DEM → interpolate → hysteresis →
  patch activity JSON, timeseries JSON, index.json)
- POST /api/activity/{id}/recalculate-elevation on both serve and edit
  servers; serve endpoint is auth-gated and triggers merge + rebuild
- --dem-url flag (also DEM_URL env var) on bincio serve and bincio edit;
  logged at startup; missing URL returns a clear 503 with setup instructions
- /api/me response gains dem_configured bool
- EditDrawer: button with loading state, shows new ↑/↓ values on success
2026-04-20 20:45:06 +02:00
Davide Scaini 872651f471 metrics: replace naive elevation accumulation with hysteresis dead-band
GPS jitter and barometric quantization noise caused systematic overestimation
of elevation gain — in extreme cases 100% of reported gain was sub-1m noise.

Implements source-aware hysteresis: elevation is only committed when it
deviates from the last committed value by ≥5m (barometric) or ≥10m (GPS/GPX/TCX).

- ParsedActivity gains `altitude_source` field ("barometric"/"gps"/"unknown")
- FIT parser sets "barometric" when enhanced_altitude is present, else "gps"
- GPX and TCX parsers always set "gps"
- metrics._elevation() uses the threshold matching the source
- 5 new parametric tests covering flat GPS noise, threshold differences, and real climbs
2026-04-20 20:29:20 +02:00
Davide Scaini 696f538f56 ci: add fastapi/bcrypt to dev dependency group so all tests pass
test_db.py and test_server_imports.py import bincio.serve.server and
bincio.serve.db which require fastapi and bcrypt. These were only in the
optional 'serve' extra so the default dev env was missing them, causing
4 test failures and 1 collection error in CI.
2026-04-20 20:23:06 +02:00
Davide Scaini 6491e4fd8c fix: show total activity count in global feed counter
The counter now shows "50 of 16398 activities" using the total from
feed.json, matching the previous behaviour where all activities were
loaded upfront.
2026-04-20 17:12:50 +02:00
Davide Scaini 104328bc50 fix: stable y-axis range and sane dist_km in activity charts
Three bugs in the time↔distance x-axis toggle:

1. GPS speed glitches (e.g. a 1-second spike at 222 km/h) were accumulated
   into dist_km, pushing all subsequent points ~60 m too far right on the
   distance axis and compressing the rest of the chart.  Cap speed at 150 km/h
   during dist_km integration; values above that are treated as 0 movement.

2. Observable Plot auto-infers the y domain from plottable points only.
   When x-mode changes, which points are "plottable" changes too, so the
   y axis range silently shifted between time and distance views.  Fix by
   computing lineDomainMin/Max once from the full dataset and passing an
   explicit domain to Plot.

3. monotone-x curve requires strictly increasing x.  In distance mode,
   stopped segments produce consecutive points with identical dist_km,
   causing NaN Bézier control points and visual artifacts.  Use linear
   curve for distance mode (data is dense enough that it looks smooth).
2026-04-20 17:06:56 +02:00
Davide Scaini 631e814d64 fix: load all year shards into combined feed, not just top 2 2026-04-20 16:14:40 +02:00
Davide Scaini db7047f210 perf: combined feed index for multi-user global feed
Instead of the browser resolving 20+ user shards recursively (~27 MB),
generate a pre-sorted feed.json at merge time with 50 activities per
page. The global feed loads one ~30 KB file on first paint; "Load more"
fetches subsequent pages (feed-2.json, feed-3.json, etc.).

Per-user profile pages still use year-sharded loadIndexPaged as before.
2026-04-20 15:31:35 +02:00
Davide Scaini e8a5fbbaba docs: add nginx gzip configuration for JSON compression
Activity index shards compress ~90% with gzip (130 KB → 14 KB).
The default nginx.conf has gzip on but gzip_types commented out,
so JSON was served uncompressed.
2026-04-20 15:24:16 +02:00
Davide Scaini d069716068 fix: clamp stats tooltip within viewport on mobile 2026-04-20 15:07:52 +02:00
Davide Scaini cea1dbc2fb ops: fix data/ triple-duplication costing ~24 GB on VPS
astro build resolves the public/data symlink and copies all activity JSON
into dist/; rsync then copied that to the webroot — but nginx already serves
/data/ directly from /var/bincio/data/ via alias, so both copies were dead
weight. Freed 36 GB → 14 GB on the live server.

- post-receive hook: prune dist/data/ before rsync, add --exclude=data/
- docs: update manual rebuild command and nginx comment to match
- serve/server.py: _mb() now uses lstat() to count symlinks at face value
  rather than following them to targets, so admin storage panel no longer
  double-counts _merged/ (which is mostly symlinks into activities/)
2026-04-19 23:34:55 +02:00
Davide Scaini 5227b30456 fix: EditDrawer correctly reads and labels unlisted privacy
- serve/server.py GET adds private:bool to the response (true when
  privacy is "unlisted" or legacy "private") so EditDrawer can read it
- edit/server.py GET: same fix for the single-user edit server
- EditDrawer: fall back to d.privacy if d.private is absent; rename
  "Private" toggle label to "Unlisted"
2026-04-19 22:58:09 +02:00
Davide Scaini 8a3e7831d3 fix: prevent double URL-rewrite in nested shard resolution
rewriteActivityUrls now skips URLs that are already absolute (start with
/ or http). Before this fix, the new user→year two-level nesting caused
year-shard URLs (/data/brut/_merged/activities/X.json) to be prepended
again at the user-shard level, producing broken doubled paths and making
every activity show "Activity not found".
2026-04-19 22:46:36 +02:00