Added get streak method again

This commit is contained in:
Verox001 2024-02-20 10:13:00 +01:00
parent 6a46104efa
commit 4711106653

View File

@ -95,6 +95,34 @@ class Habit:
return HabitList(raw_habitLists[0], raw_habitLists[1], raw_habitLists[2]) if raw_habitLists else None 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 # Saves the progress of the Habit in the attribute percentage
def fill_statistics(self): def fill_statistics(self):
count = 0 count = 0