Skip to content

Commit 10f4832

Browse files
committed
sustainability changes
1 parent 117cd60 commit 10f4832

File tree

2 files changed

+13
-24
lines changed

2 files changed

+13
-24
lines changed

client/src/SelectRoute.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export default function SelectRouteScreen({ navigation, route }) {
122122
for (let i = 0; i < routeData.routes.length; i += 1) {
123123
setScores((prevScores) => [
124124
...prevScores,
125-
getSustainabilityScore(i, false, ''),
125+
getSustainabilityScore(i, false, '')
126126
]);
127127
}
128128
// eslint-disable-next-line react-hooks/exhaustive-deps

server/src/sustainability.py

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ async def update_sus_stats(
124124
self.update_user_sus_score(username)
125125

126126
journeyData.pop("car", None)
127-
return self.calc_scores_from_route(username, journeyData)
127+
return self.calc_scores_from_route(journeyData)
128128

129129
def db_fetch_month_sus_stats(self, user):
130130
table_name = "monthly_distance"
@@ -312,34 +312,23 @@ def calc_scores(self, emissions_difference: float) -> float:
312312

313313
return round(emissions_difference / 1000, 2)
314314

315-
def calc_scores_from_route(self, user, journey_data):
316-
table_name = "monthly_distance"
317-
db = DataBase()
318-
db.connect_db()
315+
def calc_scores_from_route(self, journey_data):
319316

320317
calc_emissions_savings = self.calc_emissions_savings(journey_data)
321318
transport_score = 0
322319

323-
# If user found
324-
if db.search_user(table_name, user):
325-
self.logger.info("Found user")
326-
for transport_mode in journey_data:
327-
if transport_mode not in self.vehicle_types:
328-
self.logger.error(
329-
f"Invalid transport mode: {transport_mode}"
330-
)
331-
continue
332-
333-
transport_score += self.calc_scores(
334-
calc_emissions_savings[transport_mode]
320+
for transport_mode in journey_data:
321+
if transport_mode not in self.vehicle_types:
322+
self.logger.error(
323+
f"Invalid transport mode: {transport_mode}"
335324
)
336-
db.close_con()
337-
return transport_score
325+
continue
326+
327+
transport_score += self.calc_scores(
328+
calc_emissions_savings[transport_mode]
329+
)
330+
return transport_score
338331

339-
else:
340-
db.close_con()
341-
print("Monthly distances not found")
342-
return 0
343332

344333
def update_user_sus_score(self, user: str) -> float:
345334
db = DataBase()

0 commit comments

Comments
 (0)