Change sparkline to show duration of workouts daily displayed most recent on the left
This commit is contained in:
26
app.py
26
app.py
@@ -349,6 +349,31 @@ def render_users_and_workouts():
|
||||
duration_sparkline = sparklines.sparklines(
|
||||
[int(w['duration_minutes']) for w in workouts])[0]
|
||||
|
||||
# REFACTOR
|
||||
|
||||
def date_range(start_date, end_date):
|
||||
delta = end_date - start_date
|
||||
return [(start_date + timedelta(days=i)) for i in range(delta.days + 1)]
|
||||
|
||||
dates = date_range(start_date, end_date)
|
||||
daily_duration = []
|
||||
for date in dates:
|
||||
# check if workout exists for date
|
||||
workout = [w for w in workouts if w['start_time_date'].date()
|
||||
== date]
|
||||
if workout:
|
||||
daily_duration.append(int(workout[0]['duration_minutes']))
|
||||
else:
|
||||
daily_duration.append(0)
|
||||
|
||||
# Reverse the daily duration list so that the most recent day is on the right
|
||||
daily_duration.reverse()
|
||||
|
||||
daily_duration_sparkline = sparklines.sparklines(
|
||||
daily_duration)[0]
|
||||
|
||||
# REFACTOR BOUNDARY
|
||||
|
||||
user_data = {
|
||||
'id': user.id,
|
||||
'name': user.name,
|
||||
@@ -360,6 +385,7 @@ def render_users_and_workouts():
|
||||
'num_days': num_days,
|
||||
'workout_counts_sparkline': workout_counts_sparkline,
|
||||
'duration_sparkline': duration_sparkline,
|
||||
'daily_duration_sparkline': daily_duration_sparkline,
|
||||
'calendar_month': generate_calendar_monthly_view(workouts, datetime.now().date())
|
||||
}
|
||||
users_data.append(user_data)
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-sm text-gray-700 mb-4 max-w-full overflow-hidden">{{ user.duration_sparkline }}</div>
|
||||
<div class="text-sm text-gray-700 mb-4 max-w-full overflow-hidden">{{ user.daily_duration_sparkline }}</div>
|
||||
<div class="flex flex-col md:flex-row">
|
||||
<div class="w-full">
|
||||
<label class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" for="grid-state">
|
||||
|
||||
Reference in New Issue
Block a user