From f251240dc84644d0df15d38a2d7098ab64991417 Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Thu, 14 Sep 2023 18:20:12 +1000 Subject: [PATCH] Check if weekly workouts is zero before calculating duratio by week to avoid division by zero error --- app.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index 9696d55..b9f4948 100644 --- a/app.py +++ b/app.py @@ -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)