Skip to content

Commit

Permalink
Merge pull request #57 from utmgdsc/feature/recommendation-messages
Browse files Browse the repository at this point in the history
Recommendation Messages
  • Loading branch information
IshavSohal authored Dec 18, 2023
2 parents eff7ac2 + efcb8e7 commit 71c3044
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 56 deletions.
28 changes: 20 additions & 8 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 All @@ -22,7 +23,6 @@ class EnergyEntry(CARBON_MODEL):
electricity: int # measured in kWh
province: str
household: int
metric_threshold = 200/3

def __init__(self, oid: ObjectId, user_id: ObjectId, carbon_emissions: int, date: Union[str, datetime],
heating_oil: int, natural_gas: int, province: str, household: int, electricity: int) -> None:
Expand Down Expand Up @@ -127,10 +127,10 @@ def from_json(doc: json) -> EnergyEntryRecommendation:

@staticmethod
def from_energy_entry(energy_entry: EnergyEntry) -> EnergyEntryRecommendation:
submetric_threshold = EnergyEntry.metric_threshold/3
heating_oil_recommendation = "Heating oil emissions look good!"
natural_gas_recommendation = "Natural gas emissions look good!"
electricity_recommendation = "Electricity emissions look good!"
submetric_threshold = 11
heating_oil_recommendation = "Looking good!"
natural_gas_recommendation = "Looking good!"
electricity_recommendation = "Looking good!"

heating_oil_carbon_emissions = energy_entry.heating_oil * 2.753
natural_gas_carbon_emissions = energy_entry.natural_gas * 1.96
Expand Down Expand Up @@ -166,13 +166,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:
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:
natural_gas_recommendation = "Natural gas emissions too high"
recommendation1 = "Consider replacing natural gas heating systems with electric 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:
electricity_recommendation = "Electricity emissions too high"
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"
recommendations = [recommendation1, recommendation2, recommendation3]
electricity_recommendation = random.choice(recommendations)

return EnergyEntryRecommendation(heating_oil_recommendation, natural_gas_recommendation, electricity_recommendation)

Expand Down
103 changes: 69 additions & 34 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 All @@ -25,7 +26,7 @@ class FoodEntry(CARBON_MODEL):
cheese: int
milk: int
food_waste: int
metric_threshold = 200 / 3


# food measurements in # of 100g servings
def __init__(self, oid: ObjectId, user_id: ObjectId, carbon_emissions: int, date: Union[str, datetime],
Expand Down Expand Up @@ -75,14 +76,14 @@ def from_json(doc: json) -> FoodEntry:
)

def calculate_carbon_emissions(self) -> float:
beef_carbon_emissions = self.beef * 15.5
lamb_carbon_emissions = self.lamb * 5.84
pork_carbon_emissions = self.pork * 2.4
chicken_carbon_emissions = self.chicken * 1.8
fish_carbon_emissions = self.fish * 1.8
cheese_carbon_emissions = self.cheese * 2.79
beef_carbon_emissions = self.beef * 9.9
lamb_carbon_emissions = self.lamb * 3.9
pork_carbon_emissions = self.pork * 1.2
chicken_carbon_emissions = self.chicken * 0.98
fish_carbon_emissions = self.fish * 1.3
cheese_carbon_emissions = self.cheese * 2.3
milk_carbon_emissions = self.milk * 0.8
food_waste_carbon_emissions = self.food_waste * 0.25
food_waste_carbon_emissions = self.food_waste * 0.0025
return sum([beef_carbon_emissions, lamb_carbon_emissions, pork_carbon_emissions,
chicken_carbon_emissions, fish_carbon_emissions, cheese_carbon_emissions,
milk_carbon_emissions, food_waste_carbon_emissions])
Expand All @@ -91,6 +92,7 @@ def __repr__(self) -> str:
return f'Food ID: {self.oid.__str__()}'



class FoodEntryRecommendation(DB_MODEL):
beef_recommendation: str
lamb_recommendation: str
Expand Down Expand Up @@ -142,48 +144,81 @@ def from_json(doc: json) -> FoodEntryRecommendation:

@staticmethod
def from_food_entry(food_entry: FoodEntry) -> FoodEntryRecommendation:
submetric_threshold = FoodEntry.metric_threshold / 8
beef_recommendation = "Beef emissions look good!"
lamb_recommendation = "Lamb emissions look good!"
pork_recommendation = "Pork emissions look good!"
chicken_recommendation = "Chicken emissions look good!"
fish_recommendation = "Fish emissions look good!"
cheese_recommendation = "Cheese emissions look good!"
milk_recommendation = "Milk emissions look good!"
food_waste_recommendation = "Food waste emissions look good!"

beef_carbon_emissions = food_entry.beef * 15.5
lamb_carbon_emissions = food_entry.lamb * 5.84
pork_carbon_emissions = food_entry.pork * 2.4
chicken_carbon_emissions = food_entry.chicken * 1.8
fish_carbon_emissions = food_entry.fish * 1.8
cheese_carbon_emissions = food_entry.cheese * 2.79
submetric_threshold = 11
beef_recommendation = "Looking good!"
lamb_recommendation = "Looking good!"
pork_recommendation = "Looking good!"
chicken_recommendation = "Looking good!"
fish_recommendation = "Looking good!"
cheese_recommendation = "Looking good!"
milk_recommendation = "Looking good!"
food_waste_recommendation = "Looking good!"

beef_carbon_emissions = food_entry.beef * 9.9
lamb_carbon_emissions = food_entry.lamb * 3.9
pork_carbon_emissions = food_entry.pork * 1.2
chicken_carbon_emissions = food_entry.chicken * 0.98
fish_carbon_emissions = food_entry.fish * 1.3
cheese_carbon_emissions = food_entry.cheese * 2.3

milk_carbon_emissions = food_entry.milk * 0.8
food_waste_carbon_emissions = food_entry.food_waste * 0.25
food_waste_carbon_emissions = food_entry.food_waste * 0.0025

if beef_carbon_emissions > submetric_threshold:
beef_recommendation = "Beef emissions too high"
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"
recommendations = [recommendation1, recommendation2, recommendation3]
beef_recommendation = random.choice(recommendations)

if lamb_carbon_emissions > submetric_threshold:
lamb_recommendation = "Lamb emissions too high"

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"
recommendations = [recommendation1, recommendation2, recommendation3]
lamb_recommendation = random.choice(recommendations)

if pork_carbon_emissions > submetric_threshold:
pork_recommendation = "Pork emissions too high"
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"
recommendations = [recommendation1, recommendation2, recommendation3]
pork_recommendation = random.choice(recommendations)

if chicken_carbon_emissions > submetric_threshold:
chicken_recommendation = "Chicken emissions too high"
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"
recommendations = [recommendation1, recommendation2, recommendation3]
chicken_recommendation = random.choice(recommendations)

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

if cheese_carbon_emissions > submetric_threshold:
cheese_recommendation = "Cheese emissions too high"
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.)"
recommendations = [recommendation1, recommendation2, recommendation3]
cheese_recommendation = random.choice(recommendations)

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

if food_waste_carbon_emissions > submetric_threshold:
food_waste_recommendation = "Food waste emissions too high"
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."
recommendations = [recommendation1, recommendation2, recommendation3]
food_waste_recommendation = random.choice(recommendations)

return FoodEntryRecommendation(beef_recommendation, lamb_recommendation, pork_recommendation, chicken_recommendation,
fish_recommendation, cheese_recommendation, milk_recommendation, food_waste_recommendation)
Expand Down
47 changes: 33 additions & 14 deletions backend/models/transportation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import annotations
from typing import Union
import json
import random
from datetime import datetime
from models.abstract_carbon_model import CARBON_MODEL
from models.abstract_db_model import DB_MODEL
Expand All @@ -21,8 +22,7 @@ class TransportationEntry(CARBON_MODEL):
motorbike: int
electric_car: int
gasoline_car: int
fuel_efficiency: float
metric_threshold = 200 / 3
fuel_efficieny: float

def __init__(self, oid: ObjectId, user_id: ObjectId, carbon_emissions: int, date: Union[str, datetime],
bus: int, train: int, motorbike: int, electric_car: int, gasoline_car: int, fuel_efficiency: float) -> None:
Expand Down Expand Up @@ -82,7 +82,6 @@ class TransportationEntryRecommendation(DB_MODEL):
motorbike_recommendation: str
electric_car_recommendation: str
gasoline_car_recommendation: str
metric_threshold: int

def __init__(self, bus_recommendation: str, train_recommendation: str, motorbike_recommendation: str,
electric_car_recommendation: str, gasoline_car_recommendation: str) -> None:
Expand Down Expand Up @@ -114,12 +113,12 @@ def from_json(doc: json) -> TransportationEntryRecommendation:

@staticmethod
def from_transportation_entry(transportation_entry: TransportationEntry) -> TransportationEntryRecommendation:
submetric_threshold = TransportationEntry.metric_threshold / 5
bus_recommendation = "Bus emissions look good!"
train_recommendation = "Train emissions look good!"
motorbike_recommendation = "Motorbike emissions look good!"
electric_car_recommendation = "Electric car emissions look good!"
gasoline_car_recommendation = "Gasoline emissions look good!"
submetric_threshold = 11
bus_recommendation = "Looking good!"
train_recommendation = "Looking good!"
motorbike_recommendation = "Looking good!"
electric_car_recommendation = "Looking good!"
gasoline_car_recommendation = "Looking good!"

bus_carbon_emissions = transportation_entry.bus * 0.103
train_carbon_emissions = transportation_entry.train * 0.037
Expand All @@ -128,19 +127,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:
bus_recommendation = "Bus emissions too high"
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:
train_recommendation = "Train emissions too high"
recommendation1 = "Consider walking short distances"
recommendation2 = "Consider local public transport when possible (buses, trams)"
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:
motorbike_recommendation = "Motorbike emissions too high"
recommendation1 = "Consider walking or biking short distances"
recommendation2 = "Consider taking public transportation more often"
recommendation3 = "Consider carpooling when possible"
recommendations = [recommendation1, recommendation2, recommendation3]
motorbike_recommendation = random.choice(recommendations)

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

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

return TransportationEntryRecommendation(bus_recommendation, train_recommendation,
motorbike_recommendation, electric_car_recommendation, gasoline_car_recommendation)
Expand Down

0 comments on commit 71c3044

Please sign in to comment.