-
Notifications
You must be signed in to change notification settings - Fork 0
✨ Foundations: Trends API, DST-safe durations, SSR Trends page #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…atterns to axum 0.8 syntax
…que index for daily intensity sentinel row
…ion range; persist duration_min in sleep_metrics; update handlers/repository signatures
…e routes and library module
…e into app router
…y util; clippy clean
…allbacks for min/max); address PR #3 feedback; no API change
- summary: guard empty buckets and simplify median calc (no redundant is_empty branch) - app: log Askama template rendering errors with context - ui: preserve nulls for missing durations in Chart.js mapping Tests: cargo test passes
- app: log Askama errors but return generic user-facing message - time: extract MAX_DST_GAP_MINUTES constant (replaces magic number 3*60) - trends: compute median via select_nth_unstable (O(n) avg), keep empty-bucket guard Tests: cargo test passes
- trends: fix median correctness by sorting once and indexing (even/odd) - ui: remove unused HTMX include from Trends page Tests: cargo test passes
…on via helpers; time: add tracing warn on DST fallback; tests pass
…k; trends: compute median latency in O(n) using select_nth_unstable instead of full sort
…an; avoid clone to preserve O(n) perf
…nvariant of non-empty lower partition
… and clarify expect() message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements foundational backend and UI components for Sprint 3, introducing DST-safe duration calculations, Trends API endpoints, and a server-side rendered Trends page with Chart.js visualizations.
- Adds DST-safe duration computation using chrono-tz with wake-date semantics
- Implements Trends API endpoints for sleep data visualization and aggregated metrics
- Creates SSR Trends page with Chart.js charts for sleep analysis
Reviewed Changes
Copilot reviewed 17 out of 18 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| sleep-api/src/time.rs | DST-safe duration computation with timezone handling |
| sleep-api/src/trends.rs | Trends API endpoints for sleep bars and summary data |
| sleep-api/templates/trends.html | SSR template with Chart.js charts and date controls |
| sleep-api/src/views.rs | Askama template struct for trends page |
| migrations/0002_add_duration_min.sql | Database migration adding duration_min column |
| migrations/0003_views.sql | SQL view for daily sleep data |
| sleep-api/tests/trends_bars.rs | Integration test for sleep-bars endpoint |
| sleep-api/src/handlers.rs | Updated to compute and persist duration |
| sleep-api/src/repository.rs | Modified to accept and store duration_min |
| sleep-api/src/app.rs | Added trends routes and template rendering |
| sleep-api/Cargo.toml | Updated dependencies for new functionality |
Summary
This PR delivers the foundational backend and UI pieces for Sprint 3. It introduces DST-safe duration semantics, a SQL view for daily sleep with pre-computed duration, on-demand Trends JSON endpoints, and a minimal SSR Trends page wired with Chart.js.
Key changes
Duration semantics (DST-safe, wake-date)
DB migrations & view
Trends endpoints (on-demand JSON)
SSR Trends page
OpenAPI
Dependency updates & routing
Tests & quality
How to run locally
cargo build,cargo testset DATABASE_URL=sqlite://./sleep.db && cargo runNotes & next steps
This sets the groundwork for the Sprint 3 UI flows and trends exploration while keeping time semantics correct across DST.