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
unit: int
slot: int
checked: bool = False
percentage: int = 0
streak: int = 0
@ -112,44 +113,42 @@ class Habit:
return self.streak
# 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
else:
self.streak = 0
return self.streak
def removeStreak(self):
self.streak -= 1
return
def addStreak(self):
self.streak += 1
return
# Saves the progress of the Habit in the attribute percentage
# Saves the progress and streak of the Habit in the attribute percentage
def fill_statistics(self):
count = 0
today_date = datetime.today().date()
self.checked = False
for tracking in self.get_habitTrackings():
if tracking.created_at.date() == datetime.today().date():
self.checked = True
count = 0
# self.streak =- 1
# day
if self.unit == 0:
if tracking.created_at.date() == datetime.today().date():
count += 1
# week
elif self.unit == 1:
if tracking.created_at.isocalendar()[1] == datetime.today().isocalendar()[1]:
count += 1
# month
elif self.unit == 2:
if tracking.created_at.month == datetime.today().month:
count += 1
# year
elif self.unit == 3:
if tracking.created_at.year == datetime.today().year:
count += 1
yesterday_tracked = False
for tracking in self.get_habitTrackings():
tracking_date = tracking.created_at.date()
if tracking_date == today_date - timedelta(days=1):
yesterday_tracked = True
if tracking_date == today_date:
self.checked = True
self.streak = + 1
# Count occurrences based on unit
if self.unit == 0 and tracking_date == today_date:
count += 1 # Daily
elif self.unit == 1 and tracking_date.isocalendar()[1] == today_date.isocalendar()[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)