Repository navigation
Retire defaultMeasureId reads in diary enrichment and recipe ingredients - #10
Merged
Merged
Conversation
defaultMeasureId is the measure a food was last logged with, not its serving, so nothing reads it any more. enrich_diary_servings no longer falls back to it when an entry's measure is gone. Rules, each verified live against the server's own day totals on a throwaway date with ZZ test foods (since retired): - Weight/Atomic foods: nutrients scale by grams / 100 whatever the measure, including measureId 0 and a deleted measure the server left the entry on. serving_size/servings are set only while the food still has the entry's own measure. - Serving-based recipes (every measure is type Recipe, even "g"): nutrients scale by grams / the measure's value, and grams counts the measure's units. The old code scaled by grams alone, which was right only for value-1 measures; deleting a recipe's measure moves its entries onto "g" (value = grams per reference serving), so it mattered. - A recipe entry whose measure is missing (e.g. logged with measureId 0) raises: the server divided it by a value other than the default measure's, so the old fallback was wrong, and no rule is known. - A food mixing Recipe and other measure types raises. The guard in _food_log_day that undid the fallback goes; _rank_sources tells a recipe entry by servings without a portion weight, so a weight measure without a value no longer nulls the grams sum. _gram_measure_id returns 0 for a food without a 1 g measure: the server accepts it and derives the same batch weight and nutrients as with a real measure (verified live). With #9's get_foods raising on unknown ids, enrich indexes foods directly, and the unknown-food tests use the fake server's real not-found error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…docs Review fixes: - enrich_diary_servings raises on a Serving entry whose grams isn't a finite number, naming the entry, so _food_servings' "Try again" re-check (which could no longer be a lookup failure) goes. - enrich marks each entry recipe True/False; _food_log_day and _rank_sources read it instead of inferring it from serving_size. - get_food_log, get_nutrient_sources and create_recipe docstrings now say a serving-based recipe's grams counts the logged measure's units. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
defaultMeasureIdis the last-logged measure, not the serving (#8). This removes its last two readers.Live evidence (throwaway date, ZZ foods since retired; server totals checked per entry):
Recipe): the server counts stored × grams / measure value. Ong(value 200), grams 1.5 counted 0.536 (old code: 107.25). Onfull recipe(value 4), grams 4 counted 71.5 (old: 286). Deleting a measure moves its entries ontog._gram_measure_idnow returns 0.Also: enrich indexes foods directly (#9), raises on non-numeric grams or mixed measure types, and flags recipe entries.
Inferred, not observed: a Recipe measure's
gramscounts its units.796 tests pass; ruff is clean.
🤖 Generated with Claude Code