This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import logging
|
||||
import streamlit as st
|
||||
from queries.connection import connection
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def get_all_weekly_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_weekly_analytics(end_date:str = 'now'):
|
||||
counter_id,
|
||||
sum(increment) as count
|
||||
FROM entries
|
||||
WHERE user_id = :user_id
|
||||
group by counter_id, strftime('%W', timestamp)
|
||||
)
|
||||
select
|
||||
@@ -35,12 +38,13 @@ def get_all_weekly_analytics(end_date:str = 'now'):
|
||||
left outer join stats t on s.w = t.w
|
||||
left join counters c on t.counter_id = c.id
|
||||
GROUP by s.w
|
||||
''', 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_weekly_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_weekly_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('%W', timestamp)
|
||||
)
|
||||
SELECT
|
||||
@@ -67,7 +72,7 @@ def get_weekly_analytics(counter_id:int, end_date:str = 'now'):
|
||||
coalesce(s.count, 0) as count
|
||||
FROM weeks as w
|
||||
LEFT JOIN stats as s on s.w = w.w
|
||||
''', 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
|
||||
Reference in New Issue
Block a user