3
3
"""
4
4
5
5
from __future__ import annotations
6
+ import random
6
7
from typing import Union
7
8
import json
8
9
from datetime import datetime
@@ -25,7 +26,7 @@ class FoodEntry(CARBON_MODEL):
25
26
cheese : int
26
27
milk : int
27
28
food_waste : int
28
- metric_threshold = 200 / 3
29
+
29
30
30
31
# food measurements in # of 100g servings
31
32
def __init__ (self , oid : ObjectId , user_id : ObjectId , carbon_emissions : int , date : Union [str , datetime ],
@@ -75,14 +76,14 @@ def from_json(doc: json) -> FoodEntry:
75
76
)
76
77
77
78
def calculate_carbon_emissions (self ) -> float :
78
- beef_carbon_emissions = self .beef * 15.5
79
- lamb_carbon_emissions = self .lamb * 5.84
80
- pork_carbon_emissions = self .pork * 2.4
81
- chicken_carbon_emissions = self .chicken * 1.8
82
- fish_carbon_emissions = self .fish * 1.8
83
- cheese_carbon_emissions = self .cheese * 2.79
79
+ beef_carbon_emissions = self .beef * 9.9
80
+ lamb_carbon_emissions = self .lamb * 3.9
81
+ pork_carbon_emissions = self .pork * 1.2
82
+ chicken_carbon_emissions = self .chicken * 0.98
83
+ fish_carbon_emissions = self .fish * 1.3
84
+ cheese_carbon_emissions = self .cheese * 2.3
84
85
milk_carbon_emissions = self .milk * 0.8
85
- food_waste_carbon_emissions = self .food_waste * 0.25
86
+ food_waste_carbon_emissions = self .food_waste * 0.0025
86
87
return sum ([beef_carbon_emissions , lamb_carbon_emissions , pork_carbon_emissions ,
87
88
chicken_carbon_emissions , fish_carbon_emissions , cheese_carbon_emissions ,
88
89
milk_carbon_emissions , food_waste_carbon_emissions ])
@@ -91,6 +92,7 @@ def __repr__(self) -> str:
91
92
return f'Food ID: { self .oid .__str__ ()} '
92
93
93
94
95
+
94
96
class FoodEntryRecommendation (DB_MODEL ):
95
97
beef_recommendation : str
96
98
lamb_recommendation : str
@@ -142,48 +144,81 @@ def from_json(doc: json) -> FoodEntryRecommendation:
142
144
143
145
@staticmethod
144
146
def from_food_entry (food_entry : FoodEntry ) -> FoodEntryRecommendation :
145
- submetric_threshold = FoodEntry .metric_threshold / 8
146
- beef_recommendation = "Beef emissions look good!"
147
- lamb_recommendation = "Lamb emissions look good!"
148
- pork_recommendation = "Pork emissions look good!"
149
- chicken_recommendation = "Chicken emissions look good!"
150
- fish_recommendation = "Fish emissions look good!"
151
- cheese_recommendation = "Cheese emissions look good!"
152
- milk_recommendation = "Milk emissions look good!"
153
- food_waste_recommendation = "Food waste emissions look good!"
154
-
155
- beef_carbon_emissions = food_entry .beef * 15.5
156
- lamb_carbon_emissions = food_entry .lamb * 5.84
157
- pork_carbon_emissions = food_entry .pork * 2.4
158
- chicken_carbon_emissions = food_entry .chicken * 1.8
159
- fish_carbon_emissions = food_entry .fish * 1.8
160
- cheese_carbon_emissions = food_entry .cheese * 2.79
147
+ submetric_threshold = 11
148
+ beef_recommendation = "Looking good!"
149
+ lamb_recommendation = "Looking good!"
150
+ pork_recommendation = "Looking good!"
151
+ chicken_recommendation = "Looking good!"
152
+ fish_recommendation = "Looking good!"
153
+ cheese_recommendation = "Looking good!"
154
+ milk_recommendation = "Looking good!"
155
+ food_waste_recommendation = "Looking good!"
156
+
157
+ beef_carbon_emissions = food_entry .beef * 9.9
158
+ lamb_carbon_emissions = food_entry .lamb * 3.9
159
+ pork_carbon_emissions = food_entry .pork * 1.2
160
+ chicken_carbon_emissions = food_entry .chicken * 0.98
161
+ fish_carbon_emissions = food_entry .fish * 1.3
162
+ cheese_carbon_emissions = food_entry .cheese * 2.3
163
+
161
164
milk_carbon_emissions = food_entry .milk * 0.8
162
- food_waste_carbon_emissions = food_entry .food_waste * 0.25
165
+ food_waste_carbon_emissions = food_entry .food_waste * 0.0025
163
166
164
167
if beef_carbon_emissions > submetric_threshold :
165
- beef_recommendation = "Beef emissions too high"
168
+ recommendation1 = "Try opting for white meat (fish, chicken, etc.)"
169
+ recommendation2 = "Consider alternate forms of protein (chicken, fish, eggs, etc.)"
170
+ recommendation3 = "Try opting for low-impact plant protein sources like peas, legumes and tofu"
171
+ recommendations = [recommendation1 , recommendation2 , recommendation3 ]
172
+ beef_recommendation = random .choice (recommendations )
166
173
167
174
if lamb_carbon_emissions > submetric_threshold :
168
- lamb_recommendation = "Lamb emissions too high"
169
-
175
+ recommendation1 = "Try opting for white meat (fish, chicken, etc.)"
176
+ recommendation2 = "Consider alternate forms of protein (chicken, fish, eggs, etc.)"
177
+ recommendation3 = "Try opting for low-impact plant protein sources like peas, legumes and tofu"
178
+ recommendations = [recommendation1 , recommendation2 , recommendation3 ]
179
+ lamb_recommendation = random .choice (recommendations )
180
+
170
181
if pork_carbon_emissions > submetric_threshold :
171
- pork_recommendation = "Pork emissions too high"
182
+ recommendation1 = "Try opting for white meat (fish, chicken, etc.)"
183
+ recommendation2 = "Consider alternate forms of protein (chicken, fish, eggs, etc.)"
184
+ recommendation3 = "Try opting for low-impact plant protein sources like peas, legumes and tofu"
185
+ recommendations = [recommendation1 , recommendation2 , recommendation3 ]
186
+ pork_recommendation = random .choice (recommendations )
172
187
173
188
if chicken_carbon_emissions > submetric_threshold :
174
- chicken_recommendation = "Chicken emissions too high"
189
+ recommendation1 = "Try opting for low-impact plant protein sources (peas, legumes and tofu)"
190
+ recommendation2 = "Consider alternate forms of protein (eggs, whey, etc.)"
191
+ recommendation3 = "Consider opting for seitan"
192
+ recommendations = [recommendation1 , recommendation2 , recommendation3 ]
193
+ chicken_recommendation = random .choice (recommendations )
175
194
176
195
if fish_carbon_emissions > submetric_threshold :
177
- fish_recommendation = "Fish emissions too high"
196
+ recommendation1 = "Consider alternate forms of protein (chicken, eggs, whey, etc.)"
197
+ recommendation2 = "Try opting for low-impact plant protein sources (peas, legumes and tofu)"
198
+ recommendation3 = ""
199
+ recommendations = [recommendation1 , recommendation2 , recommendation3 ]
200
+ fish_recommendation = random .choice (recommendations )
178
201
179
202
if cheese_carbon_emissions > submetric_threshold :
180
- cheese_recommendation = "Cheese emissions too high"
203
+ recommendation1 = "Consider alternatives to cheese spreads (hummus, guacamole, etc.)"
204
+ recommendation2 = "Consider plant-based cheeses (made from nuts, soy, or tapioca)"
205
+ recommendation3 = "Consider alternatives to cheese (tofu, tempeh, etc.)"
206
+ recommendations = [recommendation1 , recommendation2 , recommendation3 ]
207
+ cheese_recommendation = random .choice (recommendations )
181
208
182
209
if milk_carbon_emissions > submetric_threshold :
183
- milk_recommendation = "Milk emissions too high"
210
+ recommendation1 = "Consider opting for almond milk"
211
+ recommendation2 = "Consider opting for soy milk"
212
+ recommendation3 = "Consider opting for oat milk"
213
+ recommendations = [recommendation1 , recommendation2 , recommendation3 ]
214
+ milk_recommendation = random .choice (recommendations )
184
215
185
216
if food_waste_carbon_emissions > submetric_threshold :
186
- food_waste_recommendation = "Food waste emissions too high"
217
+ recommendation1 = "Meal planning! Create a realistic shopping list so you only buy what you need"
218
+ recommendation2 = "Carefully assess the expiry date of all food items that you purchase"
219
+ recommendation3 = "First in First out (FIFO)! Use older ingredients first before they expire."
220
+ recommendations = [recommendation1 , recommendation2 , recommendation3 ]
221
+ food_waste_recommendation = random .choice (recommendations )
187
222
188
223
return FoodEntryRecommendation (beef_recommendation , lamb_recommendation , pork_recommendation , chicken_recommendation ,
189
224
fish_recommendation , cheese_recommendation , milk_recommendation , food_waste_recommendation )
0 commit comments