From d967920e03ac27be62c7384e2aaeb05a4c25c5eb Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Sat, 9 Dec 2023 16:14:10 +1100 Subject: [PATCH] Start to refactor away from using camel case (Not sure why I did this in the first place) --- app.py | 8 ++++---- db.py | 10 +++------- templates/dashboard.html | 6 ++---- templates/partials/topset.html | 6 ++---- templates/person.html | 10 ++-------- templates/settings.html | 10 +++++----- utils.py | 4 ---- 7 files changed, 18 insertions(+), 36 deletions(-) diff --git a/app.py b/app.py index 327ae56..7498994 100644 --- a/app.py +++ b/app.py @@ -39,7 +39,7 @@ def response_minify(response): def dashboard(): all_topsets = db.get_all_topsets() - exercises = db.get_exercises() + exercises = db.get_all_exercises() people = db.get_people() tags = db.get_tags_for_dashboard() @@ -51,7 +51,7 @@ def dashboard(): selected_exercise_ids = [int(i) for i in request.args.getlist('exercise_id')] if not selected_exercise_ids and htmx.trigger_name != 'exercise_id': - selected_exercise_ids = [e['ExerciseId'] for e in exercises] + selected_exercise_ids = [e['exercise_id'] for e in exercises] min_date = convert_str_to_date(request.args.get( 'min_date'), '%Y-%m-%d') or min([t['StartDate'] for t in all_topsets]) @@ -195,7 +195,7 @@ def get_topset(person_id, workout_id, topset_id): @ app.route("/person//workout//topset//edit_form", methods=['GET']) @ validate_topset def get_topset_edit_form(person_id, workout_id, topset_id): - exercises = db.get_exercises() + exercises = db.get_all_exercises() topset = db.get_topset(person_id, workout_id, topset_id) return render_template('partials/topset.html', person_id=person_id, workout_id=workout_id, topset_id=topset_id, exercises=exercises, exercise_name=topset['ExerciseName'], repetitions=topset['Repetitions'], weight=topset['Weight'], exercise_id=topset['ExerciseId'], is_edit=True) @@ -301,7 +301,7 @@ def delete_exercise(exercise_id): @ app.route("/settings") def settings(): people = db.get_people() - exercises = db.get_exercises() + exercises = db.get_all_exercises() if htmx: return render_block(app.jinja_env, "settings.html", "content", people=people, exercises=exercises), 200, {"HX-Trigger": "updatedPeople"} return render_template('settings.html', people=people, exercises=exercises) diff --git a/db.py b/db.py index 40d02ab..effc424 100644 --- a/db.py +++ b/db.py @@ -52,11 +52,6 @@ class DataBase(): return (rv[0] if rv else None) if one else rv - def get_exercises(self): - exercises = self.execute( - 'SELECT exercise_id AS "ExerciseId", name AS "Name" FROM exercise') - return [{"ExerciseId": e['ExerciseId'], "Name": e['Name']} for e in exercises] - def get_exercise(self, exercise_id): exercise = self.execute( 'SELECT exercise_id AS "ExerciseId", name AS "Name" FROM exercise WHERE exercise_id=%s LIMIT 1', [exercise_id], one=True) @@ -503,10 +498,11 @@ class DataBase(): # Calculate viewBox dimensions date_range = max_date - min_date + total_span = date_range.days or 1 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, vb_height = total_span, e1rm_range vb_width *= 200 / vb_width # Scale to 200px width vb_height *= 75 / vb_height # Scale to 75px height @@ -514,7 +510,7 @@ class DataBase(): estimated_1rm_scaled = [((value - min_e1rm) / e1rm_range) * vb_height for value in estimated_1rm] repetitions_scaled = [((value - min_reps) / reps_range) * vb_height for value in repetitions] weight_scaled = [((value - min_weight) / weight_range) * vb_height for value in weight] - total_span = date_range.days or 1 + relative_positions = [(date - min_date).days / total_span for date in start_dates] # Convert relative positions and scaled estimated 1RM values to numpy arrays diff --git a/templates/dashboard.html b/templates/dashboard.html index 248ded1..51fd1ce 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -46,10 +46,8 @@ }) end"> {% for e in exercises %} - + {% endfor %} diff --git a/templates/partials/topset.html b/templates/partials/topset.html index 1291222..b5f3ff4 100644 --- a/templates/partials/topset.html +++ b/templates/partials/topset.html @@ -17,10 +17,8 @@ }) end"> {% for exercise in exercises|default([], true) %} - + {% endfor %} diff --git a/templates/person.html b/templates/person.html index ec769f5..a2f24e3 100644 --- a/templates/person.html +++ b/templates/person.html @@ -28,12 +28,6 @@ - -
- {% set exercise_list = person['FilteredExercises'] %} - -
-
@@ -121,7 +115,7 @@ class="p-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"> Date - {% for e in exercise_list %} + {% for e in person['FilteredExercises'] %} {{ e['ExerciseName'] }} @@ -138,7 +132,7 @@ {{ w['StartDate'] | strftime("%b %d %Y") }} - {% for e in exercise_list %} + {% for e in person['FilteredExercises'] %} {% set topset_exercise = w['TopSets'] | get_first_element_from_list_with_matching_attribute('ExerciseId', diff --git a/templates/settings.html b/templates/settings.html index 538c3ae..63bb885 100644 --- a/templates/settings.html +++ b/templates/settings.html @@ -36,7 +36,7 @@
- {% for e in exercises %} - {{ render_partial('partials/exercise.html', exercise_id=e['ExerciseId'], - name=e['Name'])}} + {% for exercise in exercises %} + {{ render_partial('partials/exercise.html', exercise_id=exercise.exercise_id, + name=exercise.name)}} {% endfor %} diff --git a/utils.py b/utils.py index 79a7a42..2b034b7 100644 --- a/utils.py +++ b/utils.py @@ -201,10 +201,6 @@ def get_date_info(input_date, selected_view): last_day_of_year = input_date.replace( year=input_date.year+1, month=1, day=1) - timedelta(days=1) - # Next/previous week - next_week = input_date + timedelta(weeks=1) - prev_week = input_date - timedelta(weeks=1) - # Next/previous month year, month = divmod(input_date.year * 12 + input_date.month, 12) next_month = date(year, month + 1, 1)