Check if weekly workouts is zero before calculating duratio by week to avoid division by zero error

This commit is contained in:
Peter Stockings
2023-09-14 18:20:12 +10:00
parent 60a7ec3d15
commit f251240dc8

5
app.py
View File

@@ -316,8 +316,9 @@ def render_users_and_workouts():
# Calculate the workout counts and duration for the current week
workout_counts_by_week.append(len(weekly_workouts))
duration_by_week.append(
int(sum([int(w['duration_minutes']) for w in weekly_workouts]))/len(weekly_workouts))
if weekly_workouts:
duration_by_week.append(
int(sum([int(w['duration_minutes']) for w in weekly_workouts]))/len(weekly_workouts))
workout_counts_sparkline = sparklines.sparklines(
workout_counts_by_week)