Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fixes #47

Merged
merged 3 commits into from
Dec 16, 2023
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
12 changes: 6 additions & 6 deletions backend/routes/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_user(user_id: str) -> Response:
@users.route("/get_top_users", methods=['POST'])
@carbon_auth.auth.login_required
def get_top_users() -> Response:
try:
#try:
count = request.get_json()["count"]

# Monthly
Expand Down Expand Up @@ -78,8 +78,8 @@ def get_top_users() -> Response:
'top_yearly_users': top_yearly_users,
'top_overall_users': top_overall_users,
})
except CarbonTrackError as e:
abort(code=400, description=f"{e}")
#except CarbonTrackError as e:
# abort(code=400, description=f"{e}")


@users.route("/user_email/<user_email>", methods=['GET'])
Expand Down Expand Up @@ -129,7 +129,7 @@ def get_current_user() -> Response:
@users.route("/user", methods=["PUT"])
@carbon_auth.auth.login_required
def create_user() -> Response:
try:
#try:
res: dict = request.get_json()["user"]
user = User.from_json(res)
user.email = user.email.lower()
Expand All @@ -147,8 +147,8 @@ def create_user() -> Response:
return jsonify(
{"error": "User Already Exits With Same Email, Please Log In"}
)
except CarbonTrackError as e:
abort(code=400, description=f"{e}")
# except CarbonTrackError as e:
# abort(code=400, description=f"{e}")


@users.route("/user/<user_id>", methods=["DELETE"])
Expand Down
16 changes: 15 additions & 1 deletion backend/utils/FirebaseAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,21 @@
from models.user import User
from mongodb_api.carbon_track_db import CarbonTrackDB

cred = credentials.Certificate(dict(os.environ))
firebase_cert = {
"type": os.environ.get("type"),
"project_id": os.environ.get("project_id"),
"private_key_id": os.environ.get("private_key_id"),
"private_key": os.environ.get("private_key"),
"client_email": os.environ.get("client_email"),
"client_id": os.environ.get("client_id"),
"auth_uri": os.environ.get("auth_uri"),
"token_uri": os.environ.get("token_uri"),
"auth_provider_x509_cert_url": os.environ.get("auth_provider_x509_cert_url"),
"client_x509_cert_url": os.environ.get("client_x509_cert_url"),
"universe_domain": os.environ.get("universe_domain")
}

cred = credentials.Certificate(firebase_cert)
APP = firebase_admin.initialize_app(cred)


Expand Down
6 changes: 3 additions & 3 deletions frontend/src/APIs/FLASK_API.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from "axios";
import firebaseService from "../utilities/firebase";
const FLASK_LOCAL_ADDRESS: string = "http://10.0.0.72:6050";
import axios from 'axios';
import firebaseService from '../utilities/firebase';
const FLASK_LOCAL_ADDRESS: string = 'http://10.0.0.95:6050';

// Function to get the Firebase authentication token
const getFirebaseAuthToken = async (): Promise<string | null> => {
Expand Down
85 changes: 42 additions & 43 deletions frontend/src/models/User.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,54 @@
import { type ObjectId } from 'mongodb';

export interface User {
_id: ObjectId
uid: string;
full_name: string
email: string
badges: string[]
friends: ObjectId[]
overall_score: number
province: string
household: number
fuel_efficiency: number
photoURL: string;
_id: ObjectId;
uid: string;
full_name: string;
email: string;
badges: string[];
friends: ObjectId[];
monthly_score: number;
yearly_score: number;
overall_score: number;
province: string;
household: number;
fuel_efficiency: number;
photoURL: string;
}


export interface RankUser {
rank: number;
name: string;
footprint: number;
score: number;
}

rank: number;
name: string;
footprint: number;
score: number;
}

export interface TopUsersLists {
top_monthly_users: RankUser[]
top_yearly_users: RankUser[]
top_overall_users: RankUser[]
top_monthly_users: RankUser[];
top_yearly_users: RankUser[];
top_overall_users: RankUser[];
}


export function getUserLevel(score: number): number {
if (score < 250) {
return 1;
} else if (score < 500) {
return 2;
} else if (score < 1000) {
return 3;
} else if (score < 2000) {
return 4;
} else if (score < 4000) {
return 5;
} else if (score < 8000) {
return 6;
} else if (score < 16000) {
return 7;
} else if (score < 32000) {
return 8;
} else if (score < 64000) {
return 9;
} else {
return 10;
}
if (score < 250) {
return 1;
} else if (score < 500) {
return 2;
} else if (score < 1000) {
return 3;
} else if (score < 2000) {
return 4;
} else if (score < 4000) {
return 5;
} else if (score < 8000) {
return 6;
} else if (score < 16000) {
return 7;
} else if (score < 32000) {
return 8;
} else if (score < 64000) {
return 9;
} else {
return 10;
}
}
3 changes: 2 additions & 1 deletion frontend/src/screens/signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export default function SignUp(): JSX.Element {
email,
badges: [],
friends: [],
monthly_score: 0,
yearly_score: 0,
overall_score: 0,
province: '',
household: 0,
Expand All @@ -74,7 +76,6 @@ export default function SignUp(): JSX.Element {
}
} catch (err) {
console.error('[signup.tsx - handleSignUp] User not created in Flask:', err);

}
};

Expand Down