Add some additional basic nutritional values validation for ingredients#1726
Add some additional basic nutritional values validation for ingredients#1726rolandgeider wants to merge 1 commit intomasterfrom
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.
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.
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.
Also this is not fool proof. Btw I thought we already had such a check somewhere
There was a problem hiding this comment.
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.
Why are we replacing clear explicit units with abstract opaque terms?
See discussion in wger-project/flutter#614