From 76331086c168b7b14f3eb48d3424d04a7196889d Mon Sep 17 00:00:00 2001 From: Greg V Date: Tue, 15 Oct 2024 08:28:43 -0700 Subject: [PATCH] /volunteer/track - update to show committeed and active time tracking --- .vscode/settings.json | 22 +++++++++++++++++++++- api/messages/messages_service.py | 2 +- api/users/users_views.py | 11 ++++++----- services/users_service.py | 26 +++++++++++++++++++++----- 4 files changed, 49 insertions(+), 12 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index d220a10..3713422 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,5 +3,25 @@ "develop" ], "terminal.integrated.defaultProfile.osx": "x86 bash", - "python.defaultInterpreterPath": "/opt/miniconda3/envs/ohack/bin/python3.9" + "python.defaultInterpreterPath": "/opt/miniconda3/envs/ohack/bin/python3.9", + "workbench.colorCustomizations": { + "activityBar.activeBackground": "#93e6fc", + "activityBar.background": "#93e6fc", + "activityBar.foreground": "#15202b", + "activityBar.inactiveForeground": "#15202b99", + "activityBarBadge.background": "#fa45d4", + "activityBarBadge.foreground": "#15202b", + "commandCenter.border": "#15202b99", + "sash.hoverBorder": "#93e6fc", + "statusBar.background": "#61dafb", + "statusBar.foreground": "#15202b", + "statusBarItem.hoverBackground": "#2fcefa", + "statusBarItem.remoteBackground": "#61dafb", + "statusBarItem.remoteForeground": "#15202b", + "titleBar.activeBackground": "#61dafb", + "titleBar.activeForeground": "#15202b", + "titleBar.inactiveBackground": "#61dafb99", + "titleBar.inactiveForeground": "#15202b99" + }, + "peacock.color": "#61dafb" } \ No newline at end of file diff --git a/api/messages/messages_service.py b/api/messages/messages_service.py index 7ccc11e..13fba27 100644 --- a/api/messages/messages_service.py +++ b/api/messages/messages_service.py @@ -1812,7 +1812,7 @@ def get_problem_statement_list_old(): logger.debug(results) return { "problem_statements": results } -@cached(cache=TTLCache(maxsize=100, ttl=600)) +@cached(cache=TTLCache(maxsize=100, ttl=10)) @limits(calls=100, period=ONE_MINUTE) def get_github_profile(github_username): logger.debug(f"Getting Github Profile for {github_username}") diff --git a/api/users/users_views.py b/api/users/users_views.py index 6f5ecbd..7f96951 100644 --- a/api/users/users_views.py +++ b/api/users/users_views.py @@ -59,14 +59,15 @@ def save_volunteering_time(): @auth.require_user def get_volunteering_time(): # Get url params - start_date = request.args.get('start_date') - end_date = request.args.get('end_date') + start_date = request.args.get('startDate') + end_date = request.args.get('endDate') if auth_user and auth_user.user_id: - volunteering, total = users_service.get_volunteering_time(auth_user.user_id, start_date, end_date) + allVolunteering, totalActiveHours, totalCommitmentHours = users_service.get_volunteering_time(auth_user.user_id, start_date, end_date) return { - "totalHours": total, - "volunteering": volunteering + "totalActiveHours": totalActiveHours, + "totalCommitmentHours": totalCommitmentHours, + "allVolunteering": allVolunteering } else: return None diff --git a/services/users_service.py b/services/users_service.py index 6f758a1..2fa4c76 100644 --- a/services/users_service.py +++ b/services/users_service.py @@ -334,15 +334,31 @@ def get_volunteering_time(propel_id, start_date, end_date): return # Filter the volunteering data - volunteering = [] + volunteeringActiveTime = [] for v in user.volunteering: if "finalHours" in v: if start_date is not None and end_date is not None: if v["timestamp"] >= start_date and v["timestamp"] <= end_date: - volunteering.append(v) + volunteeringActiveTime.append(v) else: - volunteering.append(v) + volunteeringActiveTime.append(v) + + volunteeringCommittmentTime = [] + for v in user.volunteering: + if "commitmentHours" in v: + if start_date is not None and end_date is not None: + if v["timestamp"] >= start_date and v["timestamp"] <= end_date: + volunteeringCommittmentTime.append(v) + else: + volunteeringCommittmentTime.append(v) - total = sum([v["finalHours"] for v in volunteering]) + totalActiveHours = sum([v["finalHours"] for v in volunteeringActiveTime]) + totalCommitmentHours = sum([v["commitmentHours"] for v in volunteeringCommittmentTime]) + + # Merge volunteeringActiveTime and volunteeringCommittmentTime + # This is a bit of a hack but it is easier to do it this way than to try to do it in the frontend + allVolunteering = volunteeringActiveTime + volunteeringCommittmentTime + + logger.debug(f"allVolunteering: {allVolunteering} || volunteeringActiveTime: {volunteeringActiveTime} volunteeringCommittmentTime: {volunteeringCommittmentTime} Total Active Hours: {totalActiveHours} Total Commitment Hours: {totalCommitmentHours}") - return volunteering, total \ No newline at end of file + return allVolunteering, totalActiveHours, totalCommitmentHours \ No newline at end of file