Skip to content

Commit 7586e22

Browse files
committed
sustainability using actual user
1 parent eea114e commit 7586e22

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

client/src/SustainabilityDashboard.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
Text,
1111
} from 'react-native';
1212
import { LineChart, PieChart } from 'react-native-chart-kit';
13+
import { retrieveData } from './caching';
1314
import susDashboardStyles from './components/styles/SustainabilityDashboard.styles';
1415
import fullBloom from './assets/SustainablityDashboard/Rootyfullbloom.png';
1516
import bushy from './assets/SustainablityDashboard/RootyBushy.png';
@@ -182,7 +183,7 @@ export default function Dashboard() {
182183
});
183184

184185
// test name
185-
const senderName = 'Cormac';
186+
// const senderName = 'Cormac';
186187

187188
useEffect(() => {
188189
// eslint-disable-next-line no-use-before-define
@@ -241,6 +242,14 @@ export default function Dashboard() {
241242

242243
const getSustainabilityStats = async () => {
243244
try {
245+
let senderName = await retrieveData('username');
246+
247+
console.log(senderName);
248+
249+
if (senderName == null) {
250+
senderName = 'test_user'; // Default name if not found
251+
}
252+
244253
const baseUrl =
245254
Platform.OS === 'web'
246255
? 'http://localhost:8000'
@@ -259,15 +268,17 @@ export default function Dashboard() {
259268
},
260269
);
261270

271+
console.log('Raw response: ', response);
272+
262273
if (response.ok) {
263274
const serverMessage = await response.json();
264275
console.log('Response from Server: ', serverMessage.message);
265276

266277
const {
267-
emissionsSavings,
268-
currentYearEmissions,
269-
rawDistances,
270-
friendsSusScores,
278+
emissions_savings: emissionsSavings,
279+
current_year_emissions: currentYearEmissions,
280+
raw_distances: rawDistances,
281+
friends_sus_scores: friendsSusScores,
271282
} = serverMessage;
272283

273284
console.log('Emissions savings: ', emissionsSavings);

server/src/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from src.preferences import Preferences
1313
from src.networking import Networking
1414
from src.wayfinding import wayfinding_router_setup
15-
15+
from src.sustainability import Sustainability
1616

1717
class Server:
1818
def __init__(self):
@@ -30,6 +30,7 @@ def __init__(self):
3030
self.weather_api = weatherAPI()
3131
self.networking = Networking(self.app, self.logger)
3232
self.preferences_logic = Preferences(self.app, self.logger)
33+
self.sustainability = Sustainability(self.app, self.logger)
3334
self.signup_logic = Signup(self.app, self.logger,
3435
self.preferences_logic)
3536

server/src/sustainability.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,7 @@ def db_fetch_month_sus_stats(self, user):
6464
db.connect_db()
6565

6666
if db.search_user(table_name, user):
67-
self.logger.info("Found user")
68-
self.logger.info("connection closed, getting monthly distances")
6967
monthly_distances = db.return_user_row(table_name, user)
70-
self.logger.info(f"monthly distances: {monthly_distances}")
7168
db.close_con()
7269
return self.calc_emissions_savings(monthly_distances)
7370

0 commit comments

Comments
 (0)