Display heaviest topsets over time on home page
This commit is contained in:
6
app.py
6
app.py
@@ -3,6 +3,7 @@ from flasgger import Swagger, swag_from
|
||||
|
||||
from db import DataBase
|
||||
from decorators import validate_person, validate_topset, validate_workout
|
||||
from utils import get_people_and_exercise_rep_maxes
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config.from_pyfile('config.py')
|
||||
@@ -14,7 +15,10 @@ db = DataBase(app)
|
||||
@ app.route("/")
|
||||
@ swag_from('swagger/dashboard.yml')
|
||||
def dashboard():
|
||||
return render_template('index.html')
|
||||
all_topsets = db.get_all_topsets()
|
||||
people_and_exercise_rep_maxes = get_people_and_exercise_rep_maxes(
|
||||
all_topsets)
|
||||
return render_template('index.html', model=people_and_exercise_rep_maxes)
|
||||
|
||||
|
||||
@ app.route("/person/<int:person_id>")
|
||||
|
||||
21
db.py
21
db.py
@@ -1,7 +1,7 @@
|
||||
import datetime
|
||||
import sqlite3
|
||||
|
||||
from utils import get_all_exercises_from_topsets, get_workouts
|
||||
from utils import get_all_exercises_from_topsets, get_people_and_exercise_rep_maxes, get_workouts
|
||||
|
||||
|
||||
class DataBase():
|
||||
@@ -170,3 +170,22 @@ class DataBase():
|
||||
"Weight": topset['Weight'],
|
||||
"Repetitions": topset['Repetitions']
|
||||
}
|
||||
|
||||
def get_all_topsets(self):
|
||||
all_topsets = self.execute("""
|
||||
SELECT
|
||||
P.PersonId,
|
||||
P.Name AS PersonName,
|
||||
W.WorkoutId,
|
||||
W.StartDate,
|
||||
T.TopSetId,
|
||||
E.ExerciseId,
|
||||
E.Name AS ExerciseName,
|
||||
T.Repetitions,
|
||||
T.Weight
|
||||
FROM Person P
|
||||
LEFT JOIN Workout W ON P.PersonId=W.PersonId
|
||||
LEFT JOIN TopSet T ON W.WorkoutId=T.WorkoutId
|
||||
LEFT JOIN Exercise E ON T.ExerciseId=E.ExerciseId""")
|
||||
|
||||
return all_topsets
|
||||
|
||||
4
static/edit-icon.svg
Normal file
4
static/edit-icon.svg
Normal file
@@ -0,0 +1,4 @@
|
||||
<svg class="fhCwost7CSNRc2WSHLFW rxe6apEJoEk8r75xaVNG ADSeKHR1DvUUA48Chci_" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" style="
|
||||
height: 1.25em;
|
||||
width: 1.25em;
|
||||
"><path d="M17.414 2.586a2 2 0 00-2.828 0L7 10.172V13h2.828l7.586-7.586a2 2 0 000-2.828z"></path><path fill-rule="evenodd" d="M2 6a2 2 0 012-2h4a1 1 0 010 2H4v10h10v-4a1 1 0 112 0v4a2 2 0 01-2 2H4a2 2 0 01-2-2V6z" clip-rule="evenodd"></path></svg>
|
||||
|
After Width: | Height: | Size: 448 B |
@@ -3,24 +3,26 @@
|
||||
{% block content %}
|
||||
|
||||
<div class="w-full grid grid-cols-1 xl:grid-cols-3 2xl:grid-cols-3 gap-4">
|
||||
{% for p in model %}
|
||||
<div class="bg-white shadow rounded-lg p-4 sm:p-6 xl:p-8 ">
|
||||
|
||||
<div class="mb-4 flex items-center justify-between">
|
||||
<div>
|
||||
<h3 class="text-xl font-bold text-gray-900 mb-2">Gabe</h3>
|
||||
<h3 class="text-xl font-bold text-gray-900 mb-2">{{ p['PersonName'] }}</h3>
|
||||
<span class="text-base font-normal text-gray-500">Current rep maxes</span>
|
||||
</div>
|
||||
<div class="flex-shrink-0">
|
||||
<a href="{{ url_for('get_person' ,person_id=1) }}"
|
||||
<a href="{{ url_for('get_person' ,person_id=p['PersonId']) }}"
|
||||
class="text-sm font-medium text-cyan-600 hover:bg-gray-100 rounded-lg p-2">View workouts</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% for e in p['Exercises'] %}
|
||||
<div class="flex flex-col mt-8">
|
||||
<div class="overflow-x-auto rounded-lg">
|
||||
<div class="align-middle inline-block min-w-full">
|
||||
<div class="shadow overflow-hidden sm:rounded-lg">
|
||||
<h4 class="text-l font-semibold text-blue-400 mb-2 text-center">Bench</h4>
|
||||
<h4 class="text-l font-semibold text-blue-400 mb-2 text-center">{{ e['ExerciseName'] }}</h4>
|
||||
<table class="min-w-full divide-y divide-gray-200">
|
||||
<thead class="bg-gray-50">
|
||||
<tr>
|
||||
@@ -32,300 +34,31 @@
|
||||
class="p-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
Rep Max
|
||||
</th>
|
||||
<th scope="col"
|
||||
class="p-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
Estimated 1 Rep max
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="bg-white">
|
||||
<tr>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-normal text-gray-500">
|
||||
Apr 23 ,2021
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
5 x 100kg
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
130kg
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-normal text-gray-500">
|
||||
Apr 23 ,2021
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
5 x 100kg
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
130kg
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-normal text-gray-500">
|
||||
Apr 23 ,2021
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
5 x 100kg
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
130kg
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-normal text-gray-500">
|
||||
Apr 23 ,2021
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
5 x 100kg
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
130kg
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col mt-8">
|
||||
<div class="overflow-x-auto rounded-lg">
|
||||
<div class="align-middle inline-block min-w-full">
|
||||
<div class="shadow overflow-hidden sm:rounded-lg">
|
||||
<h4 class="text-l font-semibold text-blue-400 mb-2 text-center">Squat</h4>
|
||||
<table class="min-w-full divide-y divide-gray-200">
|
||||
<thead class="bg-gray-50">
|
||||
<tr>
|
||||
<th scope="col"
|
||||
class="p-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
Date
|
||||
</th>
|
||||
<th scope="col"
|
||||
class="p-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
Rep Max
|
||||
</th>
|
||||
<th scope="col"
|
||||
class="p-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
Estimated 1 Rep max
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="bg-white">
|
||||
{% for rm in e['RepMaxes'] %}
|
||||
<tr>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-normal text-gray-500">
|
||||
Apr 23 ,2021
|
||||
{{ rm['StartDate'] }}
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
5 x 100kg
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
130kg
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-normal text-gray-500">
|
||||
Apr 23 ,2021
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
5 x 100kg
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
130kg
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-normal text-gray-500">
|
||||
Apr 23 ,2021
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
5 x 100kg
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
130kg
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-normal text-gray-500">
|
||||
Apr 23 ,2021
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
5 x 100kg
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
130kg
|
||||
{{ rm['Repetitions'] }} x {{ rm['Weight'] }}kg
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
<div class="bg-white shadow rounded-lg p-4 sm:p-6 xl:p-8 ">
|
||||
|
||||
<div class="mb-4 flex items-center justify-between">
|
||||
<div>
|
||||
<h3 class="text-xl font-bold text-gray-900 mb-2">Michael</h3>
|
||||
<span class="text-base font-normal text-gray-500">Current rep maxes</span>
|
||||
</div>
|
||||
<div class="flex-shrink-0">
|
||||
<a href="{{ url_for('get_person' ,person_id=2) }}"
|
||||
class="text-sm font-medium text-cyan-600 hover:bg-gray-100 rounded-lg p-2">View workouts</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col mt-8">
|
||||
<div class="overflow-x-auto rounded-lg">
|
||||
<div class="align-middle inline-block min-w-full">
|
||||
<div class="shadow overflow-hidden sm:rounded-lg">
|
||||
<h4 class="text-l font-semibold text-blue-400 mb-2 text-center">Bench</h4>
|
||||
<table class="min-w-full divide-y divide-gray-200">
|
||||
<thead class="bg-gray-50">
|
||||
<tr>
|
||||
<th scope="col"
|
||||
class="p-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
Date
|
||||
</th>
|
||||
<th scope="col"
|
||||
class="p-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
Rep Max
|
||||
</th>
|
||||
<th scope="col"
|
||||
class="p-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
Estimated 1 Rep max
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="bg-white">
|
||||
<tr>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-normal text-gray-500">
|
||||
Apr 23 ,2021
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
5 x 100kg
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
130kg
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-normal text-gray-500">
|
||||
Apr 23 ,2021
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
5 x 100kg
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
130kg
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-normal text-gray-500">
|
||||
Apr 23 ,2021
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
5 x 100kg
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
130kg
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-normal text-gray-500">
|
||||
Apr 23 ,2021
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
5 x 100kg
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
130kg
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col mt-8">
|
||||
<div class="overflow-x-auto rounded-lg">
|
||||
<div class="align-middle inline-block min-w-full">
|
||||
<div class="shadow overflow-hidden sm:rounded-lg">
|
||||
<h4 class="text-l font-semibold text-blue-400 mb-2 text-center">Squat</h4>
|
||||
<table class="min-w-full divide-y divide-gray-200">
|
||||
<thead class="bg-gray-50">
|
||||
<tr>
|
||||
<th scope="col"
|
||||
class="p-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
Date
|
||||
</th>
|
||||
<th scope="col"
|
||||
class="p-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
Rep Max
|
||||
</th>
|
||||
<th scope="col"
|
||||
class="p-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
Estimated 1 Rep max
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="bg-white">
|
||||
<tr>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-normal text-gray-500">
|
||||
Apr 23 ,2021
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
5 x 100kg
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
130kg
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-normal text-gray-500">
|
||||
Apr 23 ,2021
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
5 x 100kg
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
130kg
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-normal text-gray-500">
|
||||
Apr 23 ,2021
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
5 x 100kg
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
130kg
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-normal text-gray-500">
|
||||
Apr 23 ,2021
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
5 x 100kg
|
||||
</td>
|
||||
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
|
||||
130kg
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
{% block content %}
|
||||
<div class="flex justify-center">
|
||||
<div class="bg-white shadow rounded-lg p-4 sm:p-6 xl:p-8 md:w-full lg:w-10/12 xl:w-8/12 2xl:w-5/12">
|
||||
<div class="bg-white shadow rounded-lg p-4 sm:w-full xl:p-8 md:w-full lg:w-10/12 xl:w-8/12 2xl:w-6/12">
|
||||
|
||||
<div class="mb-4 flex items-center justify-between">
|
||||
<div>
|
||||
|
||||
52
utils.py
52
utils.py
@@ -1,3 +1,6 @@
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
def get_workouts(topsets):
|
||||
# Get all unique workout_ids (No duplicates)
|
||||
workout_ids = set([t['WorkoutId']
|
||||
@@ -26,3 +29,52 @@ def get_all_exercises_from_topsets(topsets):
|
||||
'ExerciseName': next((t['ExerciseName'] for t in topsets if t['ExerciseId'] == exercise_id), 'Unknown')
|
||||
})
|
||||
return exercises
|
||||
|
||||
|
||||
def get_rep_maxes_for_person(person_topsets):
|
||||
person_exercises = get_all_exercises_from_topsets(person_topsets)
|
||||
|
||||
rep_maxes_in_exercises = []
|
||||
for e in person_exercises:
|
||||
exercise_topsets = [
|
||||
t for t in person_topsets if t['ExerciseId'] == e['ExerciseId']]
|
||||
set_reps = set([t['Repetitions'] for t in exercise_topsets])
|
||||
|
||||
topsets_for_exercise = []
|
||||
for rep in set_reps:
|
||||
reps = [t for t in exercise_topsets if t['Repetitions'] == rep]
|
||||
max_weight = max([t['Weight'] for t in reps])
|
||||
max_topset_for_rep = [t for t in reps if t['Weight'] == max_weight]
|
||||
topsets_for_exercise.append({
|
||||
'StartDate': max_topset_for_rep[0]['StartDate'],
|
||||
'Repetitions': rep,
|
||||
'Weight': max_weight
|
||||
})
|
||||
|
||||
# datetime.strptime(x['StartDate'], "%Y-%m-%d")
|
||||
topsets_for_exercise.sort(
|
||||
key=lambda x: x['Repetitions'], reverse=True)
|
||||
|
||||
rep_maxes_in_exercises.append({
|
||||
'ExerciseId': e['ExerciseId'],
|
||||
'ExerciseName': e['ExerciseName'],
|
||||
'RepMaxes': topsets_for_exercise,
|
||||
})
|
||||
return rep_maxes_in_exercises
|
||||
|
||||
|
||||
def get_people_and_exercise_rep_maxes(topsets):
|
||||
# Get all unique workout_ids (No duplicates)
|
||||
people_ids = set([t['PersonId'] for t in topsets])
|
||||
|
||||
# Group topsets into workouts
|
||||
people = []
|
||||
for person_id in people_ids:
|
||||
workouts_for_person = [
|
||||
t for t in topsets if t['PersonId'] == person_id]
|
||||
people.append({
|
||||
'PersonId': person_id,
|
||||
'PersonName': workouts_for_person[0]['PersonName'],
|
||||
'Exercises': get_rep_maxes_for_person(workouts_for_person)
|
||||
})
|
||||
return people
|
||||
|
||||
BIN
workout.db
BIN
workout.db
Binary file not shown.
Reference in New Issue
Block a user