summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorstilbruch <stilbruch@protonmail.com>2022-05-09 00:25:31 -0500
committerstilbruch <stilbruch@protonmail.com>2022-05-09 00:25:31 -0500
commit0cce988f119b80fd69b9a415c9e9b983325a12af (patch)
treea1ff33b817b28fc64065cc3396a42750f6ef9a45 /app
parent3fd02681d178298551b0f8f3bba93964be30d4ca (diff)
downloadStrengthy-0cce988f119b80fd69b9a415c9e9b983325a12af.tar.xz
Strengthy-0cce988f119b80fd69b9a415c9e9b983325a12af.zip
Improve history page
Diffstat (limited to 'app')
-rw-r--r--app/routes/workout.py36
-rw-r--r--app/tables/workout.py7
-rw-r--r--app/templates/home.html2
-rw-r--r--app/templates/workout/history.html43
4 files changed, 62 insertions, 26 deletions
diff --git a/app/routes/workout.py b/app/routes/workout.py
index 8f58aa3..767603e 100644
--- a/app/routes/workout.py
+++ b/app/routes/workout.py
@@ -144,11 +144,35 @@ def workout_record(workout_id=None):
@app.route("/workout/history/<record_id>")
@login_required
def workout_history(record_id=None):
- record = WorkoutRecord.query.filter_by(
- id=int(record_id), user_id=current_user.id
- ).first()
-
- if not record:
+ query = (
+ db.session.query(SetRecord)
+ .join(WorkoutRecord)
+ .filter(
+ WorkoutRecord.id == SetRecord.workout_record_id,
+ WorkoutRecord.user_id == current_user.id,
+ WorkoutRecord.id == record_id,
+ )
+ .order_by(SetRecord.exercise_id)
+ .all()
+ )
+ if not query:
return redirect(url_for("home"))
- return render_template("workout/history.html", record=record)
+ # Condense into format we want
+ # TODO: this should be handled by an ExerciseRecord class, but I don't have time for it
+ exercises = {}
+ for set in query:
+ if set.exercise_id in exercises:
+ exercises[set.exercise_id]["sets"].append(set)
+ else:
+ exercises[set.exercise_id] = {
+ "sets": [set],
+ "name": set.exercise.name,
+ "id": int(set.exercise.id),
+ }
+
+ return render_template(
+ "workout/history.html",
+ exercises=exercises.values(),
+ workout_record=query[0].workout_record,
+ )
diff --git a/app/tables/workout.py b/app/tables/workout.py
index bdb200e..ff9208c 100644
--- a/app/tables/workout.py
+++ b/app/tables/workout.py
@@ -75,6 +75,10 @@ class SetRecord(db.Model):
# relationships
exercise = db.relationship("Exercise")
+ # Calculates using https://www.athlegan.com/calculate-1rm
+ def one_rep_max(self):
+ return int(self.lbs / (1.0278 - (0.0278 * self.reps)))
+
# Represents a recording of a workout
class WorkoutRecord(db.Model):
@@ -95,3 +99,6 @@ class WorkoutRecord(db.Model):
self.workout = workout
self.finished = finished
self.user = current_user
+
+ def finished_nice(self, fmt="%m/%d/%y %-I:%M %p"):
+ return self.finished.strftime(fmt)
diff --git a/app/templates/home.html b/app/templates/home.html
index 243f76d..07d6269 100644
--- a/app/templates/home.html
+++ b/app/templates/home.html
@@ -109,7 +109,7 @@
{% for record in records %}
<tr>
<td>{{ record.workout.name }}</td>
- <td>{{ record.finished.strftime("%m/%d/%y %-I:%M %p") }}</td>
+ <td>{{ record.finished_nice() }}</td>
<td class="level-right"><a class="button is-small is-primary" href="/workout/history/{{ record.id }}">View</a></td>
</tr>
{% endfor %}
diff --git a/app/templates/workout/history.html b/app/templates/workout/history.html
index de199a1..e8f2bc5 100644
--- a/app/templates/workout/history.html
+++ b/app/templates/workout/history.html
@@ -1,29 +1,34 @@
{% extends 'base/layout.html' %}
-{% block title %}Workout{% endblock %}
-
{% block content %}
<div class="container">
<div class="columns is-centered">
<div class="column">
- <h1 class="title is-2">Workout</h1>
+ <h1 class="title is-2">{{ workout_record.workout.name }}</h1>
+ <h2 class="subtitle">{{ workout_record.finished_nice() }}</h2>
<div class="box">
- <table class="table is-fullwidth is-hoverable">
- <thead>
- <th>Set</th>
- <th>lbs</th>
- <th>Reps</th>
- </thead>
- <tbody>
- {% for set in record.sets %}
- <tr>
- <th></th>
- <th>{{ set.lbs }}</th>
- <th>{{ set.reps }}</th>
- </tr>
- {% endfor %}
- </tbody>
- </table>
+ {% for exercise in exercises %}
+ <a class="button is-link is-pulled-right" href="/progress/exercise/{{ exercise.id }}">View Progress</a>
+ <h1 class="title is-4 has-text-black">{{ exercise.name }}</h1>
+ <table class="table is-fullwidth is-hoverable">
+ <thead>
+ <th>Set</th>
+ <th>lbs</th>
+ <th>Reps</th>
+ <th>1RM</th>
+ </thead>
+ <tbody>
+ {% for set in exercise.sets %}
+ <tr>
+ <th>{{ loop.index0 + 1 }}</th>
+ <th>{{ set.lbs }}</th>
+ <th>{{ set.reps }}</th>
+ <th>{{ set.one_rep_max() }}</th>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ {% endfor %}
</div>
</div>
</div>