-
-
Notifications
You must be signed in to change notification settings - Fork 596
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
Add some additional basic nutritional values validation for ingredients #1726
base: master
Are you sure you want to change the base?
Conversation
@Dieterbe does the logic in |
if energy_protein > self.energy: | ||
raise ValueError( | ||
f'Energy calculated from protein is greater than total energy: {energy_protein} > {self.energy}' | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The protein, carb and fat energy values are rough. Checking this too strictly might trigger false positives , especially for ingredients that only contain 1 macro (eg egg whites)
For sanity checking maybe allow 20% error or so ? I would be curious to have a look at ingredients for which we trigger errors here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also all these checks are quite verbose. Do we need to raise ValueErrors explicitly? Could we replace these with simple, single line assert statements ? If the code is more obvious, it also reduces the need for unit testing
raise ValueError( | ||
f'Total energy calculated is greater than energy: {energy_calculated} > {self.energy}' | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also this is not fool proof. Btw I thought we already had such a check somewhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note also that in current form, if this triggers, one of the previous ones will have triggered too.
'protein': {'kg': 4, 'lb': 113}, | ||
'carbohydrates': {'kg': 4, 'lb': 113}, | ||
'fat': {'kg': 9, 'lb': 225}, | ||
'protein': {'metric': 4, 'imperial': 113}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we replacing clear explicit units with abstract opaque terms?
See discussion in wger-project/flutter#614