Add options to configure filter options for dashboard(people, exercise, start/end date)
This commit is contained in:
26
app.py
26
app.py
@@ -35,12 +35,32 @@ def response_minify(response):
|
|||||||
@ app.route("/")
|
@ app.route("/")
|
||||||
def dashboard():
|
def dashboard():
|
||||||
all_topsets = db.get_all_topsets()
|
all_topsets = db.get_all_topsets()
|
||||||
|
|
||||||
|
exercises = db.get_exercises()
|
||||||
|
people = db.get_people()
|
||||||
|
|
||||||
|
selected_person_ids = [int(i)
|
||||||
|
for i in request.args.getlist('person_id')]
|
||||||
|
if not selected_person_ids and htmx.trigger_name != 'person_id':
|
||||||
|
selected_person_ids = [p['PersonId'] for p in people]
|
||||||
|
|
||||||
|
selected_exercise_ids = [int(i)
|
||||||
|
for i in request.args.getlist('exercise_id')]
|
||||||
|
if not selected_exercise_ids and htmx.trigger_name != 'exercise_id':
|
||||||
|
selected_exercise_ids = [e['ExerciseId'] for e in exercises]
|
||||||
|
|
||||||
|
min_date = convert_str_to_date(request.args.get(
|
||||||
|
'min_date'), '%Y-%m-%d') or min([t['StartDate'] for t in all_topsets])
|
||||||
|
max_date = convert_str_to_date(request.args.get(
|
||||||
|
'max_date'), '%Y-%m-%d') or max([t['StartDate'] for t in all_topsets])
|
||||||
|
|
||||||
people_and_exercise_rep_maxes = get_people_and_exercise_rep_maxes(
|
people_and_exercise_rep_maxes = get_people_and_exercise_rep_maxes(
|
||||||
all_topsets)
|
all_topsets, selected_person_ids, selected_exercise_ids, min_date, max_date)
|
||||||
|
|
||||||
if htmx:
|
if htmx:
|
||||||
return render_template('partials/page/dashboard.html',
|
return render_template('partials/page/dashboard.html',
|
||||||
model=people_and_exercise_rep_maxes), 200, {"HX-Trigger": "updatedPeople"}
|
model=people_and_exercise_rep_maxes, people=people, exercises=exercises, min_date=min_date, max_date=max_date, selected_person_ids=selected_person_ids, selected_exercise_ids=selected_exercise_ids), 200, {"HX-Trigger": "updatedPeople"}
|
||||||
return render_template('dashboard.html', model=people_and_exercise_rep_maxes)
|
return render_template('dashboard.html', model=people_and_exercise_rep_maxes, people=people, exercises=exercises, min_date=min_date, max_date=max_date, selected_person_ids=selected_person_ids, selected_exercise_ids=selected_exercise_ids)
|
||||||
|
|
||||||
|
|
||||||
@ app.route("/person/list", methods=['GET'])
|
@ app.route("/person/list", methods=['GET'])
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
{{ render_partial('partials/page/dashboard.html',
|
{{ render_partial('partials/page/dashboard.html',
|
||||||
model=model) }}
|
model=model, people=people, exercises=exercises, min_date=min_date, max_date=max_date,
|
||||||
|
selected_person_ids=selected_person_ids, selected_exercise_ids=selected_exercise_ids) }}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -1,3 +1,85 @@
|
|||||||
|
<div class="bg-white shadow rounded-lg p-4 w-full mb-4 flex flex-wrap">
|
||||||
|
<div class="w-full lg:w-1/4 sm:w-full px-3 mb-6 md:mb-0">
|
||||||
|
<div class="flex flex-wrap -mx-3">
|
||||||
|
<div class="w-full px-3">
|
||||||
|
<div class="mb-3 w-full"><label
|
||||||
|
class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2"
|
||||||
|
for="grid-city">People</label>
|
||||||
|
<select class="bg-gray-50 border border-gray-300 hidden" data-te-select-filter="true"
|
||||||
|
data-te-select-init="" data-te-select-size="lg" hx-get="{{ url_for('dashboard') }}"
|
||||||
|
hx-include="[name='min_date'],[name='max_date'],[name='exercise_id']" hx-push-url="true"
|
||||||
|
hx-target="#container" id="dashboard-people-multi-select" multiple="" name="person_id">
|
||||||
|
{% for p in people %}
|
||||||
|
<option value="{{ p['PersonId'] }}">{{
|
||||||
|
p['Name']
|
||||||
|
}}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script>te.Select.getOrCreateInstance(document.querySelector("#dashboard-people-multi-select")).setValue({{ list_to_string(selected_person_ids) | safe}})</script>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="w-full lg:w-1/4 sm:w-full px-3 mb-6 md:mb-0">
|
||||||
|
<div class="flex flex-wrap -mx-3">
|
||||||
|
<div class="w-full px-3">
|
||||||
|
<div class="mb-3 w-full"><label
|
||||||
|
class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2"
|
||||||
|
for="grid-city">Exercises</label>
|
||||||
|
<select class="bg-gray-50 border border-gray-300 hidden" data-te-select-filter="true"
|
||||||
|
data-te-select-init="" data-te-select-size="lg" hx-get="{{ url_for('dashboard') }}"
|
||||||
|
hx-include="[name='min_date'],[name='max_date'],[name='person_id']" hx-push-url="true"
|
||||||
|
hx-target="#container" id="dashboard-exercise-multi-select" multiple="" name="exercise_id">
|
||||||
|
{% for e in exercises %}
|
||||||
|
<option value="{{ e['ExerciseId'] }}">{{
|
||||||
|
e['Name']
|
||||||
|
}}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script>te.Select.getOrCreateInstance(document.querySelector("#dashboard-exercise-multi-select")).setValue({{ list_to_string(selected_exercise_ids) | safe}})</script>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="w-full lg:w-1/4 sm:w-full px-3 mb-6 md:mb-0"><label
|
||||||
|
class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" for="grid-city">Min
|
||||||
|
date</label>
|
||||||
|
<div class="relative">
|
||||||
|
<div class="flex absolute inset-y-0 left-0 items-center pl-3 pointer-events-none"><svg
|
||||||
|
class="w-5 h-5 text-gray-500 dark:text-gray-400" viewBox="0 0 20 20" aria-hidden="true"
|
||||||
|
fill="currentColor" xmlns="http://www.w3.org/2000/svg" data-darkreader-inline-fill=""
|
||||||
|
style="--darkreader-inline-fill:currentColor;">
|
||||||
|
<path
|
||||||
|
d="M6 2a1 1 0 00-1 1v1H4a2 2 0 00-2 2v10a2 2 0 002 2h12a2 2 0 002-2V6a2 2 0 00-2-2h-1V3a1 1 0 10-2 0v1H7V3a1 1 0 00-1-1zm0 5a1 1 0 000 2h8a1 1 0 100-2H6z"
|
||||||
|
clip-rule="evenodd" fill-rule="evenodd"></path>
|
||||||
|
</svg></div><input
|
||||||
|
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full pl-10 p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500 w-full"
|
||||||
|
hx-get="{{ url_for('dashboard') }}"
|
||||||
|
hx-include="[name='min_date'],[name='max_date'],[name='person_id'],[name='exercise_id']"
|
||||||
|
hx-push-url="true" hx-target="#container" hx-trigger="change" name="min_date" type="date"
|
||||||
|
value="{{ min_date }}">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="w-full lg:w-1/4 sm:w-full px-3 mb-6 md:mb-0"><label
|
||||||
|
class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" for="grid-zip">Max
|
||||||
|
date</label>
|
||||||
|
<div class="relative">
|
||||||
|
<div class="flex absolute inset-y-0 left-0 items-center pl-3 pointer-events-none"><svg
|
||||||
|
class="w-5 h-5 text-gray-500 dark:text-gray-400" viewBox="0 0 20 20" aria-hidden="true"
|
||||||
|
fill="currentColor" xmlns="http://www.w3.org/2000/svg" data-darkreader-inline-fill=""
|
||||||
|
style="--darkreader-inline-fill:currentColor;">
|
||||||
|
<path
|
||||||
|
d="M6 2a1 1 0 00-1 1v1H4a2 2 0 00-2 2v10a2 2 0 002 2h12a2 2 0 002-2V6a2 2 0 00-2-2h-1V3a1 1 0 10-2 0v1H7V3a1 1 0 00-1-1zm0 5a1 1 0 000 2h8a1 1 0 100-2H6z"
|
||||||
|
clip-rule="evenodd" fill-rule="evenodd"></path>
|
||||||
|
</svg></div><input
|
||||||
|
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full pl-10 p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500 w-full"
|
||||||
|
hx-get="{{ url_for('dashboard') }}" hx-push-url="true" hx-target="#container" hx-trigger="change"
|
||||||
|
name="max_date" type="date" value="{{ max_date }}">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="w-full grid grid-cols-1 xl:grid-cols-3 2xl:grid-cols-3 gap-4">
|
<div class="w-full grid grid-cols-1 xl:grid-cols-3 2xl:grid-cols-3 gap-4">
|
||||||
{% for p in model['People'] %}
|
{% for p in model['People'] %}
|
||||||
<div class="bg-white shadow rounded-lg p-4 sm:p-6 xl:p-8 ">
|
<div class="bg-white shadow rounded-lg p-4 sm:p-6 xl:p-8 ">
|
||||||
|
|||||||
23
utils.py
23
utils.py
@@ -73,21 +73,24 @@ def get_rep_maxes_for_person(person_topsets):
|
|||||||
return rep_maxes_in_exercises
|
return rep_maxes_in_exercises
|
||||||
|
|
||||||
|
|
||||||
def get_people_and_exercise_rep_maxes(topsets):
|
def get_people_and_exercise_rep_maxes(topsets, selected_person_ids, selected_exercise_ids, min_date, max_date):
|
||||||
# Get all unique workout_ids (No duplicates)
|
# Get all unique workout_ids (No duplicates)
|
||||||
people_ids = set([t['PersonId'] for t in topsets])
|
people_ids = set([t['PersonId']
|
||||||
|
for t in topsets])
|
||||||
|
filtered_people_ids = [p for p in people_ids if p in selected_person_ids]
|
||||||
|
|
||||||
# Group topsets into workouts
|
# Group topsets into workouts
|
||||||
people = []
|
people = []
|
||||||
for person_id in people_ids:
|
for person_id in filtered_people_ids:
|
||||||
workouts_for_person = [
|
workouts_for_person = [
|
||||||
t for t in topsets if t['PersonId'] == person_id]
|
t for t in topsets if t['PersonId'] == person_id and t['ExerciseId'] in selected_exercise_ids and t['StartDate'] >= min_date and t['StartDate'] <= max_date]
|
||||||
people.append({
|
if workouts_for_person:
|
||||||
'PersonId': person_id,
|
people.append({
|
||||||
'PersonName': workouts_for_person[0]['PersonName'],
|
'PersonId': person_id,
|
||||||
'NumberOfWorkouts': len(list(set([t['WorkoutId'] for t in workouts_for_person if t['WorkoutId'] is not None]))),
|
'PersonName': workouts_for_person[0]['PersonName'],
|
||||||
'Exercises': get_rep_maxes_for_person(workouts_for_person)
|
'NumberOfWorkouts': len(list(set([t['WorkoutId'] for t in workouts_for_person if t['WorkoutId'] is not None]))),
|
||||||
})
|
'Exercises': get_rep_maxes_for_person(workouts_for_person)
|
||||||
|
})
|
||||||
return {"People": people, "Stats": get_stats_from_topsets(topsets)}
|
return {"People": people, "Stats": get_stats_from_topsets(topsets)}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user