Add view to list workout notes for a person
This commit is contained in:
52
db.py
52
db.py
@@ -486,4 +486,54 @@ class DataBase():
|
||||
|
||||
exercise_progress = get_exercise_graph_model(topsets[0]['exercise_name'], estimated_1rm, repetitions, weight, start_dates, messages)
|
||||
|
||||
return exercise_progress
|
||||
return exercise_progress
|
||||
|
||||
def get_workout_notes_for_person(self, person_id):
|
||||
sql_query = """
|
||||
SELECT
|
||||
p.name AS person_name,
|
||||
w.workout_id,
|
||||
to_char(w.start_date, 'Mon DD YYYY') AS formatted_start_date,
|
||||
w.note,
|
||||
t.filter as tag_filter,
|
||||
t.name AS tag_name
|
||||
FROM person p
|
||||
LEFT JOIN workout w ON p.person_id = w.person_id AND w.note IS NOT NULL AND w.note <> ''
|
||||
LEFT JOIN workout_tag wt ON w.workout_id = wt.workout_id
|
||||
LEFT JOIN tag t ON wt.tag_id = t.tag_id
|
||||
WHERE p.person_id = %s
|
||||
ORDER BY w.start_date DESC, w.workout_id, t.name;
|
||||
"""
|
||||
|
||||
# Execute the SQL query
|
||||
raw_workout_notes = self.execute(sql_query, [person_id])
|
||||
|
||||
# Initialize variables to hold the person's name and the workouts
|
||||
person_name = None
|
||||
workout_notes = {}
|
||||
|
||||
for row in raw_workout_notes:
|
||||
# Update person_name (it will be the same for all rows)
|
||||
if person_name is None:
|
||||
person_name = row['person_name']
|
||||
|
||||
# Process workout notes and tags if there's a note associated with the workout
|
||||
if row['workout_id'] and row['note']: # Check if workout_id exists and note is not None or empty
|
||||
workout_id = row['workout_id']
|
||||
if workout_id not in workout_notes:
|
||||
workout_notes[workout_id] = {
|
||||
'workout_id': workout_id,
|
||||
'formatted_start_date': row['formatted_start_date'],
|
||||
'note': row['note'],
|
||||
'tags': []
|
||||
}
|
||||
if row['tag_name']: # Only add the tag if it is not None
|
||||
workout_notes[workout_id]['tags'].append({'tag_filter': row['tag_filter'], 'tag_name': row['tag_name'], 'person_id': person_id})
|
||||
|
||||
|
||||
# Convert the workout_notes dictionary back into a list as the final result
|
||||
workout_notes_list = list(workout_notes.values())
|
||||
|
||||
# Return a tuple containing the person's name and their workout notes
|
||||
return (person_name, workout_notes_list)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user