Compare commits
2 Commits
7745518950
...
b383a5a424
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b383a5a424 | ||
|
|
b816ac1ef7 |
@ -140,20 +140,22 @@ def get_slots(user_id: int):
|
|||||||
return slots
|
return slots
|
||||||
|
|
||||||
|
|
||||||
def update_habit(id: int, name: str, note: str, times: int, unit: int):
|
|
||||||
query = f"UPDATE habits SET name = {name}, note = {note}, times = {times}, unit = {unit} WHERE id = {id};"
|
|
||||||
conn = con3()
|
|
||||||
cursor = conn.cursor()
|
|
||||||
cursor.execute(query)
|
|
||||||
conn.close()
|
|
||||||
return cursor.lastrowid
|
|
||||||
|
|
||||||
|
|
||||||
def update_slot(id: int, slot: int):
|
def update_slot(id: int, slot: int):
|
||||||
query = f"UPDATE habits SET slot = {slot} WHERE id = {id};"
|
query = f"UPDATE habits SET slot = {slot} WHERE id = {id};"
|
||||||
conn = con3()
|
conn = con3()
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
return cursor.lastrowid
|
||||||
|
|
||||||
|
|
||||||
|
def update_habit(id: int, name: str, note: str, times: int, unit: int):
|
||||||
|
query = f"UPDATE habits SET name = {name}, note = {note}, times = {times}, unit = {unit} WHERE id = {id};"
|
||||||
|
conn = con3()
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute(query)
|
||||||
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
return cursor.lastrowid
|
return cursor.lastrowid
|
||||||
|
|
||||||
@ -210,4 +212,6 @@ def delete_habitTrackings(id: int):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
pass
|
habits = get_habits(1)
|
||||||
|
for habit in habits:
|
||||||
|
print(habit[6])
|
||||||
|
|||||||
@ -23,22 +23,25 @@ class Habit:
|
|||||||
slot: int
|
slot: int
|
||||||
percentage: int = 0
|
percentage: int = 0
|
||||||
|
|
||||||
|
|
||||||
def __post_init__(self):
|
def __post_init__(self):
|
||||||
self.fill_statistics()
|
self.fill_statistics()
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create(user_id: int, name: str, times: int, note: str | None = None, unit: int | None = 1):
|
def create(user_id: int, name: str, times: int, note: str | None = None, unit: int | None = 1):
|
||||||
slot = get_next_slot(user_id)
|
slot = get_next_slot(user_id)
|
||||||
id = create_habit(user_id, name, times, unit, slot, note)
|
id = create_habit(user_id, name, times, unit, slot, note)
|
||||||
return Habit(id, user_id, name, note, times, unit, slot)
|
return Habit(id, user_id, name, note, times, unit, slot)
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get(id: int):
|
def get(id: int):
|
||||||
habit = get_habit(id)
|
habit = get_habit(id)
|
||||||
habit = Habit(habit[0], habit[1], habit[2], habit[3], habit[4], habit[5], habit[6]) if habit else None
|
habit = Habit(habit[0], habit[1], habit[2], habit[3], habit[4], habit[5], habit[6]) if habit else None
|
||||||
|
|
||||||
return habit
|
return habit
|
||||||
|
|
||||||
|
|
||||||
def update(self, name: str=None, note: str=None, times: int=None, unit: int=None):
|
def update(self, name: str=None, note: str=None, times: int=None, unit: int=None):
|
||||||
update_habit(self.id, name, note, times, unit)
|
update_habit(self.id, name, note, times, unit)
|
||||||
if name is not None:
|
if name is not None:
|
||||||
@ -50,10 +53,12 @@ class Habit:
|
|||||||
if unit is not None:
|
if unit is not None:
|
||||||
self.unit = unit
|
self.unit = unit
|
||||||
|
|
||||||
|
|
||||||
# So sollte die Slots Liste aussehen damit es funktioniert
|
# So sollte die Slots Liste aussehen damit es funktioniert
|
||||||
#[(id, 1), (id, 2), (id, 3), (id, 4), (id, 5)]
|
#[(id, 1), (id, 2), (id, 3), (id, 4), (id, 5)]
|
||||||
def update_slot(self, new_slot: int):
|
def update_slot(self, new_slot: int):
|
||||||
slots = get_slots(self.user_id)
|
slots = get_slots(self.user_id)
|
||||||
|
print(slots)
|
||||||
if new_slot > self.slot:
|
if new_slot > self.slot:
|
||||||
slots = slots[self.slot:new_slot]
|
slots = slots[self.slot:new_slot]
|
||||||
for slot in slots:
|
for slot in slots:
|
||||||
@ -62,7 +67,7 @@ class Habit:
|
|||||||
slots = slots[new_slot-1:self.slot-1]
|
slots = slots[new_slot-1:self.slot-1]
|
||||||
for slot in slots:
|
for slot in slots:
|
||||||
update_slot(slot[0], slot[1]+1)
|
update_slot(slot[0], slot[1]+1)
|
||||||
self.slot = new_slot
|
update_slot(self.id, new_slot)
|
||||||
|
|
||||||
|
|
||||||
def delete(self):
|
def delete(self):
|
||||||
@ -106,5 +111,3 @@ class Habit:
|
|||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
self.percentage = int(count / self.times * 100)
|
self.percentage = int(count / self.times * 100)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user