Closed iffy-pi closed 6 months ago
Checked the output dictionary made by Display Food Item. Comma based decimals are automatically converted to whole numbers rather than their decimal counter parts.
Updated Display Food Item to automatically convert comma based decimals to period based decimals in the back end (Commit: https://github.com/iffy-pi/apple-shortcuts/commit/7c8517fc87a46125ed4465e4eb355334a0effee4)
Made a simple shortcut "Test Logging" which passes a sample test food with Fat = 1.2 and Carbs = 2.3 into the log algorithm to test how it is parsed. Test shortcut can be downloaded here. Will be testing on my end and on users end to see the results of what is logged when in Portugese settings
Ran the shortcut on my end with Portugese-Brazil (PT-BR) language settings and did not run into the error. Neither did the user. We both reported the correct values being logged. This suggests an issue with how the food is being parsed earlier on?
Attempting a sample "Log Foods At Time Run" where I investigate the input into the Log Algorithm
Sample run worked as expected, Log Algorithm Food input had correct decimals and nutrients logged into Apple Health where the correct value (2.3 and 1.2 respectively)
Just realized that the user has specific number settings. 1 thousand, 500 and 25/100 = 1.500,25 instead of 1,500.25. Changed my number settings to match the users and ran the test shortcut again:
Even with updated number settings, the test logging shortcut works as expected. Doing sample run through with "Log Foods At Time"
Sample run through works as expected, Health app shows the values logged correctly respecting the number format
The main issue comes from the conversion of text to numbers in display food item. With comma for thousands and periods for decimals (CTPD)
3.8 => 3*1 + 8/10
3,8 => 30 + 8
3,800 => 3000 + 8*100
With periods for thousands and commas for decimals (PTCD)
3.8 => 30 + 8
3,8 => 3*1 + 8/10
3.800 => 3000 + 800
JSON Numbers use CTPD, but the system will automatically convert numbers to the selected number format which causes issues.
If the food has some nutrient set to 0.4
, when doing the calculations to log the value 0.4
will be evaluated to 4*1
instead of 4/10
, which makes the resulting value a whole number.
There needs to be a way to convert the JSON formatted numbers to their appropriate decimal version in the selected number type
This issue is currently unresolved within the shortcut, to fix it the shortcut must be able to detect and automatically convert numbers to the appropriate number type when performing calculations. This change will have to be made at all points where number calculations are performed / viewed and will take some time to implement.
Until then, users can work around this issue by setting their number format to CTPD rather than PTCD: For the number: three and two tenths: CTPD: 3.2 PTCD: 3,2
As of the current state, this is out of my scope of work
Currently working on it to make it work with PTCD system
Will be doing support check for all shortcuts:
Resolved and released in version v4.10 (#46)
When a food is made manually using decimal values with a comma e.g. "1,6" instead of "1.6", they are logged as whole numbers. This was reported by a user who uses the Portugese-Brazil language setting, where commas are used in decimals.