From bad718289e98efb730a36f494f6a716e0b4c067f Mon Sep 17 00:00:00 2001 From: Yapollon Date: Fri, 16 Feb 2024 08:11:22 +0100 Subject: [PATCH 1/2] Fixing --- db/SQLiteClient.py | 8 +++---- models/Habit.py | 51 ++++++++++++++++++++++++++------------------- models/HabitList.py | 3 +-- models/User.py | 17 ++++++++++----- 4 files changed, 46 insertions(+), 33 deletions(-) diff --git a/db/SQLiteClient.py b/db/SQLiteClient.py index 390c94d..d557bc2 100644 --- a/db/SQLiteClient.py +++ b/db/SQLiteClient.py @@ -8,7 +8,7 @@ def con3(): return conn -### User.py ### +### User ### def create_user(name: str, email: str, password: str): password = hashlib.sha256(password.encode()).hexdigest() now = datetime.now().isoformat() @@ -42,7 +42,7 @@ def get_user_by_email(email: str): return user -def update_user(id: int, name: str, email: str, password: str = None): +def update_user(id: int, name: str, email: str, password: str): now = datetime.now().isoformat() if password: query = (f"UPDATE users SET name = '{name}', email = '{email}', password = '{password}', updated_at = '{now}' " @@ -67,8 +67,8 @@ def delete_user(id: int): return cursor.lastrowid -### Habit.py ### -def create_habit(list_id: int, name: str, times: int, unit: int, slot: int, note: str | None=None): +### Habit ### +def create_habit(list_id: int, name: str, note: str, times: int, unit: int, slot: int): now = datetime.now().isoformat() query = (f"INSERT INTO habits (list_id, name, note, times, unit, slot, created_at, updated_at) " f"VALUES ('{list_id}', '{name}', '{note}', '{times}', '{unit}', '{slot}', '{now}', '{now}');") diff --git a/models/Habit.py b/models/Habit.py index 35faf65..24836e5 100644 --- a/models/Habit.py +++ b/models/Habit.py @@ -7,11 +7,11 @@ from db.SQLiteClient import (create_habit, get_habit, update_habit, delete_habit get_habitTrackings_by_habit_id, get_habitList) -# Unit wird als Integer wie folgt gemessen: -# 0: Tag -# 1: Woche (Default) -# 2: Monat -# 3: Jahr +# unit will be represented by integers like this: +# 0: day +# 1: week (default) +# 2: month +# 3: year @dataclass class Habit: @@ -28,9 +28,9 @@ class Habit: self.fill_statistics() @staticmethod - def create(list_id: int, name: str, times: int, note: str | None = None, unit: int | None = 1): + def create(list_id: int, name: str, times: int, note: str = None, unit: int = 1): slot = get_next_slot(list_id) - id = create_habit(list_id, name, times, unit, slot, note) + id = create_habit(list_id, name, note, times, unit, slot) return Habit(id, list_id, name, note, times, unit, slot) @staticmethod @@ -38,46 +38,52 @@ class Habit: habit = get_habit(id) return Habit(habit[0], habit[1], habit[2], habit[3], habit[4], habit[5], habit[6]) if habit else None - def update(self, name: str=None, note: str=None, times: int=None, unit: int=None): - update_habit(self.id, name, note, times, unit) - if name is not None: - self.name = name - if note is not None: - self.note = note - if times is not None: - self.times = times - if unit is not None: - self.unit = unit + + def update(self): + update_habit(self.id, self.name, self.note, self.times, self.unit) + def update_slot(self, new_slot: int): + # Fetches a list with the following structure [(id, slot), (id, slot), ...] slots = get_slots(self.list_id) - if new_slot > self.slot: - slots = slots[self.slot:new_slot] + + # Splits the list depending on whether the new slot is higher or lower than the current one + if new_slot > self.slot: # Example self.slot=1 new_slot=4 + slots = slots[self.slot:new_slot] # Expected list: [(id, 2), (id, 3), (id, 4)] for slot in slots: update_slot(slot[0], slot[1]-1) - if new_slot < self.slot: - slots = slots[new_slot-1:self.slot-1] + if new_slot < self.slot: # Example self.slot=4 new_slot=1 + slots = slots[new_slot-1:self.slot-1] # Expected list: [(id, 1), (id, 2), (id, 3)] for slot in slots: update_slot(slot[0], slot[1]+1) + + # Update the slot of the current habit update_slot(self.id, new_slot) + def delete(self): + # Deletes the current habit slots = get_slots(self.list_id)[self.slot+1:] for slot in slots: update_slot(slot[0], slot[1] - 1) + + # Deletes the current habit delete_habit(self.id) + def get_habitTrackings(self) -> list: trackings = [] for rawTracking in get_habitTrackings_by_habit_id(self.id): trackings.append(HabitTrackings(rawTracking[0], rawTracking[1])) return trackings - def habit_list(self): + + def habit_list(self) -> list: from models.HabitList import HabitList raw_habitLists = get_habitList(self.list_id) return HabitList(raw_habitLists[0], raw_habitLists[1], raw_habitLists[2]) if raw_habitLists else None + def fill_statistics(self): count = 0 self.checked = False @@ -104,5 +110,6 @@ class Habit: self.percentage = int(count / self.times * 100) + def to_json(self): return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True, indent=4) diff --git a/models/HabitList.py b/models/HabitList.py index 64fa292..bf3525c 100644 --- a/models/HabitList.py +++ b/models/HabitList.py @@ -1,5 +1,4 @@ from dataclasses import dataclass -from datetime import datetime from models.Habit import Habit from models.User import User @@ -22,7 +21,7 @@ class HabitList: @staticmethod def get(id: int): habitList = get_habitList(id) - return HabitList(habitList[0], habitList[1], habitList[2], datetime.strptime(habitList[3], "%Y-%m-%dT%H:%M:%S.%f"), datetime.strptime(habitList[4], "%Y-%m-%dT%H:%M:%S.%f")) if habitList else None + return HabitList(habitList[0], habitList[1], habitList[2]) if habitList else None def get_habits(self) -> list: raw_habits = get_habits(self.id) diff --git a/models/User.py b/models/User.py index e058fc3..423c6b8 100644 --- a/models/User.py +++ b/models/User.py @@ -1,12 +1,10 @@ -from datetime import datetime - from flask_login import UserMixin from db.SQLiteClient import (create_user, get_user, get_user_by_email, update_user, delete_user, get_habitLists, get_heatmap_value) class User(UserMixin): - def __init__(self, id: int, name: str, email: str, password: str | None = None): + def __init__(self, id: int, name: str, email: str, password: str = None): self.id = id self.name = name self.email = email @@ -27,29 +25,38 @@ class User(UserMixin): user = get_user_by_email(email) return User(user[0], user[1], user[2], user[3]) if user else None + def update(self): update_user(self.id, self.name, self.email, self.password if self.password else None) + def delete(self): + # calls the deletion of the users habitLists habitLists = self.get_habitLists() for habitList in habitLists: habitList.delete(self.id) + + # deletes the user delete_user(self.id) + + # returns all habitLists assigned with the user def get_habitLists(self) -> list: from models.HabitList import HabitList raw_habitLists = get_habitLists(self.id) habitLists = [] for habitList in raw_habitLists: - habitList = HabitList(habitList[0], habitList[1], habitList[2], datetime.strptime(habitList[3], "%Y-%m-%dT%H:%M:%S.%f"), datetime.strptime(habitList[4], "%Y-%m-%dT%H:%M:%S.%f")) + habitList = HabitList(habitList[0], habitList[1], habitList[2]) habitLists.append(habitList) return habitLists + + # return the heatmap-values of the last 28 days def get_heatmap(self) -> list: heatmap = [] - for day in range (0, 27): + for day in range (0, 28): value = get_heatmap_value(self.id, day) heatmap.append(value) return heatmap \ No newline at end of file From 91252a598b42736ec5713423b60119f378947992 Mon Sep 17 00:00:00 2001 From: Yapollon Date: Fri, 16 Feb 2024 08:11:25 +0100 Subject: [PATCH 2/2] Create UML.dia.autosave --- UML.dia.autosave | Bin 0 -> 2378 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 UML.dia.autosave diff --git a/UML.dia.autosave b/UML.dia.autosave new file mode 100644 index 0000000000000000000000000000000000000000..c94e3e4a83b0257c9e4f33aca6519ac1cda24f50 GIT binary patch literal 2378 zcmV-Q3AOegiwFP!000023+-K9kK#BMeeYip(J#AFbx18I5y zGKmX39g<9Jsv2oDzkMB`C?E+TUsORIq-q*)d}8O^dwp%+>mPsmJ`a^gnsOFLcLQD3 z1`3V*IAGEAZt(TDUp~2mpYA{W7%=jK{F|m^uE;AQo_)F-%!EjO7!IGFp44#3iHK7* zWDAwk;a?;S$xs#=4(>lF%5DV#5hVL=^DPk~Ws`-VN<`-LZZIMKw`m$LqF}HtwJGPv zVVo+DB)l7Zd|15(!%a2Ay?Tz+oscP=q?CLsuUeC@@wiFV2~7{HohLD8vWQqFxgsU? zWdH7z*_7h4P&B>&_z&~r`j$3dywp{6qop8XPSPoh@;I_@!gWU&s%sdA>vh4TzFo%^t^D4dr6#%lrWKpoWyZRNwh{4>4G-L;XVl^#f~+rMJpbd5OKx* zKah~0(t!2XTWPB+xzm&d#|3wX+SA zfB1A(+WY15mTXwpR%#vsms-@SZyu%#7EoS6v;8t9HO)4~hE=_OSnkx0S$}n4tXB{r zS<-Y<{b%{;XgWK;-y? z1$TpgYx`Yw*f?2})PlLbO5ztnsjhWnsk(L80eSUN1~8c%)}PATC($&dTZ|0i)^JqQ zux@l)wVR>Qkj_0nPNV$zpt~lmKvs$*->j{nvQ*13$2+eUSTo9|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