Add options to filter epoch for exercise progress graphs (1M, 3M, 6M, All), however if there isnt data in a selected epoch the endpoint returns 404. Havent bothered to look into to it, probs should clean up code as well

This commit is contained in:
Peter Stockings
2024-04-03 20:31:13 +11:00
parent dae4fcbf44
commit 6dafdf71dd
4 changed files with 37 additions and 7 deletions

12
db.py
View File

@@ -3,6 +3,7 @@ import psycopg2
import numpy as np
from psycopg2.extras import RealDictCursor
from datetime import datetime
from dateutil.relativedelta import relativedelta
from urllib.parse import urlparse
from flask import g
@@ -450,7 +451,14 @@ class DataBase():
'SELECT exercise_id, name FROM exercise')
return exercises
def get_exercise_progress_for_user(self, person_id, exercise_id, min_date=None, max_date=None):
def get_exercise_progress_for_user(self, person_id, exercise_id, min_date=None, max_date=None, epoch='all'):
today = datetime.now()
if epoch == '1M':
min_date = today - relativedelta(months=1)
elif epoch == '3M':
min_date = today - relativedelta(months=3)
elif epoch == '6M':
min_date = today - relativedelta(months=6)
# Execute SQL query to fetch topset data for a specific person and exercise
topsets = self.execute("""
SELECT
@@ -484,7 +492,7 @@ class DataBase():
start_dates = [t['start_date'] for t in topsets]
messages = [f'{t["repetitions"]} x {t["weight"]}kg ({t["estimated_1rm"]}kg E1RM) on {t["start_date"].strftime("%d %b %y")}' for t in topsets]
exercise_progress = get_exercise_graph_model(topsets[0]['exercise_name'], estimated_1rm, repetitions, weight, start_dates, messages)
exercise_progress = get_exercise_graph_model(topsets[0]['exercise_name'], estimated_1rm, repetitions, weight, start_dates, messages, epoch, person_id, exercise_id)
return exercise_progress