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

Tournant can not parse decimal fractions from Gourmand #12

Closed
fsand1 opened this issue Jun 5, 2023 · 10 comments
Closed

Tournant can not parse decimal fractions from Gourmand #12

fsand1 opened this issue Jun 5, 2023 · 10 comments

Comments

@fsand1
Copy link

fsand1 commented Jun 5, 2023

If in Gourmand a specific ingredient is defined as a fraction of a whole Tournant will not display this value. The displayed value is empty.

@Zimbelstern
Copy link
Owner

Hi, could you please provide an example how the fraction is written in the XML file?
I have tested the app with pled's recipes and the fractions are parsed quite fine, e.g. <amount>1/2</amount> in the Adalu recipe becomes 0.5 in Tournant.

@fsand1
Copy link
Author

fsand1 commented Jun 6, 2023

I am using Gourmand 1.0.0.
Fractions will be coded in decimals with comma. See attached file. The ingredient in question is the last one in the list.

Blaubeer-Wacholder-Coulis.txt

@Zimbelstern
Copy link
Owner

I see. You mean numbers in decimal representation.

Gourmand is very inconsistent, it uses
a) unlocalised numbers (with dot separator) with translated words
<rating>5.0/5 Sterne</rating>
b) localised numbers with untranslated words
<preptime>0,50 hours</preptime>
c) and sometimes even a dot as a thousands separator
<amount>1.000</amount>
all in the same file.

While it would be very easy to treat 0,5 the same as 0.5, this file format invokes a bigger problem: How should Tournant know the locale of the file content? There may be cases in which there are only ambigous numbers like 300 or 1.234. Does 1.234 equals 1234 * 10^(-3) or 1234?
Hence, in the current state, these files are not a suitable recipe exchange format.

I addressed this issue to Gourmand but as there is no active development, I wouldn't expect a fix on this side.

However, at the side of Tournant, any solution will always be a bad compromise: Should the app assume that the every file has the same locale as the Android device, neglecting the possibility of an exchange between different devices or people speaking different languages? Should the app introduce complicated settings for the user who may or may not know about the decimal separator used in the file? And how should Tournant behave when exporting to an XML file?

This problem can only be solved on Gourmand's side. Either by exporting with only the same (i.e. dot) delimiters or by specifying the locale in the file.

Until there is a solution for that, you can try to check Use fractions in the Gourmand options. 0,25 should then be exported as 1/4 instead (and the thousands delimiter will disappear, too – why?). This will, however, not work for fractions like 3,14. Alternatively, you can downgrade the app to 1.1.7 and below, if this works better for you.

@Zimbelstern Zimbelstern changed the title Tournant can not handle fraction of a whole (Tournant version 2.1) Tournant can not parse decimal fractions from Gourmand Jun 7, 2023
@Zimbelstern
Copy link
Owner

Let's try this. From version 2.2 on, Tournant will parse and write XML files with commas depending on the language of your device. You can change the decimal separator in the settings of the app (e.g. if you need to open recipes from colleagues using a different locale). But beware: Tournant now ignores everything that is not a digit or the configured decimal separator so instead of an empty amount, you may oversalt your soup. ;-)

@mendelsphotography
Copy link

just wondering if this is ever going to be fixed.

@Zimbelstern
Copy link
Owner

Could you please elaborate what is not working for you?

@mendelsphotography
Copy link

Could you please elaborate what is not working for you?

not sure if this is the same issue assuming based on what i read here it is if not let me know and will open a new issue.

When trying to add a fraction amount in a recipe like 1 and half or even half or maybe even a quarter it does not allow. So based on what i read here i tried to use a comma which did not let me put so tried a period but just put it was 1.5 not putting 1/2 the proper way.

@Zimbelstern
Copy link
Owner

If you want to use a commas instead of a periods, you can change that in the settings.

You should be able to input 0.5 tsp baking soda (or 0,5). However, this will not be displayed as ½ and you are not able to put in 1/2 literally. I do not plan to implement any fraction representation as this would open a can of worms.

@mendelsphotography
Copy link

Ok not sure but for some reason that setting doesn't make a difference and also it says it's for import and export settings, not in the app.

Also just wondering why adding fractions is opening a can of worms?
Since based on the fact that it's for recipes I would like to think it would have that. But sometimes what you think as outsider is a bug is done on purpose. But just curious why it can't be implemented.

@Zimbelstern
Copy link
Owner

Ok not sure but for some reason that setting doesn't make a difference and also it says it's for import and export settings, not in the app.
Sorry, I forgot my own implementation... and because we are still in this thread which is about Gourmand!

The decimal separator should match the locale on your device. If this is not the case, would you tell me the locale on your phone? Maybe I missed something.

Also just wondering why adding fractions is opening a can of worms? Since based on the fact that it's for recipes I would like to think it would have that. But sometimes what you think as outsider is a bug is done on purpose. But just curious why it can't be implemented.

The amount is saved as a Float. You can't save the representation of a number in a float. So you have to add another variable where you need to save if the user wants 0.5, 1/2, 2/4 or whatever. So you would have to save the denominator. This would make calculations more difficult. And then there are fractions like 1/3 which can not be saved as a decimal number... These are only some reasons why the effort will not pay off for me.

You can of course write 1/2 in the same field like the unit. Will look the same. Just no calculations possibly then.

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

No branches or pull requests

3 participants