Skip to content

Macro base values: per-100g contract for photo saveMeal and search quantity - #23

Merged
KrishP147 merged 2 commits into
mainfrom
krish/fix-macro-base-per-100g
Sep 24, 2026
Merged

KrishP147 merged 2 commits into
mainfrom
krish/fix-macro-base-per-100g

Conversation

@KrishP147

Copy link
Copy Markdown
Owner

Fixes #6

Data contract: meal_components.base_* is always per 100 g; portion_size is grams eaten.

  • A (photo): new toPer100g helper (frontend/src/utils/foodMacros.js); PhotoMealUpload.saveMeal now normalizes Gemini per-portion base_* before insert, same as saveAsCustomFood.
  • B (search): FoodSearchInput.handleSelect passes raw per-100g macros plus quantity; MealForm and PhotoMealUpload consumers set portion_size = quantity*100, portion_display = String(quantity), and compute shown totals. ReplaceFoodModal becomes correct by construction (comment added).
  • Tests: +13 (helper, FoodSearchInput, MealForm, MealForm.extended). 160/160 locally.

Existing corrupted rows are tracked in #19 (no migration here).

🤖 Generated with Claude Code

KrishP147 and others added 2 commits September 23, 2026 22:47
saveMeal wrote base_* from Gemini's per-detected-portion values
directly, violating the per-100g data contract. Extract toPer100g()
(same rounding as saveAsCustomFood) and reuse in both.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
FoodSearchInput.handleSelect multiplied per-100g macros by quantity
before handing them to callers, so every consumer's "base" values were
actually base*qty. Pass raw per-100g macros + quantity instead; move
the multiply into consumers (MealForm, PhotoMealUpload) so portion_size
= qty*100 and shown totals = base*qty per the data contract.
ReplaceFoodModal already ignored quantity, so it's correct as-is.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings September 24, 2026 03:03
@vercel

vercel Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
nutrisync-frontend Ready Ready Preview Sep 24, 2026 3:03am UTC

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@codecov

codecov Bot commented Sep 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@KrishP147
KrishP147 merged commit 44b4433 into main Sep 24, 2026
9 checks passed

This branch was successfully deployed

1 active deployment
Preview — 2fee4ca7 Deployed Sep 24, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Macro base values corrupted: photo saveMeal stores per-portion as per-100g; search quantity baked into base

2 participants