Skip to content

feat(nutrition): Batch 4 — weekly wrap-up (adherence grade + takeaway) + alcohol parity verified#73

Open
drkostas wants to merge 1 commit into
feat/68-nutrition-adaptivefrom
feat/69-nutrition-alcohol-adherence
Open

feat(nutrition): Batch 4 — weekly wrap-up (adherence grade + takeaway) + alcohol parity verified#73
drkostas wants to merge 1 commit into
feat/68-nutrition-adaptivefrom
feat/69-nutrition-alcohol-adherence

Conversation

@drkostas

Copy link
Copy Markdown
Owner

Stacked on #72. Final batch of the "port macro-engine science into soma" series (#65).

Weekly wrap-up

Soma's web/api/nutrition has no existing weekly-adherence computation — this ports macro-engine's M10A aggregator as a pure-logic module so a future endpoint can drop it in.

  • compute_weekly_wrapup(days, weight_kg) returns WeeklyWrapup { week_start, week_end, days_total, days_closed, adherence_pct, avg_kcal, avg_protein_g[/kg], training_days, weight_delta_kg, grade }.
  • Grade table: A ≥ 90 / B ≥ 80 / C ≥ 70 / D ≥ 60 / F.
  • Adherence uses ±10% kcal target tolerance.
  • wrapup_takeaway(w) generates a short commentary string from adherence + protein g/kg + training days + weight delta.

Alcohol parity

Byte-diffed soma's nutrition_engine/alcohol.py against macro-engine's — identical except for the from nutrition_engine.seed_data import DRINK_DATABASE line (already the right path). No change needed.

Test plan

  • 18 new pytest assertions for weekly_wrapup — green.
  • 25 legacy alcohol tests remain green, unchanged.

Batch 1-4 total new tests: 157 + 32 + 61 + 18 = 268 new pytest assertions, all green.

Closes #69

… + takeaway) + alcohol parity verified

Weekly adherence never had a canonical implementation in soma. This
ports macro-engine's M10A aggregator as a new pure-logic module so a
future weekly-summary endpoint can drop it in without re-deriving the
±10% tolerance.

- sync/src/nutrition_engine/weekly_wrapup.py: DayRecord +
  WeeklyWrapup dataclasses + compute_weekly_wrapup aggregator. Grade
  A>=90 / B>=80 / C>=70 / D>=60 / F. Adherence uses ±10% kcal target
  tolerance. Auto-generated takeaway string keyed to adherence +
  protein g/kg + training days + weight delta. Handles missing weight
  readings (ignores Nones in the delta computation) and open/closed
  day split.
- adherence_grade(pct) + wrapup_takeaway(w) exposed for direct use.
- sync/src/nutrition_engine/alcohol.py: parity-verified against
  macro-engine's canonical version — byte-identical except for the
  import path for DRINK_DATABASE (already fixed at Batch 0 of the
  nutrition engine). No change needed.

Tests: 18 new pytest assertions for weekly_wrapup. Full Batch 1-4
module scope: 157 + 32 + 61 + 18 = 268 new tests, all green.

Closes #69
@vercel

vercel Bot commented Apr 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
soma-demo Ready Ready Preview, Comment Apr 24, 2026 1:55am
soma-personal Ready Ready Preview, Comment Apr 24, 2026 1:55am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant