From 118a715609bb68c02909ac436861745fb873ccc1 Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Sat, 17 Sep 2022 22:39:39 +1000 Subject: [PATCH] Change date format and order list of users by age of account --- db.py | 6 ++++-- templates/base.html | 6 ++++-- templates/index.html | 1 + utils.py | 4 ++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/db.py b/db.py index e5119cf..b18a555 100644 --- a/db.py +++ b/db.py @@ -1,7 +1,7 @@ import os import psycopg2 from psycopg2.extras import RealDictCursor -import datetime +from datetime import datetime from urllib.parse import urlparse from utils import get_all_exercises_from_topsets, get_people_and_exercise_rep_maxes, get_workouts @@ -120,6 +120,8 @@ class DataBase(): FROM Person P LEFT JOIN Workout W ON P.PersonId = W.PersonId GROUP BY + P.PersonId + ORDER BY P.PersonId""", [person_id]) def get_person_final(self, person_id): @@ -170,7 +172,7 @@ class DataBase(): 'PersonId': next((t['PersonId'] for t in topsets), -1), 'PersonName': next((t['PersonName'] for t in topsets), 'Unknown'), 'WorkoutId': workout_id, - 'StartDate': next((t['StartDate'] for t in topsets), 'Unknown'), + 'StartDate': datetime.strptime(topsets[0]['StartDate'], "%Y-%m-%d").strftime("%b %d %Y"), 'Exercises': self.get_exercises(), 'TopSets': [{"TopSetId": t['TopSetId'], "ExerciseId": t['ExerciseId'], "ExerciseName": t['ExerciseName'], "Weight": t['Weight'], "Repetitions": t['Repetitions']} for t in topsets if t['TopSetId'] is not None] } diff --git a/templates/base.html b/templates/base.html index c6a39d1..3199176 100644 --- a/templates/base.html +++ b/templates/base.html @@ -9,8 +9,10 @@ diff --git a/templates/index.html b/templates/index.html index 15dbb62..914aba7 100644 --- a/templates/index.html +++ b/templates/index.html @@ -41,6 +41,7 @@ x: {{ e['EstimatedOneRepMaxProgressions']['StartDates'] | replace('"', "'") | safe }}, y: {{ e['EstimatedOneRepMaxProgressions']['Estimated1RMs'] | replace('"', "'") | safe }}, text: {{ e['EstimatedOneRepMaxProgressions']['TopSets'] | replace('"', "'") | safe }}, + name: "{{ p['PersonName'] }} - {{ e['ExerciseName'] }}", hovertemplate }], layout, config); diff --git a/utils.py b/utils.py index 7cda24e..c1af6ec 100644 --- a/utils.py +++ b/utils.py @@ -14,7 +14,7 @@ def get_workouts(topsets): t for t in topsets if t['WorkoutId'] == workout_id] workouts.append({ 'WorkoutId': workout_id, - 'StartDate': topsets_in_workout[0]['StartDate'], + 'StartDate': datetime.strptime(topsets_in_workout[0]['StartDate'], "%Y-%m-%d").strftime("%b %d %Y"), 'TopSets': [{"TopSetId": t['TopSetId'], "ExerciseId": t['ExerciseId'], "ExerciseName": t['ExerciseName'], "Weight": t['Weight'], "Repetitions": t['Repetitions']} for t in topsets_in_workout] }) return workouts @@ -47,7 +47,7 @@ def get_rep_maxes_for_person(person_topsets): max_weight = max([t['Weight'] for t in reps]) max_topset_for_rep = [t for t in reps if t['Weight'] == max_weight] topsets_for_exercise.append({ - 'StartDate': max_topset_for_rep[0]['StartDate'], + 'StartDate': datetime.strptime(max_topset_for_rep[0]['StartDate'], "%Y-%m-%d").strftime("%b %d %Y"), 'Repetitions': rep, 'Weight': max_weight, 'Estimated1RM': max_topset_for_rep[0]['Estimated1RM'],