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

feat: Don't calculate 100g nutriment if serving_quantity <=5 and value = '0', fixes #5848 #8403

Merged
merged 7 commits into from
May 22, 2023

Conversation

john-gom
Copy link
Contributor

@john-gom john-gom commented May 8, 2023

What

Screenshot

Related issue(s) and discussion

  • Fixes #[ISSUE NUMBER]

@@ -130,7 +130,12 @@ sub convert_string_to_number ($value) {
}
# Remove remaining commas that can be used as separators
$value =~ s/,//g;
$value += 0;

# If number has been recorded as 0.0 without decimals then want to preserve this
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Today we don't have a way to store "4.0" or "0.0", they are converted to 4 and 0. The API expects numbers for both reading and writing (even though we do support strings for writing).

@john-gom
Copy link
Contributor Author

john-gom commented May 9, 2023

Today we don't have a way to store "4.0" or "0.0", they are converted to 4 and 0. The API expects numbers for both reading and writing (even though we do support strings for writing).

Do you anticipate [problem,s with what I am doing here then?

@codecov-commenter
Copy link

codecov-commenter commented May 9, 2023

Codecov Report

Merging #8403 (6e61f97) into main (dbf1da6) will increase coverage by 0.00%.
The diff coverage is 61.53%.

@@           Coverage Diff           @@
##             main    #8403   +/-   ##
=======================================
  Coverage   48.47%   48.47%           
=======================================
  Files         114      114           
  Lines       21277    21286    +9     
  Branches     4770     4772    +2     
=======================================
+ Hits        10314    10319    +5     
- Misses       9679     9682    +3     
- Partials     1284     1285    +1     
Impacted Files Coverage Δ
lib/ProductOpener/KnowledgePanels.pm 11.51% <0.00%> (-0.11%) ⬇️
tests/unit/food.t 81.29% <75.00%> (-0.19%) ⬇️
lib/ProductOpener/Food.pm 62.60% <100.00%> (+0.12%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@aleene
Copy link
Contributor

aleene commented May 9, 2023

Today we don't have a way to store "4.0" or "0.0", they are converted to 4 and 0. The API expects numbers for both reading and writing (even though we do support strings for writing).

The number of digits might imply an accuracy of the value. So 0.5 implies an error of 0.05. And 0.00 an error of 0.005. A kind of implied accuracy.
We could interpret values of < 0.2 as a value of 0 with an error of 0.2. So a separate error-field would be useful.

@stephanegigandet
Copy link
Contributor

Today we don't have a way to store "4.0" or "0.0", they are converted to 4 and 0. The API expects numbers for both reading and writing (even though we do support strings for writing).

Do you anticipate [problem,s with what I am doing here then?

I tried to run it and edit products, but somehow "0.0" is not kept for me. I probably made a mistake somewhere, but I haven't found it yet.

I don't think we should have a field that is always of type number, unless it's "0.0". I think it would be very worthwhile to find a way to keep the extra 0s, but it should be in all numbers (e.g. "4.00").

The function convert_string_to_number() is intended to return a number type, it's used in other functions, so we should be careful if we change its behaviour (probably a new function would be better).

@github-actions github-actions bot removed the Numbers label May 15, 2023
@github-actions github-actions bot added 📖 Knowledge Panels https://wiki.openfoodfacts.org/Knowledge_panels serving size Template::Toolkit The templating toolkit used by product opener. The starting point for HTML/JS/CSS fixes. Translations We use a non-standard version of GetText, lack language variants support translate.openfoodfacts.org labels May 15, 2023
Copy link
Contributor

@stephanegigandet stephanegigandet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thank you!

The PR is still marked as "draft", can we merge it?

@john-gom john-gom marked this pull request as ready for review May 22, 2023 07:29
@john-gom john-gom requested a review from a team as a code owner May 22, 2023 07:29
@sonarcloud
Copy link

sonarcloud bot commented May 22, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Contributor

@stephanegigandet stephanegigandet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@john-gom john-gom merged commit 5031077 into main May 22, 2023
@john-gom john-gom deleted the issue/5848 branch May 22, 2023 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 Documentation Documentation issues improve the project for everyone. Food.pm 📖 Knowledge Panels https://wiki.openfoodfacts.org/Knowledge_panels serving size Template::Toolkit The templating toolkit used by product opener. The starting point for HTML/JS/CSS fixes. 🧪 tests Translations We use a non-standard version of GetText, lack language variants support translate.openfoodfacts.org 🧪 unit tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nutrition values for extra small serving (e.g. less than 1 g spray) cannot be extrapolated to 100g
4 participants