Add user specific profiles
Some checks failed
Run Tests / run-tests (push) Failing after 58s

This commit is contained in:
2026-04-28 21:04:52 +02:00
parent f750cfa8e1
commit bd9ff7191a
12 changed files with 294 additions and 36 deletions

View File

@@ -1,9 +1,11 @@
import logging
from queries.connection import connection
import streamlit as st
logger = logging.getLogger(__name__)
def get_all_daily_analytics(end_date:str = 'now'):
user_id = int(st.session_state.user_id)
try:
return connection().query('''
WITH RECURSIVE timeseries(d) AS (
@@ -19,6 +21,7 @@ def get_all_daily_analytics(end_date:str = 'now'):
counter_id,
sum(increment) as count
FROM entries
WHERE user_id = :user_id
group by counter_id, date(timestamp)
)
select
@@ -31,13 +34,14 @@ def get_all_daily_analytics(end_date:str = 'now'):
left outer join stats t on s.d = t.d
left join counters c on t.counter_id = c.id
GROUP by s.d
''', params={"end_date": end_date}, ttl=0)
''', params={"end_date": end_date, "user_id": user_id })
except Exception as e:
logger.error(e)
return None
def get_daily_analytics(counter_id:int, end_date:str = 'now'):
user_id = int(st.session_state.user_id)
try:
return connection().query('''
WITH RECURSIVE timeseries(d) AS (
@@ -53,6 +57,7 @@ def get_daily_analytics(counter_id:int, end_date:str = 'now'):
sum(increment) as count
FROM entries
where counter_id = :id
and user_id = :user_id
group by date(timestamp)
)
SELECT
@@ -60,7 +65,7 @@ def get_daily_analytics(counter_id:int, end_date:str = 'now'):
coalesce(s.count, 0) as count
FROM timeseries as t
LEFT JOIN stats as s on s.d = t.d
''', params={'id': counter_id, "end_date": end_date}, ttl=0)
''', params={'id': counter_id, "end_date": end_date, "user_id": user_id})
except Exception as e:
logger.error(e)
return None