Change date format and order list of users by age of account

This commit is contained in:
Peter Stockings
2022-09-17 22:39:39 +10:00
parent 7eaf4f812f
commit 118a715609
4 changed files with 11 additions and 6 deletions

6
db.py
View File

@@ -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]
}

View File

@@ -9,8 +9,10 @@
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.plot.ly/plotly-2.14.0.min.js"></script>
<script>
window.addEventListener('resize', function () {
window.dispatchEvent(new Event('resize'));
let doit;
window.addEventListener('resize', () => {
clearTimeout(doit);
doit = setTimeout(window.dispatchEvent(new Event('resize')), 100);
})
</script>
</head>

View File

@@ -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);
</script>

View File

@@ -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'],