Repository navigation
Conversation
- an opt-in setup file, units.conf, names the unit system for shopping list totals; with it a tool shows one amount per ingredient - amounts of the same kind (cup and ml, g and lb) are added through a unit table, in the base unit, rounded up, independent of recipe order - weight and volume are added only when a density is known for the ingredient; the total is marked as approximate and no density is ever assumed - the recipe view is not converted; pantry amounts are subtracted across units by the same rule - a recipe reference is matched to the referenced recipe's yield by kind: 1 l against a yield of 500 ml scales by 2, and a list of yields is matched by the entry of the same kind - no recipe syntax changes - addresses discussion #142
|
I agree with where this is going, and the measurement makes the case on its own: only 23% of shared ingredients share a unit and a spelling, so a list that cannot add across units fails on the common case, not an edge case. The split between reading and display is the important idea here, and I think it splits further. Six jobs, with different "owners":
You already single out density:
It is the only one of the six that needs data rather than definitions, so it looks like it should be its own proposal.
So conversion and aggregation already work on let c = Converter::bundled();
for order in [
[(1.0, "cup"), (200.0, "ml")],
[(200.0, "ml"), (1.0, "cup")],
] {
let mut g = GroupedQuantity::empty();
for (v, u) in order {
g.add(&Quantity::new(v.into(), Some(u.into())), &c);
}
let mut total = g.iter().next().unwrap().clone();
println!("merged: {total}");
total.convert(ConvertTo::Best(System::Metric), &c).unwrap();
println!("metric: {total}");
}Output: Either order lands on the 437 ml of your milk line, which is the requirement you set: the list is the same whichever recipe comes first. That changes one of the open questions:
The reason they would have to stop is that today the total takes the unit of whichever recipe came first, so two tools can show different lists from the same files. Taking the unit from the reader's preference instead, as above, removes that without removing the sum: the total is then the same in any order and in every tool, and the applications that add today can keep adding. Three suggestions:
For now I am only commenting on the open proposals. I will open one of my own for the locales likely in the coming week, rather than retell the design in each thread. One request while I am here: the open questions are numbered, which makes them easy to answer. Could the motivation and design points be numbered too? Right now replying to one means quoting it, as above. |
|
The open questions from the proposal, as a list that can be answered by number. Each one says what the proposal does now. Q1. Opt-in or on by default? Q2. Should the conventions hold a unit table? Q3. US customary and British imperial. Q4. What is a total shown in when weight meets volume? Q5. Where are densities kept? Q6. Is rule 4 for references worth having? Q7. What do applications that add units today do with no setup? Q8. Which steps for US customary totals? Four more came up in the first review comment above. They are not in the proposal text yet: Q9. Should weight against volume be its own proposal? Q10. Should the setup file be specified, or only the setting? Q11. Is one display setting enough? Q12. How are unit names in other languages read? On Q7, the same comment suggests an answer: keep adding, and take the unit from the reader's preference, so the total no longer depends on the order of the recipes. |
An opt-in setup that makes a shopping list show one amount per ingredient, and a rule for matching a recipe reference's unit to the referenced recipe's
yield. No recipe syntax changes.Rendered proposal
Summary
units.confwith[shopping] units = "metric"(or"us customary") asks for converged totals. Without it, list totals stay as they are today.1 cup, 200 mlbecomes437 ml. The result does not depend on the order of the recipes.≈and the amounts as written stay available. No density is ever assumed; without one the list keeps two amounts.yieldby kind:{1%l}againstyield: 500%mlscales by 2, and againstyield: [500%ml, 350%g]the entry of the same kind is used. This part needs no setup and converts nothing that is shown.Motivation
cook shopping-liston two recipes that measure milk in cups and in millilitres printsmilk 1 cup, 200 ml. It also prints1 cup, 2 cups, because amounts are added only when the unit text is identical. In random five-recipe lists from a collection of about 16,000 recipes, three shared ingredients in four come out as two or more amounts: 37% are the same unit spelled differently, 33% are different units of the same kind, 7% are weight against volume.Tools also disagree. CookCLI adds by unit text since cooklang/cookcli#433. cooklang-rs with its bundled unit table adds into the unit of whichever recipe comes first, so the total changes with recipe order.
The same text comparison decides whether a reference is scaled. A reference for
1%lof a recipe withyield: 500%mlis not scaled, and the list form ofyieldis not read at all by CookCLI 0.38.1.Addresses discussion #142. Related: cooklang/cookcli#673, cooklang/cookcli#199.
Things worth a reviewer's attention
us customary, notimperial. The setting takes the values of theunit systemkey from Proposal: add unit system metadata #148. The volumes in the table are US ones; British imperial units are an open question.lbs. A unit is looked up as written and then in lower case (Tbsp,Cup), exceptCandF.lbsis added.[density]inunits.confon top. It is not part of this PR. Ingredients whose cup weight depends on how they are cut are left out, and so is plain salt.The two parts can be accepted separately: reference matching does not depend on the setup file.
This PR contains the proposal only; conventions and test updates follow once it is accepted.