From 4711106653112dbbe9d3b70f56d201f475d052a6 Mon Sep 17 00:00:00 2001 From: Verox001 Date: Tue, 20 Feb 2024 10:13:00 +0100 Subject: [PATCH] Added get streak method again --- models/Habit.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/models/Habit.py b/models/Habit.py index e2d46a5..177cd04 100644 --- a/models/Habit.py +++ b/models/Habit.py @@ -95,6 +95,34 @@ class Habit: return HabitList(raw_habitLists[0], raw_habitLists[1], raw_habitLists[2]) if raw_habitLists else None + def getStreak(self): + streak = 0 + trackings = [] + + for rawTracking in get_habitTrackings_by_habit_id(self.id): + trackings.append(HabitTrackings(datetime.strptime(rawTracking[2], "%Y-%m-%d"))) + + trackings.sort(reverse=True) + if current_date == tracking[0]: + streak += 1 + for habitdate in trackings[1:]: + future_date = habitdate - relativedelta(day=1) + if future_date - habitdate == 0-0-1: + streak + 1 + + + future_date = habitdate - relativedelta(day=1) + + for habitdate in trackings: + current_date = date.today() + if current_date == habitdate or current_date == habitdate - relativedelta(day=1): + streak += 1 + + future_date = habitdate - relativedelta(day=1) + + return streak + + # Saves the progress of the Habit in the attribute percentage def fill_statistics(self): count = 0