Проект
Приложение за следене на навиците, написано на Python - Курсова работа на английски
Създаване на приложение за следене на навиците, без графичен интерфейс.
Описване на стъпките, по които се създава приложението.
Кандидати // 4
Свиване-
Веселин Василев
Здравейте ! Изпратих Ви лично съобщение. Благодаря Ви много за отделеното внимание !!!!
Поздрави: Веселин Василев.- Aктивност:
- 30%
30% - 10 дни
-
Божидар Георгиев
from datetime import datetime, timedelta
class Habit:
def __init__(self, task, periodicity):
self.task = task
self.periodicity = periodicity
self.completions = []
self.last_completed = None
self.streak = 0
def check_off(self):
now = datetime.now()
self.completions.append(now)
if not self.last_completed or now - self.last_completed > self.periodicity:
self.streak = 1
else:
self.streak += 1
self.last_completed = now
def is_broken(self):
if not self.last_completed:
return True
return datetime.now() - self.last_completed > self.periodicity
def get_streak(self):
if self.is_broken():
return 0
return self.streak
class User:
def __init__(self, name):
self.name = name
self.habits = []
def add_habit(self, habit):
self.habits.append(habit)
def get_longest_streak(self):
return max((habit.get_streak() for habit in self.habits), default=0)
def get_daily_habits(self):
daily_period = timedelta(days=1)
return [habit for habit in self.habits if habit.periodicity = past_period]
if len(completions_in_period) < period.days / habit.periodicity.days:
struggling_habits.append(habit)
return struggling_habits
# Usage example
if __name__ == "__main__":
# Define some habits
habit1 = Habit("Brush teeth", timedelta(days=1))
habit2 = Habit("Go to the gym", timedelta(weeks=1))
# Create a user and add habits
user = User("John Doe")
user.add_habit(habit1)
user.add_habit(habit2)
# Check off some tasks
habit1.check_off() # brushing teeth
habit2.check_off() # going to the gym
# Print longest streak
print(f"Longest streak: {user.get_longest_streak()} days")
# Print daily habits
daily_habits = user.get_daily_habits()
print("Daily habits:", [habit.task for habit in daily_habits])
# Print struggling habits in the last month
struggling_habits = user.get_struggling_habits(timedelta(days=30))
print("Struggling habits:", [habit.task for habit in struggling_habits])
- Aктивност:
- 50%
50% - 5 дни
- 150 лв.
-
Божидар Георгиев
from datetime import datetime, timedelta
class Habit:
def __init__(self, task, periodicity):
self.task = task
self.periodicity = periodicity
self.completions = []
self.last_completed = None
self.streak = 0
def check_off(self):
now = datetime.now()
self.completions.append(now)
if not self.last_completed or now - self.last_completed > self.periodicity:
self.streak = 1
else:
self.streak += 1
self.last_completed = now
def is_broken(self):
if not self.last_completed:
return True
return datetime.now() - self.last_completed > self.periodicity
def get_streak(self):
if self.is_broken():
return 0
return self.streak
class User:
def __init__(self, name):
self.name = name
self.habits = []
def add_habit(self, habit):
self.habits.append(habit)
def get_longest_streak(self):
return max((habit.get_streak() for habit in self.habits), default=0)
def get_daily_habits(self):
daily_period = timedelta(days=1)
return [habit for habit in self.habits if habit.periodicity = past_period]
if len(completions_in_period) < period.days / habit.periodicity.days:
struggling_habits.append(habit)
return struggling_habits
# Usage example
if __name__ == "__main__":
# Define some habits
habit1 = Habit("Brush teeth", timedelta(days=1))
habit2 = Habit("Go to the gym", timedelta(weeks=1))
# Create a user and add habits
user = User("John Doe")
user.add_habit(habit1)
user.add_habit(habit2)
# Check off some tasks
habit1.check_off() # brushing teeth
habit2.check_off() # going to the gym
# Print longest streak
print(f"Longest streak: {user.get_longest_streak()} days")
# Print daily habits
daily_habits = user.get_daily_habits()
print("Daily habits:", [habit.task for habit in daily_habits])
# Print struggling habits in the last month
struggling_habits = user.get_struggling_habits(timedelta(days=30))
print("Struggling habits:", [habit.task for habit in struggling_habits])
- Aктивност:
- 50%
50% - 5 дни
- 150 лв.
-
Божидар Георгиев
from datetime import datetime, timedelta
class Habit:
def __init__(self, task, periodicity):
self.task = task
self.periodicity = periodicity
self.completions = []
self.last_completed = None
self.streak = 0
def check_off(self):
now = datetime.now()
self.completions.append(now)
if not self.last_completed or now - self.last_completed > self.periodicity:
self.streak = 1
else:
self.streak += 1
self.last_completed = now
def is_broken(self):
if not self.last_completed:
return True
return datetime.now() - self.last_completed > self.periodicity
def get_streak(self):
if self.is_broken():
return 0
return self.streak
class User:
def __init__(self, name):
self.name = name
self.habits = []
def add_habit(self, habit):
self.habits.append(habit)
def get_longest_streak(self):
return max((habit.get_streak() for habit in self.habits), default=0)
def get_daily_habits(self):
daily_period = timedelta(days=1)
return [habit for habit in self.habits if habit.periodicity = past_period]
if len(completions_in_period) < period.days / habit.periodicity.days:
struggling_habits.append(habit)
return struggling_habits
# Usage example
if __name__ == "__main__":
# Define some habits
habit1 = Habit("Brush teeth", timedelta(days=1))
habit2 = Habit("Go to the gym", timedelta(weeks=1))
# Create a user and add habits
user = User("John Doe")
user.add_habit(habit1)
user.add_habit(habit2)
# Check off some tasks
habit1.check_off() # brushing teeth
habit2.check_off() # going to the gym
# Print longest streak
print(f"Longest streak: {user.get_longest_streak()} days")
# Print daily habits
daily_habits = user.get_daily_habits()
print("Daily habits:", [habit.task for habit in daily_habits])
# Print struggling habits in the last month
struggling_habits = user.get_struggling_habits(timedelta(days=30))
print("Struggling habits:", [habit.task for habit in struggling_habits])
- Aктивност:
- 50%
50% - 5 дни
- 150 лв.