reformating
This commit is contained in:
parent
7ad54ffb30
commit
e2dd7c5fdf
@ -102,7 +102,6 @@ def get_habits(list_id: int):
|
|||||||
|
|
||||||
|
|
||||||
def get_heatmap_value(user_id: int, days: int):
|
def get_heatmap_value(user_id: int, days: int):
|
||||||
# Berechnet das Datum, ab dem die Habits gezählt werden sollen
|
|
||||||
date = (datetime.now() - timedelta(days=days)).date()
|
date = (datetime.now() - timedelta(days=days)).date()
|
||||||
print(date)
|
print(date)
|
||||||
|
|
||||||
@ -121,23 +120,15 @@ def get_heatmap_value(user_id: int, days: int):
|
|||||||
|
|
||||||
conn = con3()
|
conn = con3()
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
# Execute the queries
|
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
all_habits = cursor.fetchall()
|
all_habits = cursor.fetchall()
|
||||||
cursor.execute(query2)
|
cursor.execute(query2)
|
||||||
checked_habits = cursor.fetchall()
|
checked_habits = cursor.fetchall()
|
||||||
|
|
||||||
# Close the database connection
|
|
||||||
count = len(all_habits)
|
|
||||||
print(count)
|
|
||||||
count2 = len(checked_habits)
|
|
||||||
print(count2)
|
|
||||||
|
|
||||||
# Close the database connection
|
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
# Calculate the percentage of checked Habits
|
# Calculate the percentage of checked Habits
|
||||||
|
count = len(all_habits)
|
||||||
|
count2 = len(checked_habits)
|
||||||
if count > 0:
|
if count > 0:
|
||||||
return int(count2 / count * 100)
|
return int(count2 / count * 100)
|
||||||
else:
|
else:
|
||||||
@ -198,8 +189,7 @@ def delete_habit(id: int):
|
|||||||
### HabitTrackings.py ###
|
### HabitTrackings.py ###
|
||||||
def create_habitTrackings(habit_id: int):
|
def create_habitTrackings(habit_id: int):
|
||||||
now = datetime.now().isoformat()
|
now = datetime.now().isoformat()
|
||||||
query = (
|
query = f"INSERT INTO habit_trackings (habit_id, created_at) VALUES ('{habit_id}','{now}');"
|
||||||
f"INSERT INTO habit_trackings (habit_id, created_at) VALUES ('{habit_id}','{now}');")
|
|
||||||
conn = con3()
|
conn = con3()
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
@ -240,16 +230,14 @@ def delete_habitTrackings(id: int):
|
|||||||
### HabitList.py ###
|
### HabitList.py ###
|
||||||
def create_habitList(user_id: int, name: str, description: str):
|
def create_habitList(user_id: int, name: str, description: str):
|
||||||
now = datetime.now().isoformat()
|
now = datetime.now().isoformat()
|
||||||
query = (
|
query = (f"INSERT INTO habit_lists (name, description, created_at, updated_at) "
|
||||||
f"INSERT INTO habit_lists (name, description, created_at, updated_at) VALUES ('{name}', '{description}', '{now}', '{now}');")
|
f"VALUES ('{name}', '{description}', '{now}', '{now}');")
|
||||||
|
|
||||||
conn = con3()
|
conn = con3()
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
|
query2 = (f"INSERT INTO habit_users (user_id, list_id, created_at, updated_at)"
|
||||||
query1 = f"INSERT INTO habit_users (user_id, list_id, created_at, updated_at) VALUES ('{user_id}', '{cursor.lastrowid}', '{now}', '{now}');"
|
f" VALUES ('{user_id}', '{cursor.lastrowid}', '{now}', '{now}');")
|
||||||
|
cursor.execute(query2)
|
||||||
cursor.execute(query1)
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
return cursor.lastrowid
|
return cursor.lastrowid
|
||||||
@ -266,7 +254,8 @@ def get_habitList(id: int):
|
|||||||
|
|
||||||
|
|
||||||
def get_habitLists(user_id: int):
|
def get_habitLists(user_id: int):
|
||||||
query = f"SELECT habit_lists.* FROM habit_lists JOIN habit_users ON habit_lists.id = habit_users.list_id WHERE habit_users.user_id = {user_id};"
|
query = (f"SELECT habit_lists.* FROM habit_lists JOIN habit_users ON habit_lists.id = habit_users.list_id "
|
||||||
|
f"WHERE habit_users.user_id = {user_id};")
|
||||||
conn = con3()
|
conn = con3()
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
|
|||||||
@ -4,7 +4,7 @@ from datetime import datetime
|
|||||||
|
|
||||||
from models.HabitTrackings import HabitTrackings
|
from models.HabitTrackings import HabitTrackings
|
||||||
from db.SQLiteClient import update_slot, create_habit, get_habit, delete_habit, get_next_slot, \
|
from db.SQLiteClient import update_slot, create_habit, get_habit, delete_habit, get_next_slot, \
|
||||||
get_habitTrackings_by_habit_id, get_slots, update_habit, get_habitList, get_habitLists
|
get_habitTrackings_by_habit_id, get_slots, update_habit, get_habitList
|
||||||
|
|
||||||
|
|
||||||
# Unit wird als Integers wie folgt gemessen:
|
# Unit wird als Integers wie folgt gemessen:
|
||||||
@ -76,37 +76,29 @@ class Habit:
|
|||||||
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):
|
||||||
trackings.append(HabitTrackings(rawTracking[0], rawTracking[1], datetime.strptime(rawTracking[2], "%Y-%m-%dT%H:%M:%S.%f")))
|
trackings.append(HabitTrackings(rawTracking[0], rawTracking[1],
|
||||||
|
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():
|
||||||
if tracking.created_at == datetime.today():
|
|
||||||
self.checked = True
|
|
||||||
|
|
||||||
# day
|
# day
|
||||||
if self.unit == 0:
|
if self.unit == 0:
|
||||||
if tracking.created_at == datetime.today():
|
if tracking.created_at == datetime.today():
|
||||||
# self.checked = True
|
|
||||||
count += 1
|
count += 1
|
||||||
# week
|
# week
|
||||||
elif self.unit == 1:
|
elif self.unit == 1:
|
||||||
if tracking.created_at.isocalendar()[1] == datetime.today().isocalendar()[1]:
|
if tracking.created_at.isocalendar()[1] == datetime.today().isocalendar()[1]:
|
||||||
# self.checked = True
|
|
||||||
count += 1
|
count += 1
|
||||||
# month
|
# month
|
||||||
elif self.unit == 2:
|
elif self.unit == 2:
|
||||||
if tracking.created_at.month == datetime.today().month:
|
if tracking.created_at.month == datetime.today().month:
|
||||||
# self.checked = True
|
|
||||||
count += 1
|
count += 1
|
||||||
# year
|
# year
|
||||||
elif self.unit == 3:
|
elif self.unit == 3:
|
||||||
if tracking.created_at.year == datetime.today().year:
|
if tracking.created_at.year == datetime.today().year:
|
||||||
# self.checked = True
|
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
self.percentage = int(count / self.times * 100)
|
self.percentage = int(count / self.times * 100)
|
||||||
@ -115,8 +107,11 @@ class Habit:
|
|||||||
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)
|
||||||
|
return HabitList(raw_habitLists[0], raw_habitLists[1], raw_habitLists[2],
|
||||||
return HabitList(raw_habitLists[0], raw_habitLists[1], raw_habitLists[2], datetime.strptime(raw_habitLists[3], "%Y-%m-%dT%H:%M:%S.%f"), datetime.strptime(raw_habitLists[4], "%Y-%m-%dT%H:%M:%S.%f")) if raw_habitLists else None
|
datetime.strptime(raw_habitLists[3], "%Y-%m-%dT%H:%M:%S.%f"),
|
||||||
|
datetime.strptime(raw_habitLists[4], "%Y-%m-%dT%H:%M:%S.%f")) \
|
||||||
|
if raw_habitLists else None
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
|
|
||||||
from db.SQLiteClient import delete_habitTrackings, create_habitList, get_habitList, get_habits, get_users
|
from db.SQLiteClient import delete_habitList, create_habitList, get_habitList, get_habits, get_users
|
||||||
from models.Habit import Habit
|
from models.Habit import Habit
|
||||||
from models.User import User
|
from models.User import User
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ class HabitList:
|
|||||||
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], 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
|
||||||
|
|
||||||
def delete(self):
|
def delete(self):
|
||||||
delete_habitTrackings(self.id)
|
delete_habitList(self.id)
|
||||||
|
|
||||||
def get_habits(self):
|
def get_habits(self):
|
||||||
raw_habits = get_habits(self.id)
|
raw_habits = get_habits(self.id)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user