From ca3eb48da6ff3c31ed86904308a2caed632a476d Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Sun, 2 Apr 2023 23:27:20 +1000 Subject: [PATCH] WIP: Add option to toggle graphs (havent yet added axis filter) --- app.py | 11 +++++++--- db.py | 3 ++- templates/partials/page/person.html | 34 +++++++++++++++++++++++------ templates/person.html | 2 +- 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/app.py b/app.py index a6e9ed3..7346f3b 100644 --- a/app.py +++ b/app.py @@ -83,6 +83,8 @@ def get_person(person_id): max_date = convert_str_to_date(request.args.get( 'max_date'), '%Y-%m-%d') or max_date + graph_axis = request.args.getlist('graph_axis') or [] + selected_exercise_ids = [int(i) for i in request.args.getlist('exercise_id')] if not selected_exercise_ids and htmx.trigger_name != 'exercise_id': @@ -114,13 +116,16 @@ def get_person(person_id): if topsets_for_exercise: repitions = [t['Repetitions'] for t in topsets_for_exercise] weights = [t['Weight'] for t in topsets_for_exercise] + estimated_one_rep_max = [t['Estimated1RM'] + for t in topsets_for_exercise] start_dates = [t['StartDate'].strftime( "%Y-%m-%d") for t in topsets_for_exercise] exercise_view_model = { 'ExerciseId': exercise_id, 'ExerciseName': topsets_for_exercise[0]['ExerciseName'], - 'Repititions': repitions[::-1], + 'Repetitions': repitions[::-1], 'Weights': weights[::-1], + 'Estimated1RM': estimated_one_rep_max[::-1], 'StartDates': start_dates[::-1] } exercise_graph_view_models.append(exercise_view_model) @@ -128,9 +133,9 @@ def get_person(person_id): if htmx: return render_template('partials/page/person.html', - person=person, selected_exercise_ids=active_exercise_ids, max_date=max_date, min_date=min_date, tags=tags), 200, {"HX-Trigger": "updatedPeople"} + person=person, selected_exercise_ids=active_exercise_ids, max_date=max_date, min_date=min_date, tags=tags, graph_axis=graph_axis), 200, {"HX-Trigger": "updatedPeople"} - return render_template('person.html', person=person, selected_exercise_ids=active_exercise_ids, max_date=max_date, min_date=min_date, tags=tags), 200, {"HX-Trigger": "updatedPeople"} + return render_template('person.html', person=person, selected_exercise_ids=active_exercise_ids, max_date=max_date, min_date=min_date, tags=tags, graph_axis=graph_axis), 200, {"HX-Trigger": "updatedPeople"} @ app.route("/person//calendar") diff --git a/db.py b/db.py index 400f527..792447b 100644 --- a/db.py +++ b/db.py @@ -158,7 +158,8 @@ class DataBase(): E.exercise_id AS "ExerciseId", E.name AS "ExerciseName", T.repetitions AS "Repetitions", - T.weight AS "Weight" + T.weight AS "Weight", + round((100 * T.Weight::numeric::integer)/(101.3-2.67123 * T.Repetitions),0)::numeric::integer AS "Estimated1RM" FROM Person P LEFT JOIN Workout W ON P.person_id=W.person_id LEFT JOIN TopSet T ON W.workout_id=T.workout_id diff --git a/templates/partials/page/person.html b/templates/partials/page/person.html index 03ee730..42a9011 100644 --- a/templates/partials/page/person.html +++ b/templates/partials/page/person.html @@ -34,7 +34,7 @@
-
+
+ +
{% with person_id=person['PersonId'], tags=tags %} @@ -166,6 +184,7 @@
+{% if graph_axis %}
{% for exercise_graph in person['ExerciseGraphs'] %}
@@ -179,7 +198,7 @@ Plotly.newPlot("e-{{ exercise_graph['ExerciseId'] }}", [ { x: {{ exercise_graph['StartDates'] | replace('"', "'") | safe }}, - y: {{ exercise_graph['Repititions'] | replace('"', "'") | safe }}, + y: {{ exercise_graph['Repetitions'] | replace('"', "'") | safe }}, name: 'Reps', type: 'scatter' }, @@ -222,6 +241,7 @@
{% endfor %}
+{% endif %} {{ render_partial('partials/stats.html', stats=person['Stats']) }} diff --git a/templates/person.html b/templates/person.html index e1a18e1..c11588d 100644 --- a/templates/person.html +++ b/templates/person.html @@ -4,6 +4,6 @@ {{ render_partial('partials/page/person.html', person=person, selected_exercise_ids=selected_exercise_ids, max_date=max_date, -min_date=min_date, tags=tags) }} +min_date=min_date, tags=tags, graph_axis=graph_axis) }} {% endblock %} \ No newline at end of file