Compare commits

...

2 Commits

View File

@ -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