Skip to content

Commit

Permalink
added additional user attributes, fixed postman collection and energy…
Browse files Browse the repository at this point in the history
… endpoint
  • Loading branch information
IshavSohal committed Nov 27, 2023
1 parent c24ca95 commit 1176ea3
Show file tree
Hide file tree
Showing 5 changed files with 340 additions and 35 deletions.
3 changes: 2 additions & 1 deletion backend/models/energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from bson import ObjectId
from bson import json_util


class EnergyEntry(DB_MODEL):
oid: ObjectId
user_id: ObjectId
Expand Down Expand Up @@ -66,7 +67,7 @@ def calculate_carbon_emissions(self) -> float:
heating_oil_carbon_emissions = self.heating_oil * 2.753
natural_gas_carbon_emissions = self.natural_gas * 1.96

if self.province == "British Colombia":
if self.province == "British Columbia":
electricity_carbon_emissions = (self.electricity * 0.015)/self.household
elif self.province == "Alberta":
electricity_carbon_emissions = (self.electricity * 0.54)/self.household
Expand Down
11 changes: 8 additions & 3 deletions backend/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ class User(DB_MODEL):
score: int
province: str
household: int
fuel_efficiency: float

def __init__(self, oid: ObjectId, full_name: str, email: str, badges: list[str], friends: list[str], score:int, province:str, household:int) -> None:
def __init__(self, oid: ObjectId, full_name: str, email: str, badges: list[str], friends: list[str], score:int, province:str, household:int, fuel_efficiency: float) -> None:
super().__init__(oid)
self.full_name = str(full_name)
self.email = str(email)
Expand All @@ -28,6 +29,7 @@ def __init__(self, oid: ObjectId, full_name: str, email: str, badges: list[str],
self.score = score
self.province = province
self.household = household
self.fuel_efficiency = fuel_efficiency

def to_json(self, for_mongodb: bool = False) -> json:
res = {
Expand All @@ -38,7 +40,8 @@ def to_json(self, for_mongodb: bool = False) -> json:
'friends': self.friends,
'score': self.score,
'province': self.province,
'household': self.household
'household': self.household,
'fuel_efficiency': self.fuel_efficiency
}
if for_mongodb:
return res
Expand All @@ -54,8 +57,10 @@ def from_json(doc: json) -> User:
friends=doc["friends"],
score=doc["score"],
province=doc["province"],
household=doc["household"]
household=doc["household"],
fuel_efficiency=doc["fuel_efficiency"]
)


def __repr__(self) -> str:
return f'User ID: {self.oid.__str__()}'
Loading

0 comments on commit 1176ea3

Please sign in to comment.