Self hosted FLOSS fitness/workout, nutrition and weight tracker
Remove the dead imperial branch from the nutritional calculations
Roland Geidere41bf7b9fe26
diff --git a/wger/nutrition/consts.py b/wger/nutrition/consts.pyindex 581b4eb2d..97d9a2f8e 100644--- a/wger/nutrition/consts.py+++ b/wger/nutrition/consts.py@@ -31,13 +31,13 @@ class SyncMode(enum.Enum):ENERGY_FACTOR = {- 'protein': {'kg': 4, 'lb': 113},- 'carbohydrates': {'kg': 4, 'lb': 113},- 'fat': {'kg': 9, 'lb': 225},- 'fiber': {'kg': 2, 'lb': 57},+ 'protein': 4,+ 'carbohydrates': 4,+ 'fat': 9,+ 'fiber': 2,}"""-Simple approximation of energy (kcal) provided per gram or ounce+Simple approximation of energy (kcal) provided per gramThe values are the conversion factors from EU Regulation 1169/2011, Annex XIV"""diff --git a/wger/nutrition/dataclasses.py b/wger/nutrition/dataclasses.pyindex 80df909f0..fe0a1a87b 100644--- a/wger/nutrition/dataclasses.py+++ b/wger/nutrition/dataclasses.py@@ -120,10 +120,10 @@ class IngredientData:# usually not included in the carbohydrate value. See the comments on the# threshold constants in consts.py for the tolerances used.energy_computed = (- self.protein * ENERGY_FACTOR['protein']['kg']- + self.carbohydrates * ENERGY_FACTOR['carbohydrates']['kg']- + self.fat * ENERGY_FACTOR['fat']['kg']- + (self.fiber or 0) * ENERGY_FACTOR['fiber']['kg']+ self.protein * ENERGY_FACTOR['protein']+ + self.carbohydrates * ENERGY_FACTOR['carbohydrates']+ + self.fat * ENERGY_FACTOR['fat']+ + (self.fiber or 0) * ENERGY_FACTOR['fiber'])if self.energy > ENERGY_CHECK_MIN_KCAL or energy_computed > ENERGY_CHECK_MIN_KCAL:energy_lower = (diff --git a/wger/nutrition/helpers.py b/wger/nutrition/helpers.pyindex 20be177dd..522aca4ab 100644--- a/wger/nutrition/helpers.py+++ b/wger/nutrition/helpers.py@@ -39,11 +39,11 @@ class BaseMealItem:This just provides some common helper functions"""- def get_nutritional_values(self, use_metric=True):+ def get_nutritional_values(self):"""Sums the nutritional info for the ingredient in the MealItem- :param use_metric Flag that controls the units used+ All values are in grams"""values = NutritionalValues()@@ -70,23 +70,6 @@ class BaseMealItem:if self.ingredient.sodium:values.sodium = self.ingredient.sodium * item_weight / 100- # # If necessary, convert weight units- # if not use_metric:- # for key, value in nutritional_info.items():- #- # # Energy is not a weight!- # if key == 'energy':- # continue- #- # # Everything else, to ounces- # nutritional_info[key] = AbstractWeight(value, 'g').oz- #- # nutritional_info['energy_kilojoule'] = Decimal(nutritional_info['energy']) * Decimal(4.184)-- # Only 2 decimal places, anything else doesn't make sense- # for i in nutritional_info:- # nutritional_info[i] = Decimal(nutritional_info[i]).quantize(TWOPLACES)-return valuesdiff --git a/wger/nutrition/models/meal.py b/wger/nutrition/models/meal.pyindex e90012a95..2227a5fff 100644--- a/wger/nutrition/models/meal.py+++ b/wger/nutrition/models/meal.py@@ -83,15 +83,13 @@ class Meal(models.Model):"""return self.plan- def get_nutritional_values(self, use_metric=True):+ def get_nutritional_values(self):"""Sums the nutritional info of all items in the meal-- :param: use_metric Flag that controls the units used"""nutritional_values = NutritionalValues()for item in self.mealitem_set.select_related():- nutritional_values += item.get_nutritional_values(use_metric=use_metric)+ nutritional_values += item.get_nutritional_values()return nutritional_valuesdiff --git a/wger/nutrition/models/plan.py b/wger/nutrition/models/plan.pyindex a0df5c26b..ac13a7e08 100644--- a/wger/nutrition/models/plan.py+++ b/wger/nutrition/models/plan.py@@ -133,7 +133,6 @@ class NutritionPlan(models.Model):nutritional_representation = cache.get(cache_mapper.get_nutrition_cache_by_key(self.pk))if not nutritional_representation:nutritional_values = NutritionalValues()- use_metric = self.user.userprofile.use_metricresult = {'total': NutritionalValues(),'percent': {'protein': 0, 'carbohydrates': 0, 'fat': 0},@@ -142,25 +141,21 @@ class NutritionPlan(models.Model):# Energyfor meal in self.meal_set.select_related():- nutritional_values += meal.get_nutritional_values(use_metric=use_metric)+ nutritional_values += meal.get_nutritional_values()result['total'] = nutritional_valuesenergy = nutritional_values.energy- # In percent. The macros are always in grams, regardless of the- # unit the user prefers, so the energy factor per gram applies.+ # In percentif energy:result['percent']['protein'] = (- nutritional_values.protein * ENERGY_FACTOR['protein']['kg'] / energy * 100+ nutritional_values.protein * ENERGY_FACTOR['protein'] / energy * 100)result['percent']['carbohydrates'] = (- nutritional_values.carbohydrates- * ENERGY_FACTOR['carbohydrates']['kg']- / energy- * 100+ nutritional_values.carbohydrates * ENERGY_FACTOR['carbohydrates'] / energy * 100)result['percent']['fat'] = (- nutritional_values.fat * ENERGY_FACTOR['fat']['kg'] / energy * 100+ nutritional_values.fat * ENERGY_FACTOR['fat'] / energy * 100)# Per body weight