Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/src/SelectRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export default function SelectRouteScreen({ navigation, route }) {
for (let i = 0; i < routeData.routes.length; i += 1) {
setScores((prevScores) => [
...prevScores,
getSustainabilityScore(i, false, ''),
getSustainabilityScore(i, false, '')
]);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
35 changes: 12 additions & 23 deletions server/src/sustainability.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ async def update_sus_stats(
self.update_user_sus_score(username)

journeyData.pop("car", None)
return self.calc_scores_from_route(username, journeyData)
return self.calc_scores_from_route(journeyData)

def db_fetch_month_sus_stats(self, user):
table_name = "monthly_distance"
Expand Down Expand Up @@ -312,34 +312,23 @@ def calc_scores(self, emissions_difference: float) -> float:

return round(emissions_difference / 1000, 2)

def calc_scores_from_route(self, user, journey_data):
table_name = "monthly_distance"
db = DataBase()
db.connect_db()
def calc_scores_from_route(self, journey_data):

calc_emissions_savings = self.calc_emissions_savings(journey_data)
transport_score = 0

# If user found
if db.search_user(table_name, user):
self.logger.info("Found user")
for transport_mode in journey_data:
if transport_mode not in self.vehicle_types:
self.logger.error(
f"Invalid transport mode: {transport_mode}"
)
continue

transport_score += self.calc_scores(
calc_emissions_savings[transport_mode]
for transport_mode in journey_data:
if transport_mode not in self.vehicle_types:
self.logger.error(
f"Invalid transport mode: {transport_mode}"
)
db.close_con()
return transport_score
continue

transport_score += self.calc_scores(
calc_emissions_savings[transport_mode]
)
return transport_score

else:
db.close_con()
print("Monthly distances not found")
return 0

def update_user_sus_score(self, user: str) -> float:
db = DataBase()
Expand Down
Loading