Refactor stats endpoint so supports filtering people and make dashboard page utilise it

This commit is contained in:
Peter Stockings
2025-01-27 00:07:27 +11:00
parent 527395d704
commit 5ed737ee94
7 changed files with 31 additions and 36 deletions

7
app.py
View File

@@ -448,12 +448,13 @@ def get_exercise_progress_for_user(person_id, exercise_id):
return render_template('partials/sparkline.html', **exercise_progress)
@app.route("/stats/person/<int:person_id>", methods=['GET'])
def get_stats_for_person(person_id):
@app.route("/stats", methods=['GET'])
def get_stats():
selected_people_ids = request.args.getlist('person_id', type=int)
min_date = request.args.get('min_date', type=convert_str_to_date)
max_date = request.args.get('max_date', type=convert_str_to_date)
selected_exercise_ids = request.args.getlist('exercise_id', type=int)
stats = db.stats.fetch_stats_for_person(person_id, min_date, max_date, selected_exercise_ids)
stats = db.stats.fetch_stats(selected_people_ids, min_date, max_date, selected_exercise_ids)
return render_template('partials/stats.html', stats=stats, refresh_url=request.full_path)
@ app.route("/person/<int:person_id>/workout/<int:workout_id>", methods=['GET'])