From e3435df8b5eafad772a74949d3c1327581e50a51 Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Sat, 9 Dec 2023 14:42:33 +1100 Subject: [PATCH] Switch to using custom svg sparkline for exercise graphs on person view, this isnt a proper implementation as it separate requests for each exercise selected (Want to get rid of dependency on plotly) --- app.py | 6 ++- db.py | 15 +++--- templates/person.html | 109 +++--------------------------------------- 3 files changed, 21 insertions(+), 109 deletions(-) diff --git a/app.py b/app.py index 8704437..b7adf36 100644 --- a/app.py +++ b/app.py @@ -432,7 +432,11 @@ def calculate_relative_positions(start_dates): @ app.route("/person//exercise//sparkline", methods=['GET']) def get_exercise_progress_for_user(person_id, exercise_id): - exercise_progress = db.get_exercise_progress_for_user(person_id, exercise_id) + min_date = convert_str_to_date(request.args.get( + 'min_date'), '%Y-%m-%d') + max_date = convert_str_to_date(request.args.get( + 'max_date'), '%Y-%m-%d') + exercise_progress = db.get_exercise_progress_for_user(person_id, exercise_id, min_date, max_date) if not exercise_progress: abort(404) diff --git a/db.py b/db.py index ec229f0..40d02ab 100644 --- a/db.py +++ b/db.py @@ -464,7 +464,7 @@ class DataBase(): 'SELECT exercise_id, name FROM exercise') return exercises - def get_exercise_progress_for_user(self, person_id, exercise_id): + def get_exercise_progress_for_user(self, person_id, exercise_id, min_date=None, max_date=None): # Execute SQL query to fetch topset data for a specific person and exercise topsets = self.execute(""" SELECT @@ -479,10 +479,13 @@ class DataBase(): JOIN workout W ON T.workout_id = W.workout_id WHERE - W.person_id = %s AND E.exercise_id = %s + W.person_id = %s + AND E.exercise_id = %s AND + (%s IS NULL OR W.start_date >= %s) AND + (%s IS NULL OR W.start_date <= %s) ORDER BY W.start_date; - """, [person_id, exercise_id]) + """, [person_id, exercise_id, min_date, min_date, max_date, max_date]) # Return None if no topsets found if not topsets: @@ -500,9 +503,9 @@ class DataBase(): # Calculate viewBox dimensions date_range = max_date - min_date - e1rm_range = max_e1rm - min_e1rm - reps_range = max_reps - min_reps - weight_range = max_weight - min_weight + e1rm_range = (max_e1rm - min_e1rm) or 1 + reps_range = (max_reps - min_reps) or 1 + weight_range = (max_weight - min_weight) or 1 vb_width, vb_height = date_range.days, e1rm_range vb_width *= 200 / vb_width # Scale to 200px width vb_height *= 75 / vb_height # Scale to 75px height diff --git a/templates/person.html b/templates/person.html index 7e3219c..ec769f5 100644 --- a/templates/person.html +++ b/templates/person.html @@ -35,7 +35,7 @@
-
+
-
+
@@ -81,7 +81,7 @@ hx-target="#container" hx-push-url="true" hx-trigger="change">
-
+
@@ -102,22 +102,6 @@ hx-target="#container" hx-push-url="true" hx-trigger="change">
-
-
- - -
-
{% with person_id=person['PersonId'], tags=tags %} @@ -186,95 +170,16 @@
-{% if graph_axis %}
- {% for exercise_graph in person['ExerciseGraphs'] %} + {% for exercise_id in selected_exercise_ids %}
-
-
- {{ - exercise_graph['ExerciseName'] }} -
-
- +
{% endfor %}
-{% endif %} {{ render_partial('partials/stats.html', stats=person['Stats']) }}