From fc570208bf4b170f4d08b01d39822c8b743ee379 Mon Sep 17 00:00:00 2001 From: Yapollon Date: Wed, 28 Feb 2024 14:28:31 +0100 Subject: [PATCH] Habit Streak Update (2/2)+ Minor change --- models/Habit.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/models/Habit.py b/models/Habit.py index d0fee6d..83ad11b 100644 --- a/models/Habit.py +++ b/models/Habit.py @@ -102,11 +102,14 @@ class Habit: # Loads the progress and checks if the streak is not broken def load_statistics(self): print("loading") - today_date = datetime.today().date() + today = datetime.today().date() + yesterday = today - timedelta(days=1) tracking_dates = [tracking.created_at.date() for tracking in self.get_habitTrackings()] - yesterday = today_date - timedelta(days=1) - if not self.checked and not yesterday in tracking_dates: - self.streak = 0 + + if not today in tracking_dates: + self.checked = False + if not yesterday in tracking_dates: + self.streak = 0 update_habit_statistics(self.id, self.count, self.count, self.streak) self.percentage = int(self.count / self.times * 100)