Plot estimated 1 rep max progression for each exercise on dashboard
This commit is contained in:
3
db.py
3
db.py
@@ -226,7 +226,8 @@ class DataBase():
|
||||
E.ExerciseId AS "ExerciseId",
|
||||
E.Name AS "ExerciseName",
|
||||
T.Repetitions AS "Repetitions",
|
||||
T.Weight AS "Weight"
|
||||
T.Weight AS "Weight",
|
||||
round((100 * T.Weight)/(101.3-2.67123 * T.Repetitions),0)::numeric::integer AS "Estimated1RM"
|
||||
FROM Person P
|
||||
LEFT JOIN Workout W ON P.PersonId=W.PersonId
|
||||
LEFT JOIN TopSet T ON W.WorkoutId=T.WorkoutId
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
|
||||
<title>Workout Tracker</title>
|
||||
<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'));
|
||||
})
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
@@ -2,6 +2,17 @@
|
||||
|
||||
{% block content %}
|
||||
|
||||
<script>
|
||||
let layout = {
|
||||
margin: { t: 0 }, xaxis: { type: 'date', showgrid: false }, yaxis: {
|
||||
title: 'Estimated 1RM (kg)',
|
||||
showgrid: false
|
||||
}
|
||||
};
|
||||
let config = { responsive: true, displayModeBar: false };
|
||||
let hovertemplate = '<i>Estimated 1RM</i>: <b>%{y}kg</b><br><i>Topset</i>:<b>%{text}</b><br><i>Date</i>: <b>%{x}</b>';
|
||||
</script>
|
||||
|
||||
<div class="w-full grid grid-cols-1 xl:grid-cols-3 2xl:grid-cols-3 gap-4">
|
||||
{% for p in model %}
|
||||
<div class="bg-white shadow rounded-lg p-4 sm:p-6 xl:p-8 ">
|
||||
@@ -23,6 +34,16 @@
|
||||
<div class="align-middle inline-block min-w-full">
|
||||
<div class="shadow overflow-hidden sm:rounded-lg">
|
||||
<h4 class="text-l font-semibold text-blue-400 mb-2 text-center">{{ e['ExerciseName'] }}</h4>
|
||||
<div id="person-{{ p['PersonId'] }}-exercise-{{ e['ExerciseId'] }}"
|
||||
class="w-full mt-2 aspect-video"></div>
|
||||
<script>
|
||||
Plotly.newPlot(document.getElementById("person-{{ p['PersonId'] }}-exercise-{{ e['ExerciseId'] }}"), [{
|
||||
x: {{ e['EstimatedOneRepMaxProgressions']['StartDates'] | replace('"', "'") | safe }},
|
||||
y: {{ e['EstimatedOneRepMaxProgressions']['Estimated1RMs'] | replace('"', "'") | safe }},
|
||||
text: {{ e['EstimatedOneRepMaxProgressions']['TopSets'] | replace('"', "'") | safe }},
|
||||
hovertemplate
|
||||
}], layout, config);
|
||||
</script>
|
||||
<table class="min-w-full divide-y divide-gray-200">
|
||||
<thead class="bg-gray-50">
|
||||
<tr>
|
||||
|
||||
11
utils.py
11
utils.py
@@ -1,4 +1,5 @@
|
||||
from datetime import datetime
|
||||
import json
|
||||
|
||||
|
||||
def get_workouts(topsets):
|
||||
@@ -48,17 +49,23 @@ def get_rep_maxes_for_person(person_topsets):
|
||||
topsets_for_exercise.append({
|
||||
'StartDate': max_topset_for_rep[0]['StartDate'],
|
||||
'Repetitions': rep,
|
||||
'Weight': max_weight
|
||||
'Weight': max_weight,
|
||||
'Estimated1RM': max_topset_for_rep[0]['Estimated1RM'],
|
||||
})
|
||||
|
||||
# datetime.strptime(x['StartDate'], "%Y-%m-%d")
|
||||
topsets_for_exercise.sort(
|
||||
key=lambda x: x['StartDate'], reverse=True)
|
||||
key=lambda x: x['Repetitions'], reverse=True)
|
||||
|
||||
rep_maxes_in_exercises.append({
|
||||
'ExerciseId': e['ExerciseId'],
|
||||
'ExerciseName': e['ExerciseName'],
|
||||
'RepMaxes': topsets_for_exercise,
|
||||
'EstimatedOneRepMaxProgressions': {
|
||||
'StartDates': json.dumps([t['StartDate'] for t in exercise_topsets]),
|
||||
'TopSets': json.dumps([f"{t['Repetitions']} x {t['Weight']}kg" for t in exercise_topsets]),
|
||||
'Estimated1RMs': json.dumps([t['Estimated1RM'] for t in exercise_topsets]),
|
||||
}
|
||||
})
|
||||
return rep_maxes_in_exercises
|
||||
|
||||
|
||||
Reference in New Issue
Block a user