From d51266c2d1ad9513fb03c608db1d13834169b78e Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Sat, 9 Dec 2023 15:00:53 +1100 Subject: [PATCH] Remove graph model data from dashboard/people endpoints --- app.py | 37 ++----------------------------------- utils.py | 7 +------ 2 files changed, 3 insertions(+), 41 deletions(-) diff --git a/app.py b/app.py index b7adf36..327ae56 100644 --- a/app.py +++ b/app.py @@ -85,8 +85,6 @@ def get_person(person_id): max_date = request.args.get( 'max_date', default=max_date, type=convert_str_to_date) - graph_axis = request.args.getlist('graph_axis') - selected_exercise_ids = request.args.getlist('exercise_id', type=int) all_exercise_ids_for_person = [e['ExerciseId'] for e in person['Exercises']] @@ -105,41 +103,10 @@ def get_person(person_id): lambda e: e['ExerciseId'] in selected_exercise_ids, person['Exercises']) person['FilteredExercises'] = list(filtered_exercises) - if graph_axis: - # 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 selected_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] - 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'], - 'Repetitions': repitions[::-1], - 'Weights': weights[::-1], - 'Estimated1RM': estimated_one_rep_max[::-1], - 'StartDates': start_dates[::-1] - } - exercise_graph_view_models.append(exercise_view_model) - person['ExerciseGraphs'] = exercise_graph_view_models - else: - person['ExerciseGraphs'] = [] - if htmx: - return render_block(app.jinja_env, 'person.html', 'content', person=person, selected_exercise_ids=selected_exercise_ids, max_date=max_date, min_date=min_date, tags=tags, graph_axis=graph_axis), 200, {"HX-Trigger": "updatedPeople"} + return render_block(app.jinja_env, 'person.html', 'content', person=person, selected_exercise_ids=selected_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=selected_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=selected_exercise_ids, max_date=max_date, min_date=min_date, tags=tags), 200, {"HX-Trigger": "updatedPeople"} @ app.route("/person//calendar") diff --git a/utils.py b/utils.py index cb6c347..79a7a42 100644 --- a/utils.py +++ b/utils.py @@ -63,12 +63,7 @@ def get_rep_maxes_for_person(person_topsets): rep_maxes_in_exercises.append({ 'ExerciseId': e['ExerciseId'], 'ExerciseName': e['ExerciseName'], - 'RepMaxes': topsets_for_exercise, - 'EstimatedOneRepMaxProgressions': { - 'StartDates': json.dumps([t['StartDate'].strftime("%Y-%m-%d") 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]), - } + 'RepMaxes': topsets_for_exercise }) return rep_maxes_in_exercises