iffy-pi / apple-shortcuts

A repository for handling the updates and versioning of my apple shortcuts
https://iffy-pi.github.io/apple-shortcuts/
3 stars 0 forks source link

Nutrition Framework - Issues logging decimal values that use comma instead of period #1

Closed iffy-pi closed 6 months ago

iffy-pi commented 11 months ago

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.

iffy-pi commented 11 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.

iffy-pi commented 11 months ago

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)

iffy-pi commented 11 months ago

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

iffy-pi commented 11 months ago

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?

iffy-pi commented 11 months ago

Attempting a sample "Log Foods At Time Run" where I investigate the input into the Log Algorithm

iffy-pi commented 11 months ago

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)

iffy-pi commented 11 months ago

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: IMG_1755 IMG_1754

iffy-pi commented 11 months ago

Even with updated number settings, the test logging shortcut works as expected. Doing sample run through with "Log Foods At Time"

iffy-pi commented 11 months ago

Sample run through works as expected, Health app shows the values logged correctly respecting the number format

Image (2) Image (1)
iffy-pi commented 11 months ago

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

iffy-pi commented 11 months ago

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

iffy-pi commented 9 months ago

As of the current state, this is out of my scope of work

iffy-pi commented 6 months ago

Currently working on it to make it work with PTCD system

iffy-pi commented 6 months ago

Will be doing support check for all shortcuts:

iffy-pi commented 6 months ago

Resolved and released in version v4.10 (#46)