From 9a572a2b3140582f5a3fd9e5bd28553ef94ad5db Mon Sep 17 00:00:00 2001 From: Yapollon Date: Tue, 30 Jan 2024 11:17:34 +0100 Subject: [PATCH] You can now give back the heat map values for any given day! --- db/SQLiteClient.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/db/SQLiteClient.py b/db/SQLiteClient.py index ac03161..514a7d6 100644 --- a/db/SQLiteClient.py +++ b/db/SQLiteClient.py @@ -1,4 +1,4 @@ -from datetime import datetime +from datetime import datetime, timedelta import hashlib import sqlite3 @@ -100,6 +100,26 @@ def get_habits(user_id: int): return habits +def get_heatmap_value(user_id: int, days: int): + date = (datetime.now() - timedelta(days=days)).date() + print(date) + query = f"SELECT id FROM habits WHERE user_id = {user_id};" + query2 = f"SELECT habits.id FROM habits, habit_trackings WHERE habits.user_id = {user_id} AND habits.created_at LIKE '{date}%' AND habit_trackings.habit_id = habits.id;" + print(query2) + conn = con3() + cursor = conn.cursor() + cursor.execute(query) + all_habits = cursor.fetchall() + cursor.execute(query2) + checked_habits = cursor.fetchall() + count = len(all_habits) + print(count) + count2 = len(checked_habits) + print(count2) + conn.close() + return int(count2 / count * 100) + + def get_next_slot(user_id: int): query = f"SELECT slot FROM habits WHERE user_id = {user_id} ORDER BY slot DESC LIMIT 1;" conn = con3() @@ -187,3 +207,7 @@ def delete_habitTrackings(id: int): cursor.execute(query) conn.commit() conn.close() + + +if __name__ == "__main__": + pass \ No newline at end of file