Skip to content

Commit

Permalink
Merge pull request #61 from utmgdsc/feature/deploy_to_app_store
Browse files Browse the repository at this point in the history
Feature/deploy to app store
  • Loading branch information
Yazan10x authored Jan 8, 2024
2 parents 2750b16 + 9a3c067 commit ba7d68d
Show file tree
Hide file tree
Showing 15 changed files with 119 additions and 42 deletions.
2 changes: 1 addition & 1 deletion backend/models/energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def calculate_carbon_emissions(self) -> float:
electricity_carbon_emissions = (self.electricity * 0.17) / self.household
else: # self.province == "Nunavut"
electricity_carbon_emissions = (self.electricity * 0.84) / self.household
return sum([heating_oil_carbon_emissions, natural_gas_carbon_emissions, electricity_carbon_emissions])
return int(sum([heating_oil_carbon_emissions, natural_gas_carbon_emissions, electricity_carbon_emissions]))

def __repr__(self) -> str:
return f'Energy ID: {self.oid.__str__()}'
Expand Down
10 changes: 4 additions & 6 deletions backend/models/food.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class FoodEntry(CARBON_MODEL):
milk: int
food_waste: int


# food measurements in # of 100g servings
def __init__(self, oid: ObjectId, user_id: ObjectId, carbon_emissions: int, date: Union[str, datetime],
beef: int, lamb: int, pork: int, chicken: int, fish: int, cheese: int, milk: int,
Expand Down Expand Up @@ -84,15 +83,14 @@ def calculate_carbon_emissions(self) -> float:
cheese_carbon_emissions = self.cheese * 2.3
milk_carbon_emissions = self.milk * 0.8
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])
return int(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]))

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 @@ -177,7 +175,7 @@ def from_food_entry(food_entry: FoodEntry) -> FoodEntryRecommendation:
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:
recommendation1 = "Try opting for white meat (fish, chicken, etc.)"
recommendation2 = "Consider alternate forms of protein (chicken, fish, eggs, etc.)"
Expand Down
33 changes: 30 additions & 3 deletions backend/postman/Backend.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,41 @@
}
},
"url": {
"raw": "{{LocalBaseURL}}/users/user_email/yazan@gmail.com",
"raw": "{{LocalBaseURL}}/users/user_email/yazan@armoush.ca",
"host": [
"{{LocalBaseURL}}"
],
"path": [
"users",
"user_email",
"[email protected]"
"[email protected]"
]
}
},
"response": []
},
{
"name": "Get Top Users",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"count\": 3\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{LocalBaseURL}}/users/get_top_users",
"host": [
"{{LocalBaseURL}}"
],
"path": [
"users",
"get_top_users"
]
}
},
Expand Down Expand Up @@ -586,7 +613,7 @@
"bearer": [
{
"key": "token",
"value": "eyJhbGciOiJSUzI1NiIsImtpZCI6IjBiYmQyOTllODU2MmU3MmYyZThkN2YwMTliYTdiZjAxMWFlZjU1Y2EiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL3NlY3VyZXRva2VuLmdvb2dsZS5jb20vY2FyYm9uLXRyYWNrLXN5c3RlbSIsImF1ZCI6ImNhcmJvbi10cmFjay1zeXN0ZW0iLCJhdXRoX3RpbWUiOjE3MDExMjc0NTAsInVzZXJfaWQiOiJ3UFVEaEFiM0Q5ZHpoeDJXa1RBZlBLbnhGSG0xIiwic3ViIjoid1BVRGhBYjNEOWR6aHgyV2tUQWZQS254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pcmViYXNlIjp7ImlkZW50aXRpZXMiOnsiZW1haWwiOlsiYWhtYWRAYXJtb3VzaC5jYSJdfSwic2lnbl9pbl9wcm92aWRlciI6InBhc3N3b3JkIn19.FW2RaJ4OR5FhyKvsTgxTPJoRvPOyIYRwwOl6aqKIzFEdu1k6R48nBHrIJcKYc3HYNKX_czgFfboeTOQNO3Jb5B3sWDO81awn1xa4dySKOa24DUr71EkVdUlGgB38TjhLZiyweuMGg0e6pLu4OqSXu3MRg-91LzHS3hA2L7X-TOfhCS7zoLS7hAJi5X_NHmD5PIOiRwSqvzyQq7jd6HJ4r2ukiIsz8YKP4zKWNNwFPrpMLc_D0SzgE7-DXGe17B2NH2H2IhYpKCuY0iRSV6zXWqk5E3RET98VNuVFBUQDjRf9mlBnPEtqC0nZTNYDFU_qAMgk6G0XtGVM3IIanCBjWw",
"type": "string"
}
]
Expand Down
26 changes: 15 additions & 11 deletions backend/routes/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@carbon_auth.auth.login_required
def get_user(user_id: str) -> Response:
try:
query = {"_id": ObjectId(user_id)}
query = {"_id": ObjectId(user_id), "archived": False}
item = CarbonTrackDB.users_coll.find_one(query)
item = User.from_json(item).to_json()
return jsonify({"user": item})
Expand All @@ -31,7 +31,7 @@ def get_top_users() -> Response:

# Monthly
_top_monthly_users = (
CarbonTrackDB.users_coll.find().sort("monthly_score", -1).limit(count)
CarbonTrackDB.users_coll.find({"archived": False}).sort("monthly_score", -1).limit(count)
)
top_monthly_users = []
rank = 1
Expand Down Expand Up @@ -96,7 +96,7 @@ def get_top_users() -> Response:
@carbon_auth.auth.login_required
def get_user_by_email(user_email: str) -> Response:
try:
query = {"email": user_email}
query = {"email": user_email, "archived": False}
item = CarbonTrackDB.users_coll.find_one(query)
item = User.from_json(item).to_json()
return jsonify({"user": item})
Expand All @@ -113,7 +113,7 @@ def get_current_user() -> Response:
print(current_user)

# Construct the query to find the user in MongoDB
query = {"uid": current_user["uid"]}
query = {"uid": current_user["uid"], "archived": False}

# Fetch user data from MongoDB
mongo_user = CarbonTrackDB.users_coll.find_one(query)
Expand Down Expand Up @@ -160,11 +160,15 @@ def create_user() -> Response:
@carbon_auth.auth.login_required
def delete_user(user_id: str) -> Response:
try:
query = {"_id": ObjectId(user_id)}
query = {"_id": ObjectId(user_id), "archived": False}
item = CarbonTrackDB.users_coll.find_one(query)
item = User.from_json(item).to_json()
CarbonTrackDB.users_coll.delete_one(query)
return jsonify({"deleted user": item})
item = User.from_json(item)
CarbonTrackDB.users_coll.update_one(query, {
'$set': {
'archived': True
}
})
return jsonify({"user": item})
except CarbonTrackError as e:
abort(code=400, description=f"{e}")

Expand All @@ -173,7 +177,7 @@ def delete_user(user_id: str) -> Response:
@carbon_auth.auth.login_required
def update_user(user_id: str) -> Response:
try:
query = {"_id": ObjectId(user_id)}
query = {"_id": ObjectId(user_id), "archived": False}
user = User.from_json(request.get_json()["user"]).to_json()
del user["_id"]
del user["email"]
Expand All @@ -189,7 +193,7 @@ def update_user(user_id: str) -> Response:
@carbon_auth.auth.login_required
def update_user_email(uid: str) -> Response:
try:
query = {"uid": uid}
query = {"uid": uid, "archived": False}
new_email = request.get_json().get("email", "")

current_user = carbon_auth.auth.current_user()
Expand All @@ -212,7 +216,7 @@ def update_user_name(user_id: str) -> Response:
try:
new_name = request.get_json().get("newName", "")

query = {"uid": user_id}
query = {"uid": user_id, "archived": False}

current_user = carbon_auth.auth.current_user()
print(current_user)
Expand Down
16 changes: 10 additions & 6 deletions frontend/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
"expo": {
"plugins": [
[
"expo-image-picker",
"expo-build-properties",
{
"photosPermission": "The app accesses your photos to let you share them with your friends."
"ios": {
"useFrameworks": "static"
}
}
]
],
"name": "CarbonTrack",
"name": "CarbonTrack for Individuals",
"slug": "CarbonTrack",
"version": "1.0.0",
"version": "1.0.2",
"orientation": "portrait",
"icon": "./assets/icon.png",
"userInterfaceStyle": "light",
Expand All @@ -23,15 +25,17 @@
"**/*"
],
"ios": {
"supportsTablet": true
"supportsTablet": true,
"bundleIdentifier": "club.usec.carbontrack"
},
"android": {
"adaptiveIcon": {
"backgroundColor": "#243E36"
},
"permissions": [
"android.permission.RECORD_AUDIO"
]
],
"package": "com.carbontrack.usec"
},
"web": {
"favicon": "./assets/favicon.png"
Expand Down
Binary file modified frontend/assets/adaptive-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions frontend/eas.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"cli": {
"version": ">= 5.9.2"
},
"build": {
"development": {
"developmentClient": true,
"distribution": "internal"
},
"preview": {
"distribution": "internal"
},
"production": {}
},
"submit": {
"production": {}
}
}
3 changes: 2 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@react-native-community/slider": "^4.4.2",
"@react-native-firebase/app": "^18.7.1",
"@react-native-firebase/auth": "^18.7.1",
"@react-native-firebase/firestore": "^18.6.0",
"@react-native-firebase/firestore": "^18.7.1",
"@react-native-firebase/storage": "^18.7.1",
"@react-native-picker/picker": "^2.5.1",
"@react-navigation/bottom-tabs": "^6.5.11",
Expand All @@ -28,6 +28,7 @@
"bson-objectid": "^2.0.4",
"events": "^3.3.0",
"expo": "~49.0.12",
"expo-build-properties": "^0.8.3",
"expo-cli": "6.3.10",
"expo-font": "~11.4.0",
"expo-image-picker": "~14.3.2",
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/APIs/UsersAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ export const UsersAPI = {
}
},

deleteUser: async (userID: ObjectId) => {
try {
const res = await FLASK_HTTPS.delete(routeName + '/user/' + userID.toString());
return res.data.user as User;
} catch (error) {
console.error('Error fetching user from Flask BE: ', error);
return undefined;
}
},

getTopUsers: async (count: number) => {
try {
const res = await FLASK_HTTPS.post(routeName + '/get_top_users', {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/appNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import DashBoardScreen from '../screens/dashboard';
import CommunityHub from '../screens/communityHub';
import FootprintDecomp from '../screens/footpringDecomp';

import SettingsScreen from '../screens/settings';
import SettingsScreen from '../screens/settings/settings';
import UpdatePasswordScreen from '../screens/settings/updatePassword';
import UpdateProfileScreen from '../screens/settings/updateProfile';
import UpdateHomeScreen from '../screens/settings/updateHomeScreen';
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/screens/Energy/energyHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function EnergyHistory(): JSX.Element {
const [expandedStates, setExpandedStates] = useState(Array(100).fill(false));
const [monthlyData, setMonthlyData] = useState<MonthlyEntry[]>();
const [startDate] = useState<Date>(new Date(2023, 8, 1));
const [endDate] = useState<Date>(new Date(2023, 11, 31));
const [endDate] = useState<Date>(new Date(2024, 3, 30));
const navigation = useNavigation<StackNavigation>();
const [energyEntry, setEnergyEntry] = useState<EnergyEntry>();
const [recommendationForToday, setRecommendationForToday] = useState<EnergyEntryRecommendation>();
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/screens/Food/foodHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function FoodHistory(): JSX.Element {
const [expandedStates, setExpandedStates] = useState(Array(100).fill(false));
const [monthlyData, setMonthlyData] = useState<MonthlyEntry[]>();
const [startDate] = useState<Date>(new Date(2023, 8, 1));
const [endDate] = useState<Date>(new Date(2023, 11, 31));
const [endDate] = useState<Date>(new Date(2024, 3, 30));
const navigation = useNavigation<StackNavigation>();
const [foodEntry, setFoodEntry] = useState<FoodEntry>();
const [recommendationForToday, setRecommendationForToday] = useState<FoodEntryRecommendation>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function TransportationHistory(): JSX.Element {
const [expandedStates, setExpandedStates] = useState(Array(100).fill(false));
const [monthlyData, setMonthlyData] = useState<MonthlyEntry[]>();
const [startDate] = useState<Date>(new Date(2023, 8, 1));
const [endDate] = useState<Date>(new Date(2023, 11, 31));
const [endDate] = useState<Date>(new Date(2024, 3, 30));
const navigation = useNavigation<StackNavigation>();
const [transportationEntry, setTransportationEntry] = useState<TransportationEntry>();
const [recommendationForToday, setRecommendationForToday] =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React, { useEffect, useState } from 'react';
import { View, Text, StyleSheet, TouchableOpacity} from 'react-native';
import Colors from '../../assets/colorConstants';
import Colors from '../../../assets/colorConstants';
import { useFonts } from 'expo-font';
import {type RootStackParamList} from '../components/types';
import {type RootStackParamList} from '../../components/types';
import type { StackNavigationProp } from '@react-navigation/stack';
import { useNavigation } from '@react-navigation/native';
import { Entypo,FontAwesome, Feather } from '@expo/vector-icons';
import { getAuth, onAuthStateChanged } from 'firebase/auth';
import firebaseService from '../utilities/firebase';
import { UsersAPI } from '../APIs/UsersAPI';
import { type User } from '../models/User';
import firebaseService from '../../utilities/firebase';
import { UsersAPI } from '../../APIs/UsersAPI';
import { type User } from '../../models/User';

export type StackNavigation = StackNavigationProp<RootStackParamList>;
export default function SettingsScreen(): JSX.Element {
Expand All @@ -20,8 +20,8 @@ export default function SettingsScreen(): JSX.Element {


const [loaded] = useFonts({
Montserrat: require('../../assets/fonts/MontserratThinRegular.ttf'),
Josefin: require('../../assets/fonts/JosefinSansThinRegular.ttf'),
Montserrat: require('../../../assets/fonts/MontserratThinRegular.ttf'),
Josefin: require('../../../assets/fonts/JosefinSansThinRegular.ttf'),
});

const auth = getAuth();
Expand Down Expand Up @@ -55,6 +55,21 @@ export default function SettingsScreen(): JSX.Element {

}

const handleDeleteAccount =async ():Promise<void> => {
try{
if (user !== undefined || user != null){
await UsersAPI.deleteUser(user._id);
console.log("User has been deleted!")
navigation.navigate('Home');
}
} catch(error){
console.error("Deleting Account Error:", error)
}

}




if (!loaded) {
return <></>;
Expand Down Expand Up @@ -84,10 +99,10 @@ export default function SettingsScreen(): JSX.Element {
<Feather name="edit-2" size={24} color={Colors.DARKDARKGREEN} style={styles.nextButton}/>
</TouchableOpacity>

<TouchableOpacity style={styles.buttons}>
<TouchableOpacity style={styles.buttons} onPress={() => {void handleDeleteAccount()}}>
<FontAwesome name="universal-access" size={24} color={Colors.DARKDARKGREEN} style={styles.icon} />
<Text style={styles.labels}> Accessibility </Text>
<Feather name="edit-2" size={24} color={Colors.DARKDARKGREEN} style={styles.nextButton}/>
<Text style={styles.labels}> Delete Account </Text>
<Feather name="trash" size={24} color={Colors.DARKDARKGREEN} style={styles.nextButton}/>
</TouchableOpacity>

<TouchableOpacity style={styles.logOutButton} onPress={() => {void handleLogOut()}}>
Expand Down

0 comments on commit ba7d68d

Please sign in to comment.