This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user