trails/openspec/changes/profile-weekly-distance/tasks.md
Ullrich Schäfer ceda9f1877
profile-weekly-distance: weekly distance bar chart on the profile
Implements the profile-weekly-distance change (specs/profile-weekly-distance):

- getWeeklyDistance(ownerId, { publicOnly, weeks=12 }) in activities.server.ts:
  one query that gap-fills in SQL — generate_series of week-starts LEFT JOINed
  to activities — so it returns exactly 12 contiguous { weekStart, distance }
  rows with matching Postgres week boundaries, viewer-scoped, no cache, no
  schema change.
- WeeklyDistanceChart: SVG bars normalized to the busiest week (empty weeks keep
  their slot as zero-height bars), per-bar title distance, localized label;
  renders nothing when there's no distance in the window. Mounted under the
  ProfileStats header.
- i18n journal.profileStats.weeklyDistance (en + de).

Tests: WeeklyDistanceChart component (jsdom: bar count incl. zero weeks, empty
→ hidden, normalization); e2e creates an activity with distance and asserts the
chart renders. typecheck + lint + unit (journal 321) green; verified in the
browser.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-13 07:46:06 +02:00

1.5 KiB

1. Aggregate query

  • 1.1 Added getWeeklyDistance(ownerId, { publicOnly, weeks = 12 }) to activities.server.ts: sum(distance) per week, viewer-scoped.
  • 1.2 Gap-fill done in SQL (generate_series of week-starts LEFT JOINed to the activities) — returns exactly N contiguous { weekStart, distance } rows, oldest→newest, and guarantees the week boundaries match Postgres date_trunc('week', …) (no JS/Postgres boundary drift). Filter conditions live in the JOIN's ON clause so empty weeks survive.

2. Loader & view

  • 2.1 Profile loader fetches it in parallel with the stats, same publicOnly: !isOwn scoping, only when content is visible.
  • 2.2 WeeklyDistanceChart: SVG bars normalized to the busiest week, per-bar title distance (via stats.ts), localized label; renders nothing when every week is 0. Mounted under ProfileStats.

3. i18n

  • 3.1 Added journal.profileStats.weeklyDistance (label) to en + de. Per-bar readout is the language-neutral km distance.

4. Tests & checks

  • 4.1 Gap-fill is in SQL (no JS helper to unit-test) → covered by the e2e (a real activity produces a non-zero bar over a full 12-week axis).
  • 4.2 Component (jsdom): one bar per week incl. zero weeks; nothing when all zero; heights normalized to the busiest week.
  • 4.3 E2E profile-weekly-distance.test.ts: create an activity with distance → the weekly chart renders on the profile. Passes locally.
  • 4.4 typecheck + lint + unit (journal 321) green; new e2e passes locally. Full pnpm test:e2e runs in CI.