Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
454ce33846
@ -40,7 +40,6 @@ class Habit:
|
|||||||
|
|
||||||
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:
|
||||||
@ -52,7 +51,6 @@ class Habit:
|
|||||||
if unit is not None:
|
if unit is not None:
|
||||||
self.unit = unit
|
self.unit = unit
|
||||||
|
|
||||||
|
|
||||||
def update_slot(self, new_slot: int):
|
def update_slot(self, new_slot: int):
|
||||||
slots = get_slots(self.list_id)
|
slots = get_slots(self.list_id)
|
||||||
if new_slot > self.slot:
|
if new_slot > self.slot:
|
||||||
@ -65,14 +63,12 @@ class Habit:
|
|||||||
update_slot(slot[0], slot[1]+1)
|
update_slot(slot[0], slot[1]+1)
|
||||||
update_slot(self.id, new_slot)
|
update_slot(self.id, new_slot)
|
||||||
|
|
||||||
|
|
||||||
def delete(self):
|
def delete(self):
|
||||||
slots = get_slots(self.list_id)[self.slot+1:]
|
slots = get_slots(self.list_id)[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)
|
||||||
delete_habit(self.id)
|
delete_habit(self.id)
|
||||||
|
|
||||||
|
|
||||||
def get_habitTrackings(self) -> list[HabitTrackings]:
|
def get_habitTrackings(self) -> list[HabitTrackings]:
|
||||||
trackings = []
|
trackings = []
|
||||||
for rawTracking in get_habitTrackings_by_habit_id(self.id):
|
for rawTracking in get_habitTrackings_by_habit_id(self.id):
|
||||||
@ -80,13 +76,13 @@ class Habit:
|
|||||||
datetime.strptime(rawTracking[2], "%Y-%m-%dT%H:%M:%S.%f")))
|
datetime.strptime(rawTracking[2], "%Y-%m-%dT%H:%M:%S.%f")))
|
||||||
return trackings
|
return trackings
|
||||||
|
|
||||||
|
|
||||||
def fill_statistics(self):
|
def fill_statistics(self):
|
||||||
count = 0
|
count = 0
|
||||||
|
self.checked = False
|
||||||
for tracking in self.get_habitTrackings():
|
for tracking in self.get_habitTrackings():
|
||||||
# day
|
# day
|
||||||
if self.unit == 0:
|
if self.unit == 0:
|
||||||
if tracking.created_at == datetime.today():
|
if tracking.created_at.date() == datetime.today().date():
|
||||||
count += 1
|
count += 1
|
||||||
# week
|
# week
|
||||||
elif self.unit == 1:
|
elif self.unit == 1:
|
||||||
@ -103,11 +99,9 @@ class Habit:
|
|||||||
|
|
||||||
self.percentage = int(count / self.times * 100)
|
self.percentage = int(count / self.times * 100)
|
||||||
|
|
||||||
|
|
||||||
def to_json(self):
|
def to_json(self):
|
||||||
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True, indent=4)
|
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True, indent=4)
|
||||||
|
|
||||||
|
|
||||||
def habit_list(self):
|
def habit_list(self):
|
||||||
from models.HabitList import HabitList
|
from models.HabitList import HabitList
|
||||||
raw_habitLists = get_habitList(self.list_id)
|
raw_habitLists = get_habitList(self.list_id)
|
||||||
|
|||||||
@ -33,14 +33,6 @@ class User(UserMixin):
|
|||||||
def delete(self):
|
def delete(self):
|
||||||
delete_user(self.id)
|
delete_user(self.id)
|
||||||
|
|
||||||
# def get_habits(self):
|
|
||||||
# raw_habits = get_habits(self.id)
|
|
||||||
# habits = []
|
|
||||||
# for habit in raw_habits:
|
|
||||||
# habit = Habit(habit[0], habit[1], habit[2], habit[3], habit[4], habit[5], habit[6])
|
|
||||||
# habits.append(habit)
|
|
||||||
# return habits
|
|
||||||
|
|
||||||
def get_habitLists(self):
|
def get_habitLists(self):
|
||||||
from models.HabitList import HabitList
|
from models.HabitList import HabitList
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user