Skip to content

Commit

Permalink
randomly chose recommendation for each submetric
Browse files Browse the repository at this point in the history
  • Loading branch information
IshavSohal committed Dec 18, 2023
1 parent 0658343 commit 7f69882
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 28 deletions.
26 changes: 15 additions & 11 deletions backend/models/energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

from __future__ import annotations
import random
from typing import Union
import json
from datetime import datetime
Expand Down Expand Up @@ -161,22 +162,25 @@ def from_energy_entry(energy_entry: EnergyEntry) -> EnergyEntryRecommendation:
electricity_carbon_emissions = (energy_entry.electricity * 0.84) / energy_entry.household

if heating_oil_carbon_emissions > submetric_threshold:
recommendation1 = ""
recommendation2 = ""
recommendation3 = ""
heating_oil_recommendation = "Heating oil emissions too high"
recommendation1 = "Be conservative by opting to dress up/down instead of turning on the AC/heater."
recommendation2 = "Consider investing in ENERGY STAR certified products"
recommendation3 = "Consider improving your home insulation, if applicable"
recommendations = [recommendation1, recommendation2, recommendation3]
heating_oil_recommendation = random.choice(recommendations)

if natural_gas_carbon_emissions > submetric_threshold:
recommendation1 = ""
recommendation2 = ""
recommendation3 = ""
natural_gas_recommendation = "Natural gas emissions too high"
recommendation1 = "Consider replacing natural gas heating systems with electic alternatives"
recommendation2 = "Consider investing in ENERGY STAR certified products"
recommendation3 = "Consider improving your home insulation, if applicable"
recommendations = [recommendation1, recommendation2, recommendation3]
natural_gas_recommendation = random.choice(recommendations)

if electricity_carbon_emissions > submetric_threshold:
recommendation1 = "Avoid phantom power by unplugging devices you are not actually using (like your chargers or toasters!)"
recommendation1 = "Avoid phantom power by unplugging devices you are not actually using (ex.chargers, toasters, etc.)"
recommendation2 = "Consider investing in ENERGY STAR certified products"
recommendation3 = "Be conservative by opting to dress up/down instead of turning on the AC/heater."
electricity_recommendation = "Electricity emissions too high"
recommendation3 = "Be conservative by opting to dress up/down instead of turning on the AC/heater"
recommendations = [recommendation1, recommendation2, recommendation3]
electricity_recommendation = random.choice(recommendations)

return EnergyEntryRecommendation(heating_oil_recommendation, natural_gas_recommendation, electricity_recommendation)

Expand Down
25 changes: 17 additions & 8 deletions backend/models/food.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

from __future__ import annotations
import random
from typing import Union
import json
from datetime import datetime
Expand Down Expand Up @@ -162,49 +163,57 @@ def from_food_entry(food_entry: FoodEntry) -> FoodEntryRecomendation:
recommendation1 = "Try opting for white meat (fish, chicken, etc.)"
recommendation2 = "Consider alternate forms of protein (chicken, fish, eggs, etc.)"
recommendation3 = "Try opting for low-impact plant protein sources like peas, legumes and tofu"
beef_recommendation = "Beef emissions too high"
recommendations = [recommendation1, recommendation2, recommendation3]
beef_recommendation = random.choice(recommendations)

if lamb_carbon_emissions > submetric_threshold:
recommendation1 = "Try opting for white meat (fish, chicken, etc.)"
recommendation2 = "Consider alternate forms of protein (chicken, fish, eggs, etc.)"
recommendation3 = "Try opting for low-impact plant protein sources like peas, legumes and tofu"
lamb_recommendation = "Lamb emissions too high"
recommendations = [recommendation1, recommendation2, recommendation3]
lamb_recommendation = random.choice(recommendations)

if pork_carbon_emissions > submetric_threshold:
recommendation1 = "Try opting for white meat (fish, chicken, etc.)"
recommendation2 = "Consider alternate forms of protein (chicken, fish, eggs, etc.)"
recommendation3 = "Try opting for low-impact plant protein sources like peas, legumes and tofu"
pork_recommendation = "Pork emissions too high"
recommendations = [recommendation1, recommendation2, recommendation3]
pork_recommendation = random.choice(recommendations)

if chicken_carbon_emissions > submetric_threshold:
recommendation1 = "Try opting for low-impact plant protein sources (peas, legumes and tofu)"
recommendation2 = "Consider alternate forms of protein (eggs, whey, etc.)"
recommendation3 = "Consider opting for seitan"
chicken_recommendation = "Chicken emissions too high"
recommendations = [recommendation1, recommendation2, recommendation3]
chicken_recommendation = random.choice(recommendations)

if fish_carbon_emissions > submetric_threshold:
recommendation1 = "Consider alternate forms of protein (chicken, eggs, whey, etc.)"
recommendation2 = "Try opting for low-impact plant protein sources (peas, legumes and tofu)"
recommendation3 = ""
fish_recommendation = "Fish emissions too high"
recommendations = [recommendation1, recommendation2, recommendation3]
fish_recommendation = random.choice(recommendations)

if cheese_carbon_emissions > submetric_threshold:
recommendation1 = "Consider alternatives to cheese spreads (hummus, guacamole, etc.)"
recommendation2 = "Consider plant-based cheeses (made from nuts, soy, or tapioca)"
recommendation3 = "Consider alternatives to cheese (tofu, tempeh, etc.)"
cheese_recommendation = "Cheese emissions too high"
recommendations = [recommendation1, recommendation2, recommendation3]
cheese_recommendation = random.choice(recommendations)

if milk_carbon_emissions > submetric_threshold:
recommendation1 = "Consider opting for almond milk"
recommendation2 = "Consider opting for soy milk"
recommendation3 = "Consider opting for oat milk"
milk_recommendation = "Milk emissions too high"
recommendations = [recommendation1, recommendation2, recommendation3]
milk_recommendation = random.choice(recommendations)

if food_waste_carbon_emissions > submetric_threshold:
recommendation1 = "Meal planning! Create a realistic shopping list so you only buy what you need"
recommendation2 = "Carefully assess the expiry date of all food items that you purchase"
recommendation3 = "First in First out (FIFO)! Use older ingredients first before they expire."
food_waste_recommendation = "Food waste emissions too high"
recommendations = [recommendation1, recommendation2, recommendation3]
food_waste_recommendation = random.choice(recommendations)

return FoodEntryRecomendation(beef_recommendation, lamb_recommendation, pork_recommendation, chicken_recommendation,
fish_recommendation, cheese_recommendation, milk_recommendation, food_waste_recommendation)
Expand Down
22 changes: 13 additions & 9 deletions backend/models/transportation.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,35 +126,39 @@ def from_transportation_entry(transportation_entry: TransportationEntry) -> Tran
gasoline_car_carbon_emissions = ((transportation_entry.fuel_efficiency * 2.3)/100) * transportation_entry.gasoline_car

if bus_carbon_emissions > submetric_threshold:
recommendation1 = "Consider walking or biking short distances"
recommendation2 = ""
recommendation3 = ""
recommendation1 = "Consider walking short distances"
recommendation2 = "Consider riding an E-Bike or E-scooter when possible"
recommendation3 = "Consider riding a bicycle when travelling short distances"
recommendations = [recommendation1, recommendation2, recommendation3]
bus_recommendation = random.choice(recommendations)

if train_carbon_emissions > submetric_threshold:
recommendation1 = "Consider walking or biking short distances"
recommendation1 = "Consider walking short distances"
recommendation2 = "Consider local public transport when possible (buses, trams)"
recommendation3 = ""
train_recommendation = "Train emissions too high"
recommendation3 = "Consider riding a bicycle, E-Bike or E-scooter when travelling short distances"
recommendations = [recommendation1, recommendation2, recommendation3]
train_recommendation = random.choice(recommendations)

if motorbike_carbon_emissions > submetric_threshold:
recommendation1 = "Consider walking or biking short distances"
recommendation2 = "Consider taking public transportation more often"
recommendation3 = "Consider carpooling when possible"
motorbike_recommendation = "Motorbike emissions too high"
recommendations = [recommendation1, recommendation2, recommendation3]
motorbike_recommendation = random.choice(recommendations)

if electric_car_carbon_emissions > submetric_threshold:
recommendation1 = "Consider taking public transportation more often"
recommendation2 = "Consider carpooling when possible"
recommendation3 = "Consider walking or biking short distances"
electric_car_recommendation = "Electric car emissions too high"
recommendations = [recommendation1, recommendation2, recommendation3]
electric_car_recommendation = random.choice(recommendations)

if gasoline_car_carbon_emissions > submetric_threshold:
recommendation1 = "Consider taking public transportation more often"
recommendation2 = "Consider carpooling when possible"
recommendation3 = "Consider walking or biking short distances"
gasoline_car_recommendation = "Gasoline car emissions too high"
recommendations = [recommendation1, recommendation2, recommendation3]
gasoline_car_recommendation = random.choice(recommendations)


return TransportationEntryRecommendation(bus_recommendation, train_recommendation,
Expand Down

0 comments on commit 7f69882

Please sign in to comment.