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_monthly_analytics(end_date:str = 'now'):
|
||||
user_id = int(st.session_state.user_id)
|
||||
try:
|
||||
return connection().query('''
|
||||
WITH RECURSIVE timeseries(d) AS (
|
||||
@@ -26,6 +28,7 @@ def get_all_monthly_analytics(end_date:str = 'now'):
|
||||
counter_id,
|
||||
sum(increment) as count
|
||||
FROM entries
|
||||
WHERE user_id = :user_id
|
||||
group by counter_id, strftime('%m', timestamp), strftime('%Y', timestamp)
|
||||
)
|
||||
select
|
||||
@@ -38,12 +41,13 @@ def get_all_monthly_analytics(end_date:str = 'now'):
|
||||
left outer join stats t on m.m = t.m and m.y = t.y
|
||||
left join counters c on t.counter_id = c.id
|
||||
GROUP by m.m, m.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_monthly_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 (
|
||||
@@ -66,6 +70,7 @@ def get_monthly_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('%m', timestamp), strftime('%Y', timestamp)
|
||||
)
|
||||
SELECT
|
||||
@@ -73,7 +78,7 @@ def get_monthly_analytics(counter_id:int, end_date:str = 'now'):
|
||||
coalesce(s.count, 0) as count
|
||||
FROM months as m
|
||||
LEFT JOIN stats as s on s.m = m.m and 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
|
||||
Reference in New Issue
Block a user