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
import streamlit as st
from queries.connection import connection
logger = logging.getLogger(__name__)
def get_all_yearly_analytics(end_date:str = 'now'):
user_id = int(st.session_state.user_id)
try:
return connection().query('''
WITH RECURSIVE timeseries(d) AS (
@@ -23,6 +25,7 @@ def get_all_yearly_analytics(end_date:str = 'now'):
counter_id,
sum(increment) as count
FROM entries
WHERE user_id = :user_id
group by counter_id, strftime('%Y', timestamp)
)
select
@@ -35,12 +38,13 @@ def get_all_yearly_analytics(end_date:str = 'now'):
left outer join stats t on y.y = t.y
left join counters c on t.counter_id = c.id
GROUP by y.y
''', 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_yearly_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 (
@@ -60,6 +64,7 @@ def get_yearly_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 strftime('%Y', timestamp)
)
SELECT
@@ -67,7 +72,7 @@ def get_yearly_analytics(counter_id:int, end_date:str = 'now'):
coalesce(s.count, 0) as count
FROM years as m
LEFT JOIN stats as s on s.y = m.y
''', 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