33""" 
44
55from  __future__ import  annotations 
6+ import  random 
67from  typing  import  Union 
78import  json 
89from  datetime  import  datetime 
@@ -25,7 +26,7 @@ class FoodEntry(CARBON_MODEL):
2526    cheese : int 
2627    milk : int 
2728    food_waste : int 
28-      metric_threshold   =   200   /   3 
29+ 
2930
3031    # food measurements in # of 100g servings 
3132    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:
7576        )
7677
7778    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  
8485        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  
8687        return  sum ([beef_carbon_emissions , lamb_carbon_emissions , pork_carbon_emissions ,
8788                    chicken_carbon_emissions , fish_carbon_emissions , cheese_carbon_emissions ,
8889                    milk_carbon_emissions , food_waste_carbon_emissions ])
@@ -91,6 +92,7 @@ def __repr__(self) -> str:
9192        return  f'Food ID: { self .oid .__str__ ()}  
9293
9394
95+ 
9496class  FoodEntryRecommendation (DB_MODEL ):
9597    beef_recommendation : str 
9698    lamb_recommendation : str 
@@ -142,48 +144,81 @@ def from_json(doc: json) -> FoodEntryRecommendation:
142144
143145    @staticmethod  
144146    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+ 
161164        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  
163166
164167        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 )
166173
167174        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+         
170181        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 )
172187
173188        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 )
175194
176195        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 )
178201
179202        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 )
181208
182209        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 )
184215
185216        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 )
187222
188223        return  FoodEntryRecommendation (beef_recommendation , lamb_recommendation , pork_recommendation , chicken_recommendation ,
189224                                       fish_recommendation , cheese_recommendation , milk_recommendation , food_waste_recommendation )
0 commit comments