From c4bd430eaf7af22bb94acbaaa23376bc64439b46 Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Sun, 2 Apr 2023 22:36:30 +1000 Subject: [PATCH] WIP: Add graphs to workouts list view that show reps/weight, still need to refactor logic and dont display unless plot button(Need to add) is checked --- app.py | 28 ++++++++++++++++++- templates/partials/page/person.html | 43 +++++++++++++++++++++++++++++ utils.py | 13 +++++++++ 3 files changed, 83 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index fac05aa..a6e9ed3 100644 --- a/app.py +++ b/app.py @@ -5,7 +5,7 @@ from flask import Flask, render_template, redirect, request, url_for import jinja_partials from decorators import validate_person, validate_topset, validate_workout from db import DataBase -from utils import get_people_and_exercise_rep_maxes, convert_str_to_date, get_earliest_and_latest_workout_date, filter_workout_topsets, get_exercise_ids_from_workouts, first_and_last_visible_days_in_month +from utils import flatten, get_people_and_exercise_rep_maxes, convert_str_to_date, get_earliest_and_latest_workout_date, filter_workout_topsets, get_exercise_ids_from_workouts, first_and_last_visible_days_in_month from flask_htmx import HTMX import minify_html from urllib.parse import urlparse, unquote, quote @@ -100,6 +100,32 @@ def get_person(person_id): filtered_exercises = filter( lambda e: e['ExerciseId'] in active_exercise_ids, person['Exercises']) person['FilteredExercises'] = list(filtered_exercises) + + # New feature to plot reps and weights over time + topsets_with_start_date = flatten([(p['StartDate'], p['TopSets']) + for p in person['Workouts']]) + topsets = flatten([[{**t, 'StartDate': start_date} for t in topsets] + for (start_date, topsets) in topsets_with_start_date]) + + exercise_graph_view_models = [] + for exercise_id in active_exercise_ids: + topsets_for_exercise = [ + t for t in topsets if t['ExerciseId'] == exercise_id] + if topsets_for_exercise: + repitions = [t['Repetitions'] for t in topsets_for_exercise] + weights = [t['Weight'] 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], + 'Weights': weights[::-1], + 'StartDates': start_dates[::-1] + } + exercise_graph_view_models.append(exercise_view_model) + person['ExerciseGraphs'] = exercise_graph_view_models + 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"} diff --git a/templates/partials/page/person.html b/templates/partials/page/person.html index ed667e8..0a578d3 100644 --- a/templates/partials/page/person.html +++ b/templates/partials/page/person.html @@ -162,9 +162,52 @@ + +
+ {% for exercise_graph in person['ExerciseGraphs'] %} +
+
+
+ {{ + exercise_graph['ExerciseName'] }} +
+
+ +
+
+ {% endfor %} +
+ {{ render_partial('partials/stats.html', stats=person['Stats']) }}