Closed V1d1o7 closed 2 years ago
hmm interesting suggestion. It makes sense to support fractions both for data entry and display but storing stuff in fractions would mean additional computing everytime a recipe is scaled.
What could be done i think is that upon input fractions are converted to decimals and when displaying be converted back to fractions. Thats not easy to implement given the current way things work but much easier than changing to a non number datatype.
Just for my general understanding: if a recipe uses more than 1 of something its 1 1/4
cups of or 5 1/2
xyz right ? Also what kind of resolution is realistically needed (1/10 or 1/20 or only something like 1/8) because the converter needs some kind of limit (could be in the settings like the decimal places i guess)
Our stupid weights and measurements for cooking use:
1/8 = .125
1/4 = .25
1/3 = .33
1/2 = .5
2/3 = .65
3/4 = .75
So it could be 1¼ Cups
or it could just be ¼ teaspoon
works in both directions, more than a whole or less than. I am fairly certain the above are the only fractions we use in cooking, if not it's the most common.
I understand that you are based in Django and this website is most likely not Django, but it is an example of a scaling recipe and might be of at least a starting point.
Thanks for all the info, this should definitely be doable (at least for displaying, data entry might be a little harder).
Let me know when you have anything that needs some testing and I will be more than happy to do so!
I think this will be more challenging than it seems.
If you have a recipe that calls for 2 tablespoons, and you double the recipe, that's 4 tablespoons... but 4 tablespoons also equals 1/4 cup. So you have to figure out which is the more appropriate unit to present to the user.
Displaying it as 4 tablespoons is fine, but what if you want to quadruple the recipe? It then becomes 8 tablespoons, which is better represented as 1/2 cup, because the person reading the recipe doesn't want to have to fill 8 separate tablespoons.
Or..
Say the recipe calls for 1/4 cup, and you want to halve the recipe.. it would be better to convert it to 2 tablespoons, because 1/8 measuring cups aren't terribly common. Most people have 1 cup, 3/4 cup, 1/2 cup, 1/4 cup measuring cups.
So you'd need to set some thresholds for unit conversion.
Perhaps a library already exists for this sort of thing
EDIT: It gets even weirder with teaspoons. 3tsp = 1tbsp. So the unit calculations get even more complicated when scaling the recipe.
Though you do make a very good point @NessInOnett on that front, I would just be happy to have the fractions as I have a conversion sheet in my cook book as it is and personally don't mind the math. Besides if I am multiplying a recipe I typically don't rewrite the recipe, I will just multiply each ingredient as I am making it. Now I am not saying you are wrong, you are very much so correct. If it were to be full functionality of being able to multiply or divide a recipe then yes it very may well be a bit harder to implement. However, small steps can lead to success.
https://github.com/hgrecco/pint
May be worth looking into
Thanks for all the great feedback. This was actually in discussion several month ago when i first postet this in the r/selfhosted reddit. Back then i migrated all units to be unique entities in the database (as did i with foods/ingredients). This allowed me to add ingredient linking (e.g. you have a cake with a certain base dough that is linked in the recipes) and it also allows to define how different units convert to each other.
i have not yet implemented anything like this but it is possible. I think the first think i will need to do is what is mentioned above (differentiate between decimal and fractions display), later conversion would be really nice but as you say is a much more difficult topic (although trough storing everything as decimals it should be possible)
(e.g. you have a cake with a certain base dough that is linked in the recipes)
OK.... this is the software for me. 🤘 That was a feature I was hoping for. I had two wishes: recipe notes so I can leave myself reminders of what to modify next time.. and reusable recipes. And it seems both are possible.
Sounds like a plan on the units. I appreciate that you're receptive to feedback.. thanks!
definitely, although i need to warn you, this is a lot of work and there are some other features that are higher in priority right now.
Any updates on this? Testing the app for now but would really like to see fractions implemented even if we have to do 1/2 instead of ½ (alt+0189).
sadly i do not have much free time to work on recipes overall atm and there are some more important features. I will try to get this going asap but i suspect it will take some time.
Just started using this today and fractions are definitely something I would be interested in.
I would just be happy to have the fractions as I have a conversion sheet in my cook book as it is and personally don't mind the math. Besides if I am multiplying a recipe I typically don't rewrite the recipe, I will just multiply each ingredient as I am making it.
Personally, as a first version, I would be fine with this too. I don't think you need to convert units to allow fractions.
Just started using this today and fractions are definitely something I would be interested in.
I would just be happy to have the fractions as I have a conversion sheet in my cook book as it is and personally don't mind the math. Besides if I am multiplying a recipe I typically don't rewrite the recipe, I will just multiply each ingredient as I am making it.
Personally, as a first version, I would be fine with this too. I don't think you need to convert units to allow fractions.
Agree with this as well. I'm okay with doing the conversions. I would rather have the functionality sooner than later even if that means I would get weird things like 9 tsp instead of 3tbsp.
I too would love to see fractions implemented. Its only real complaint I have right now but I understand you have other things on your plate.
haha ok this is apparently a much bigger thing than i tough 😂 it will be the next thing on my list to at least display decimals as fractions and maybe add some way of entering fractions when editing recipes (which will internally be stored as decimals).
You could also make the fractions an enumerated type, as really the only fractional values that make sense are the ones @tdvantine pointed out. Then you'd have an integer for the measure and an optional fraction drop-down. This is the way the MyFitnessPal app handles portions (e.g., 1/2 a cup gets entered as '0' for the integer portion, and '½' for the fractional portion). The scaling logic would be a little messy, but I wouldn't be worried about the kind of unit conversions that @LuckySandwich had pointed out.
Then again, I'm fine with decimal values instead of integers for the measure, and just figuring the closest 'measure' in my head, even if scaling led to weird decimals -- maybe only display three significant digits. 2.387 cups would be 2⅓ cups plus a 'dash' in my head.
PS -- love the app so far.
Thanks for the feedback The problem i am having is that, over the time, i have added a lot of fields that are basically optional and since test coverage isn't super good yet this has led to several issues where some parts of the application believe that something is required while others don't.
For that reason i dont really want to add a second field as tons of logic would need to be rewritten to support both fields. But it would definitely be the easier solution.
Without actually trying it out i was going to try to order the fractions by usefulness (smallest first, ...) and then do some kind of formula to try and match the decimals to their appropriate fractions.
Sadly i have been super busy over the last few month and had very little time to work on recipes, i am hoping to getting back to it soon but cant guarantee. Fractions is definitely a top priority when i am getting back to it.
ok so i have just added support to automatically convert the decimals into fractions. It uses Alberth's algorithm which means that even if 1/3 is rounded to .33333 or whatever it should find 1/3 as the closest matching fraction.
i guess next will be to add a little popup/calculator to the recipe edit page to allow for fraction input. The database format will remain decimals.
i will run this version a few more days on my local instance and probably push the update before christmas (if i dont forget about it 😂 ) feel free to test the dev branch but rember that there is no way to revert back to master until the updates (you cant undo the database migrations)
@vabene1111 Thanks a ton for doing this, it just makes it easier for those of us that have to live with volume measurement.
This has been completed correct? This issue isn't marked as closed but I saw an update saying that we can convert decimals to fractions.
It is basically completed for now but i plan on further improving this once more important features have been cleared.
The main thing i think is missing is a way to enter fractions when editing a recipe, leaving this issue open just reminds me of that.
Apart from that fractions are working pretty well (i guess because nobody has complained yet, i personally use decimals so if anything is broken feel free to tell me).
I have been using fractions in production and works great. Just enter the value as a decimal and it will show as a fraction on the recipes page. Other than what V said with extra features it is great!
Ah I didn't see that it was a setting, that makes sense. Working great for me now, thanks V!
Not sure if this is the right spot but: when putting in "small" decimals and displaying as fractions, the fractions are sometimes incorrect (e.g. input is 42.1, fraction shows as 42 and 1/9). v0.16.7, ref f531249
i am currently on my mobile, could you open a separate issue for this maybe with a screenshot as well and the exact values you inputted, maybe the algorithm that automatically converts the values has an issue somewhere @charlesoblack
Rounding works when fraction display is enabled but is not effective when showing decimals.
Example: I'd like store my pizza recipe on per person basis, so the amount of yeast is 1/3g, which I enter as "0.3333333g". When I scale the recipe up to 3 persons, the amount is not rounded to 1g but to 0.99g in decimal mode. In fraction mode it shows 1g.
I assume this is related to capturing only two decimals when entering the recipe. The suggested solution would be to capture ingredients in the original decimal resolution and use rounding for displaying only.
hmm interesting. All decimals are captured and when scaling/rendering the ingredients are shown to a set amount (user setting) of percision. But this set amount does not use rounding but cuts of decimals after a certain length (i think) which returns 0.99 for 3 times 0.33333 which is actually the mathematically correct result. There is also the problem of some rounding/cutting off happening on the server (in the API directly) and some happending on the client (scaling).
I will need to look into this and introduce proper rounding rules.
Thank you for your quick answer! If the current algorithm just cuts off, 0.5*10^(-'x') should be added to the value before cutting off after the 'x'th decimal.
When trying different settings of the number of decimals in the setting, I could actually not get anything but 2 decimals to show. When exporting with the standard template the value entered as "23.3333333" appeared as "23.33". Thanks again for considering an update to the rounding algorithm.
maybe i have broken the decimal setting at some point when moving stuff to the frontend, we will investigate :joy: thanks for the input
While the help text says that fractions only apply to ingredients, they are also applied to nutritional values in the UI.
right, this uses the same formatter. but i guess this is fine, we could update the help text but to be honest i find this to be a very very minor issue
fractions are considered complete for me for now, when we get to rewriting the recipe editor i will include some kind of widget to enter fractions and have them converted to decimals, everything else works already.
Is your feature request related to a problem? Please describe. The ability to add fractions for the stupid American weights and measurement system.
Describe the solution you'd like The ability to use 1/3, 2/3, 1/2, 3/4, etc etc
Describe alternatives you've considered Currently it is decimals only which works well for the metric system (which everyone should use anyways...), but not so well when you have 2/3 cup of an ingredient Additional context N/A