Copilot/optimize analytics and ignore non weighted sets#144
Conversation
Agent-Logs-Url: https://github.com/gfauredev/LogOut/sessions/71104b9b-78e8-4caf-bac5-93182234d723 Co-authored-by: gfauredev <19304085+gfauredev@users.noreply.github.com>
Agent-Logs-Url: https://github.com/gfauredev/LogOut/sessions/71104b9b-78e8-4caf-bac5-93182234d723 Co-authored-by: gfauredev <19304085+gfauredev@users.noreply.github.com>
📝 WalkthroughWalkthroughVolume transitions from a dedicated exercise selector to a metric option within the 8 metric-exercise pair slots. Translation keys are updated across all locales, the Analytics component state is consolidated to 8 slots, and chart aggregation logic now handles Volume alongside other metrics using existing ChangesVolume Metric Integration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
📊 Coverage ReportLines: 3774/5029 (75.04474050507059%) ⏱️ Tests: 255 tests in 0.622s
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/components/analytics/mod.rs (1)
104-249: 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick winConsolidate the Volume branch into the shared mode-aggregation skeleton.
The new
Metric::Volumebranch (lines 111–170) re-implements the sameSet/SessionAverage/SessionTotaliteration skeleton as the non-Volume branch (lines 191–248), differing only in how the per-log value is computed and thatSessionTotalsums (vsWeight's max). This duplicates ~60 lines, forces anunreachable!()arm at lines 239–241, and introduces a minor inconsistency (if total > 0.0vsif !values.is_empty()).Volume can flow through the existing pipeline if
Metric::extract_valuereturns the per-log volume forMetric::Volume(only whenweight_hg.0 > 0 && reps.is_some()), andlog_matches/ theSessionTotalaggregator gain aVolumearm. Volume is intrinsically weighted, so it should bypass theuse_weighted_setspartition.♻️ Sketch of the unified flow
In
models::analytics, extendextract_value(rough shape):impl Metric { pub fn extract_value(self, log: &ExerciseLog) -> Option<f64> { match self { // ... existing arms ... Metric::Volume => { if log.weight_hg.0 > 0 { log.reps.map(|r| { f64::from(log.weight_hg.0) / HG_PER_KG * f64::from(r) }) } else { None } } } } }Then in
mod.rs, drop the entireif metric == Metric::Volume { ... } elsesplit and adjust the shared closures:- if metric == Metric::Volume { - match mode { - AnalyticsMode::Set => { /* ... */ } - AnalyticsMode::SessionAverage => { /* ... */ } - AnalyticsMode::SessionTotal => { /* ... */ } - } - } else { let use_weighted_sets = weighted_exercise_ids.contains(exercise_id.as_str()); let log_matches = |log: &crate::models::ExerciseLog| -> bool { if log.exercise_id != exercise_id { return false; } let is_weighted = log.weight_hg.0 > 0; match metric { - Metric::Weight => is_weighted, + Metric::Weight | Metric::Volume => is_weighted, Metric::Reps | Metric::Distance | Metric::Duration => { is_weighted == use_weighted_sets } - Metric::Volume => false, } }; // ... unchanged Set / SessionAverage arms ... AnalyticsMode::SessionTotal => { // ... let total = match metric { Metric::Weight => { values.iter().copied().fold(f64::NEG_INFINITY, f64::max) } - Metric::Reps | Metric::Distance | Metric::Duration => { + Metric::Reps + | Metric::Distance + | Metric::Duration + | Metric::Volume => { values.iter().sum() } - Metric::Volume => unreachable!( - "volume is handled by the dedicated branch above" - ), }; // ... } - }This drops ~60 lines, removes the
unreachable!(), and makes future metric additions a single-arm change.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/components/analytics/mod.rs` around lines 104 - 249, The Volume handling duplicates the mode-aggregation logic; implement Metric::extract_value to return per-log volume (using HG_PER_KG and log.reps when log.weight_hg.0 > 0) and then remove the special-case `if metric == Metric::Volume { ... } else { ... }` branch in mod.rs so all metrics flow through the shared Set/SessionAverage/SessionTotal skeleton; update the `log_matches` closure to treat Metric::Volume as intrinsically weighted (i.e., ignore use_weighted_sets and require weight_hg.0 > 0), and add a Metric::Volume arm in the SessionTotal match to sum values (instead of unreachable!), keeping the existing behavior for Metric::Weight (max) and others (sum).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/components/analytics/mod.rs`:
- Around line 104-249: The Volume handling duplicates the mode-aggregation
logic; implement Metric::extract_value to return per-log volume (using HG_PER_KG
and log.reps when log.weight_hg.0 > 0) and then remove the special-case `if
metric == Metric::Volume { ... } else { ... }` branch in mod.rs so all metrics
flow through the shared Set/SessionAverage/SessionTotal skeleton; update the
`log_matches` closure to treat Metric::Volume as intrinsically weighted (i.e.,
ignore use_weighted_sets and require weight_hg.0 > 0), and add a Metric::Volume
arm in the SessionTotal match to sum values (instead of unreachable!), keeping
the existing behavior for Metric::Weight (max) and others (sum).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 1a37f22d-a67c-439b-965b-f5afced09f4a
📒 Files selected for processing (5)
assets/en.ftlassets/es.ftlassets/fr.ftlsrc/components/analytics/mod.rssrc/components/analytics/selector.rs
This Pull Request…
Engineering Principles
scope is focused (no unrelated dependency updates or formatting)
README’s Engineering PrinciplesCI/CD Readiness
feat/…,fix/…,refactor/…, …dx fmt; cargo fmtnix flake checkssucceeds without warningsdx buildwith necessary platform flags succeedscargo clippy -- -D warnings -W clippy::all -W clippy::pedanticproduces zero warnings
cargo llvm-cov nextest --ignore-filename-regex '(src/components/|\.cargo/registry/|nix/store)'maestro test --headless maestro/webmaestro test --headless maestro/androidSummary by CodeRabbit
Release Notes
New Features
Updates
Localisation