Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle fractions nicely during recalculations #2004

Closed
christianlupus opened this issue Dec 17, 2023 · 9 comments · Fixed by #2421
Closed

Handle fractions nicely during recalculations #2004

christianlupus opened this issue Dec 17, 2023 · 9 comments · Fixed by #2421
Labels
enhancement New feature or request Frontend Issue or PR related to the frontend code

Comments

@christianlupus
Copy link
Collaborator

In recipes, fractions are usually used for the non-integer quantity, e.g. 1/2 tsp. The specification 0.5 tsp is rather uncommon.
It would be nice if the automatic change from the input (e.g. 1/3) to 0.33 could be prevented by configuration.

Ursprünglich gepostet von @cloud2018 in #1987 (comment)

@christianlupus christianlupus added enhancement New feature or request Frontend Issue or PR related to the frontend code labels Dec 17, 2023
@christianlupus christianlupus changed the title In recipes, fractions are usually used for the non-integer quantity, e.g. 1/2 tsp. The specification 0.5 tsp is rather uncommon. Handle fractions nicely during recalculations Dec 17, 2023
@christianlupus
Copy link
Collaborator Author

@j0hannesr0th do you think, you can extent the script in this direction?

@j0hannesr0th
Copy link
Contributor

I've played a bit with fractions during the implementation and decided to parse fractions as decimal.

I'll give you an example for a dessert pudding recipe:

  • 7 servings of pudding -> 3/4 litres of milk
  • 4 servings of pudding -> 3/7 litres of milk
  • 9 servings of pudding -> 27/28 litres of milk
  • 10 servings of pudding -> 15/14 litres of milk
  • 14 servings of pudding -> 3/2 litres of milk

Not sure if this feature is helpful for fractions...

A possible solution I've thought about is:

  • if a fraction is used in the recipe -> disable the yield input
  • only allow clicking of the < > arrows
  • the number will increase / decrease by the number of servings
    -> 7, 14, 21, ...

@cloud2018
Copy link

For this reason, most recipes are also given for 1 or 4 portions and not for 7 (prime number) portions, as in the more theoretical example.

In j0hannesr0th's example, the usual specification for 14 portions would not be 3/2 litres of milk but 1 1/2 litres of milk,

Y you could use for example, if the quantity modulo 2 = 1, x 1/2. Similarly for 1/8, 1/4. Something similar would be possible for 1/3. Only if such a familiar representation is not possible should a decimal representation be used.

Have a look on https://www.chefkoch.de/rezepte/845091189864506/Omas-Pizzasuppe.html?portionen=6
shows the quantity of vegetable stock
for 6 portions ¾ liter
for 12 portions 1 ½ liters
for 4 portions ½ liter
for 5 portions 0.63 liters

@j0hannesr0th
Copy link
Contributor

I checked the recipe you've provided but it works not properly (not with fractions) for 8 servings, too. It could have used 1/3 and 2/3 in some places, but has used the decimal version instead.

The pudding problem I described is not a theoretical problem, it's a real life problem. I have some special dessert glasses and the original recipe was for 8 glasses. With my glasses it filled only 7 glasses - using 8 glasses made the glasses look empty. So instead of fixing all the ingredients I just changed the servings.


Off topic for personal interest: @cloud2018 are you familiar with imperial measurement in cooking?

I have a lot of ice recipes which often use 3 or 4 mg of locust bean gum. How do you show this in grain? 1/16 and 1/22 grains? It needs to be measured perfectly because if you use too much your ice cream will be like bubble gum and not creamy.

@seyfeb
Copy link
Collaborator

seyfeb commented Dec 17, 2023

I think the point of the request is the following. Lots of people are used to seeing 1/2 tsp rather than 0.5 tsp as an ingredient. However if someone decides to write 0.5 tsp we should honor the decision and show this as 0.5 tsp in the ingredient list.

We would still need to decide what happens to 1 tsp if the number of servings is halved. Then we could either use an opinionated approach by showing fractions or look at the other ingredients and, if fractions are used in there, use fractions.

However, I would suggest to avoid overly complicated and unusal fractions (in recipes). Without having done any research it would say readable fractions are 1/2, 1/3, 1/4, 1/5, and 1/8 (debatable) and for numbers larger than one I would suggest the form 3 1/2 instead of 7/2.

This would also mean 2/7 is not shown, but 0.29 (precision tbd) instead, which is probably much more intuitive for the majority of people ;).

@j0hannesr0th
Copy link
Contributor

@seyfeb as far as i remember "1/8 litres milk" is stored as varchar in the database. Talking about database standardisation you must then write a function which translates decimals to common "readable" fractions, since MariaDB can't store "native" fractions.

How do you want to store "1 1/3 litres milk" in the database?

Ingredient Value Unit
Milk (referenced, FK) 1.33333333333333333333333333 Litres (referenced, FK)

Like this? And how does the the user enter it?

1 ⅓ or 1.33 or 1 1/3 or 4/3

I could provide more examples of why using fractions instead of decimals makes no sense, but since it's your project, I don't want to spend time discussing things that are ultimately unimportant and where I cannot make a decision.

@seyfeb
Copy link
Collaborator

seyfeb commented Dec 17, 2023

1 ⅓, 1 1/3, or 4/3 should all be fine since this are standard formats we might be able to parse.

The question how to store these values in a structured way, as you asked is a good one. Currently this is no problem, since there are only strings stored in the JSON. Afaik they are not stored in the database, but it is discussed to store them in a more structured way, e.g., as a HowToSupply (see here).

When storing 1/3 as 0.33333333333333333333333333 it seems possible to convert it back to 1/3, but it certainly is a workaround.

Edit: You could obviously store every number in the database as nominator with denominator where floats have a denominator of 1. In the schema.org JSON the value can be a number or a string.

@seanwalter
Copy link

I would like to add a plug for maintaining fractions in how ingredients are shown, especially if that’s how they were entered. I appreciate the app’s ability to calculate new ingredient quantities by changing the number of servings, but — at least for me — a lot of that quickly becomes meaningless…

If a recipe for 4 servings is increased to 5 and I need to increase 1/4 tsp of something, I have no idea how to measure 0.31 tsp. Even if the app were to show the exact calculation of 0.3125 tsp, there’s not an intuitive conversion from that number to quantities supported by actual measuring spoons. But I can look at 1/4 tsp as my original quantity in the original recipe, pull out my 1/4 tsp spoon, use it for the base amount, and then estimate how to fill it 1/4 full to get enough ingredient for one more portion.

As someone else said in this thread, I don’t want to tell you how to develop your app, which my entire family really appreciates. But I at least want to register a strong preference for fractions in ingredient lists when that was the original text — at least for the baseline number of servings. It’s the way home cooks have been conditioned to think.

Maybe the solution could be to switch to decimals if someone changes the number of servings. If someone is doing that, they might be more understanding of the fact that the app needs to switch to decimals in order to calculate the new volumes and keep the coding manageable.

Weissnix4711 added a commit to Weissnix4711/nc-cookbook that referenced this issue Jul 13, 2024
Handle 16ths during recalculation of ingredients, else use decimal
christianlupus pushed a commit to Weissnix4711/nc-cookbook that referenced this issue Sep 12, 2024
Handle 16ths during recalculation of ingredients, else use decimal
christianlupus pushed a commit to Weissnix4711/nc-cookbook that referenced this issue Sep 12, 2024
Handle 16ths during recalculation of ingredients, else use decimal

Signed-off-by: Christian Wolf <[email protected]>
@christianlupus christianlupus linked a pull request Sep 12, 2024 that will close this issue
4 tasks
christianlupus added a commit that referenced this issue Sep 12, 2024
Handle fractional ingredients (Fixes #2004)
@TinfoilSubmarine
Copy link

Hi, the linked fix doesn't fully solve this issue because it notably omits support for 1/3s, which are fairly common in recipes here in the US.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Frontend Issue or PR related to the frontend code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants