Skip to content

Document how diary entries count by measure type; warn against type switches - #12

Merged
ColinToft merged 2 commits into
mainfrom
colin/weight-measure-diary
Oct 13, 2026
Merged

ColinToft merged 2 commits into
mainfrom
colin/weight-measure-diary

Conversation

@ColinToft

Copy link
Copy Markdown
Owner

Why

Switching Colin's milk food's only measure (`g`) from `Atomic` to `Weight` dropped its diary entries to 1/100 of their grams. This PR records the server's actual rule so nobody repeats that, and makes the recipe-ingredient refusal warn against it.

The server's rule (verified live on ZZ foods, 2027-03-30, Oct 13 2026)

A diary entry is stored as a count of its measure. Its grams are:

  • `Weight` measure: count x measure value
  • `Atomic` measure: count x 100, whatever its value

Logging always sends grams, and the count is derived with the same rule, so fresh entries are always right. Measured with the server's day totals (400 kcal/100 g food):

food measure logged counted
g-only Atomic g 50 / 150 g 200 / 600 kcal
g-only Weight g 50 / 150 g 200 / 600 kcal
`create_custom_food` shape (Weight scoop 30 g + server g) scoop 30 / 90 g 120 / 360 kcal
same g 50 / 150 g 200 / 600 kcal
Atomic scoop 30 g scoop 30 / 90 g 120 / 360 kcal

Editing a measure re-reads existing entries:

  • Atomic -> Weight (value 1): 180 g -> 1.8 g; back to Atomic: 180 g again
  • Atomic scoop (30) -> Weight: 90 g -> 27 g
  • Weight scoop (30) -> Atomic: 90 g -> 300 g; Weight g -> Atomic: 50 g -> 5000 g
  • resizing a Weight measure 30 -> 60: 90 g -> 180 g; resizing an Atomic one: unchanged
  • replacing the measure list with a new Weight g: the server re-points the entries to it and they read 1.8 g

So PR #11's foods (Weight serving + server `g`) are diary-correct; no code fix is needed. The client never changes a measure's type.

Changes

  • Comment at `_WEIGHED_MEASURE` with the rule and the numbers.
  • `update_custom_food` docstring: only Weight resizes rescale; types are re-sent unchanged.
  • `_check_recipe_ingredient`'s refusal now says not to switch the type, and to make a new food instead. Test asserts it.
  • README: the same warning.

Tests

`uv run pytest -q`: 830 passed. ruff check/format clean.

🤖 Generated with Claude Code

ColinToft and others added 2 commits October 13, 2026 13:57
Verified live: a diary entry is stored as a count of its measure; its grams
are count x value for Weight measures and count x 100 for Atomic ones.
Foods made by create_custom_food (Weight serving + server g) log correctly by
either measure. Switching a logged measure's type rescales its entries by
value/100, so the recipe-ingredient refusal now warns against that fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ColinToft
ColinToft merged commit 979d446 into main Oct 13, 2026
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.

1 participant