Merge remote-tracking branch 'origin/master'

This commit is contained in:
janphilippweinsheimer 2024-02-28 10:48:29 +01:00
commit d0c5127c92

View File

@ -24,6 +24,7 @@ class Habit:
times: int times: int
unit: int unit: int
slot: int slot: int
checked: bool = False
percentage: int = 0 percentage: int = 0
streak: int = 0 streak: int = 0
@ -112,44 +113,42 @@ class Habit:
return self.streak return self.streak
# bisherige streak zurückgeben, falls nicht vorhanden bei null starten # bisherige streak zurückgeben, falls nicht vorhanden bei null starten
if self.streak != 0 and (current_date == trackings[0] or yesterdate == trackings[0]): if current_date == trackings[0] or yesterdate == trackings[0]:
return self.streak return self.streak
else: else:
self.streak = 0 self.streak = 0
return self.streak return self.streak
def removeStreak(self): # Saves the progress and streak of the Habit in the attribute percentage
self.streak -= 1
return
def addStreak(self):
self.streak += 1
return
# Saves the progress of the Habit in the attribute percentage
def fill_statistics(self): def fill_statistics(self):
count = 0 today_date = datetime.today().date()
self.checked = False self.checked = False
for tracking in self.get_habitTrackings(): count = 0
if tracking.created_at.date() == datetime.today().date(): # self.streak =- 1
self.checked = True
# day yesterday_tracked = False
if self.unit == 0:
if tracking.created_at.date() == datetime.today().date(): for tracking in self.get_habitTrackings():
count += 1 tracking_date = tracking.created_at.date()
# week
elif self.unit == 1: if tracking_date == today_date - timedelta(days=1):
if tracking.created_at.isocalendar()[1] == datetime.today().isocalendar()[1]: yesterday_tracked = True
count += 1 if tracking_date == today_date:
# month self.checked = True
elif self.unit == 2: self.streak = + 1
if tracking.created_at.month == datetime.today().month:
count += 1 # Count occurrences based on unit
# year if self.unit == 0 and tracking_date == today_date:
elif self.unit == 3: count += 1 # Daily
if tracking.created_at.year == datetime.today().year: elif self.unit == 1 and tracking_date.isocalendar()[1] == today_date.isocalendar()[1]:
count += 1 count += 1 # Weekly
elif self.unit == 2 and tracking_date.month == today_date.month:
count += 1 # Monthly
elif self.unit == 3 and tracking_date.year == today_date.year:
count += 1 # Yearly
if not yesterday_tracked:
self.streak = 0
self.percentage = int(count / self.times * 100) self.percentage = int(count / self.times * 100)