q-m / nutriscore-ruby

nutriscore computation for Ruby
MIT License
1 stars 0 forks source link

Check example with negative points ≥11 #1

Closed wvengen closed 2 years ago

wvengen commented 2 years ago

In eec3947c5685888a0a78e6ef9dd41001e9094c32 a test was added with a product with negative points ≥11, meaning the protein value is not taken into account (previously it rose an exception in this case). I'm not fully sure the amount of points returned is correct. Check that the spec for Köttbullar Mammas has the right score and score_class.

wvengen commented 2 years ago

Filling the values in at [this Nutri-Score calculator](), I get the expected values.

Explanation

The Nutri-Score is calculated by adding points for the bad ingredients and subtracting points for the good ingredients. The ore points a food has in total, the unhealthier it is. Depending on the score, the food is assigned a grade from A-E. A is the best score and E is the worst.

First the points for the negative ingredients are calculated: 2P(kJ) + 0P(Sugar) + 5P(Saturated Fat) + 7P(Sodium) = 14P

Then points are deducted for the positive ingredients. In the case of the positive ingredients, the points for protein were not deducted, because it is not a cheese, the number of negative points is greater than 11 and the product consists of less than 80% fruit,vegetables or nuts. The total score for the positive ingredients is therefore calculated as follows: 0P(Fiber) + 0P(Vegetables, fruit, nuts) = 0P

To obtain the overall result, the sum of the good ingredients 0P is deducted from the sum of negative ingredients (14P): 14P - 0P = 14P

This results in 14 and thus corresponds to a Nutri-Score of D.