Skip to content

Commit

Permalink
init setup for altair chart migration
Browse files Browse the repository at this point in the history
  • Loading branch information
luutuankiet committed Feb 22, 2024
1 parent 20da70d commit 2a7f484
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 33 deletions.
45 changes: 24 additions & 21 deletions app/charts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from helper.source_env import dbt_project_dir
import datetime
import re
import altair as alt

motherduck_token = os.environ.get("motherduck_token")
con = duckdb.connect(f'md:ticktick_gtd?motherduck_token={motherduck_token}')
Expand Down Expand Up @@ -198,7 +199,7 @@ def get_table_nocache(query):
group by due_date_id
"""
today_table = get_table_nocache(today_table_query).reset_index()
today_table = get_table_nocache(today_table_query).reset_index(drop=True)
overdue_count = today_table[today_table['due_date_id'] < pd.to_datetime(datetime.datetime.now().date())]
overdue_count = overdue_count['cnt'].iloc[0] if overdue_count.shape[0] > 0 else 0

Expand All @@ -220,9 +221,9 @@ def get_table_nocache(query):
with st.expander("query"):
debug_overdue_count=get_table_nocache("""
select
due_date_id,
td_created_time,
td_modified_time,
due_date_id::date as due_date_id,
td_created_time::timestamp as td_created_time,
td_modified_time::timestamp as td_modified_time,
fld_folder_name,
l_list_name,
td_title
Expand All @@ -233,23 +234,24 @@ def get_table_nocache(query):
and fld_folder_name not in ('🚀SOMEDAY lists','🛩Horizon of focus','💤on hold lists')
and l_list_name not like '%tickler note%'
and due_date_id is not null
""").reset_index()
""").reset_index(drop=True)
debug_overdue_count = debug_overdue_count[debug_overdue_count['due_date_id'] < pd.to_datetime(datetime.datetime.now().date())] if debug_overdue_count.shape[0] > 0 else None
debug_overdue_count.sort_values(by=['due_date_id','fld_folder_name','l_list_name'], ascending=True,inplace=True)
st.dataframe(debug_overdue_count,hide_index=True)
st.code(today_table_query)
with col2:
st.metric(
label="tasks lined up",
value=today_count,
delta = f"{delta_today} than usual {today_avg} tasks",
delta_color="inverse",
delta = f"{delta_today} than usual {today_avg} tasks" if today_count > 0 else "all's well.",
delta_color="inverse" if today_count > 0 else "off",
)
with st.expander("query"):
debug_today_count=get_table_nocache("""
select
due_date_id,
td_created_time,
td_modified_time,
due_date_id::date as due_date_id,
td_created_time::timestamp as td_created_time,
td_modified_time::timestamp as td_modified_time,
fld_folder_name,
l_list_name,
td_title
Expand All @@ -260,8 +262,9 @@ def get_table_nocache(query):
and fld_folder_name not in ('🚀SOMEDAY lists','🛩Horizon of focus','💤on hold lists')
and l_list_name not like '%tickler note%'
and due_date_id is not null
""").reset_index()
""").reset_index(drop=True)
debug_today_count = debug_today_count[debug_today_count['due_date_id'] == pd.to_datetime(datetime.datetime.now().date())]
debug_today_count.sort_values(by=['due_date_id','fld_folder_name','l_list_name'], ascending=True,inplace=True)
st.dataframe(debug_today_count,hide_index=True)
st.code(today_table_query)
# st.code(today_table)
Expand All @@ -270,16 +273,16 @@ def get_table_nocache(query):
st.metric(
"open loops",
value = counter,
delta = f"{counter_delta} than clarify",
delta_color="inverse",
delta = f"{counter_delta} than clarify" if counter > 0 else "all's well.",
delta_color="inverse" if counter > 0 else "off",
# help="compared to number of items to clarify"
)
with col4:
st.metric(
label="Clarifyme count",
value=clarifyme_count,
delta=f'{delta_clarifyme} than weekly average {clarifyme_avg}',
delta_color="inverse",
delta=f'{delta_clarifyme} than weekly average {clarifyme_avg}' if clarifyme_count > 0 else "all's well.",
delta_color="inverse" if clarifyme_count > 0 else "off",
)

st.write('# active plots')
Expand All @@ -303,14 +306,14 @@ def get_table_nocache(query):

active_count = get_table(active_query)
filtered_active_count = active_count[(active_count['key'] >= pd.to_datetime(start)) & (active_count['key'] <= pd.to_datetime(end))]
filtered_active_count.sort_values(by=['key'],ascending=True,inplace=True)
st.write('## 1. number of tasks you modified aka *actively working on*')
st.bar_chart(
filtered_active_count,
x='day_of_year',y='tasks_active'
)


alt_active_count = alt.Chart(filtered_active_count).mark_bar().encode(
x=alt.X('day_of_year', sort=None, title="Day of week"),
y=alt.Y('tasks_active', title="Count"),
)

st.altair_chart(alt_active_count, use_container_width=True)


with tab3:
Expand Down
29 changes: 29 additions & 0 deletions app/charts/tmp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt

# Sample data (replace with your actual data)
data = {'day_of_year': ['2022-01-01', '2022-01-02', '2022-01-03'],
'tasks_created': [10, 15, 20],
'tasks_modified': [5, 10, 15],
'tasks_completed': [2, 8, 12]}

df = pd.DataFrame(data)

# Convert 'day_of_year' to datetime for proper plotting
df['day_of_year'] = pd.to_datetime(df['day_of_year'].date())

# Streamlit App
st.title('Activity Counts Over Time')

# Line Chart
st.area_chart(df.set_index('day_of_year'))

# Data Table (optional)
st.write("Activity Data:")
st.dataframe(df)

# You can add more Streamlit components, sliders, date pickers, etc., for interactivity

# # Show the app
# st.show()
37 changes: 37 additions & 0 deletions dbt_project/analyses/completed_counts.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
with source as (

select
fld_folder_name,
l_list_name,
datepart('day',active) as day,
datepart('month',active) as month,
datepart('year',active) as year,
count(*) as cnt
from
(
select
td_completed_time::timestamp as active,
*
from obt) a
group by
fld_folder_name,
l_list_name,
datepart('day',active),
datepart('month',active),
datepart('year',active)
),

task_level as (
select count(*) as tasks_completed, day,month,year

from source group by day,month,year


)

select *
,(year||'-'||month||'-'||day)::date as key
,(year||'-'||month||'-'||day) as day_of_year
from task_level


37 changes: 37 additions & 0 deletions dbt_project/analyses/created_counts.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
with source as (

select
fld_folder_name,
l_list_name,
datepart('day',active) as day,
datepart('month',active) as month,
datepart('year',active) as year,
count(*) as cnt
from
(
select
td_created_time::timestamp as active,
*
from obt) a
group by
fld_folder_name,
l_list_name,
datepart('day',active),
datepart('month',active),
datepart('year',active)
),

task_level as (
select count(*) as tasks_created, day,month,year

from source group by day,month,year


)

select *
,(year||'-'||month||'-'||day)::date as key
,(year||'-'||month||'-'||day) as day_of_year
from task_level


12 changes: 0 additions & 12 deletions dbt_project/analyses/modified_counts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,3 @@ select *
from task_level



-- select
-- *

-- from source
-- order by day,month,year,fld_folder_name,l_list_name





-- select * from obt where td_modified_time::timestamp like '2024-01-09%'
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ sqlfluff-templater-dbt
sqlfmt==0.0.3
requests==2.26.0
streamlit==1.27.0
altair
# if encounter the charset / urllib warn : pip install --upgrade requests urllib3 chardet charset_normalizer

0 comments on commit 2a7f484

Please sign in to comment.