diff --git a/app/charts/main.py b/app/charts/main.py index 98786a3..e90dbca 100644 --- a/app/charts/main.py +++ b/app/charts/main.py @@ -16,8 +16,33 @@ tags_count_path = os.path.join(analytics_path,'active_tags_count.sql') loops_count_path = os.path.join(analytics_path,'open_loops_count.sql') active_count_path = os.path.join(analytics_path,'modified_counts.sql') +created_count_path = os.path.join(analytics_path,'created_counts.sql') +completed_count_path = os.path.join(analytics_path,'completed_counts.sql') + +st.set_page_config(page_title="MY GTD DASHBOARD", layout="wide", initial_sidebar_state="collapsed", menu_items=None) + +st.header("🌏 Ken's GTD dashboard",divider="blue") + + + +@st.cache_data(ttl=datetime.timedelta(hours=1),max_entries=10) +def get_table(query): + return cur.sql(query).df() +def get_table_nocache(query): + return cur.sql(query).df() +obt=get_table("select * from obt") + + +with st.sidebar: + if st.button("force script reload"): + st.rerun() + + if st.button("force cache reload"): + st.cache_data.clear() + folders = obt['fld_folder_name'].drop_duplicates().to_list() + filter_folder = st.multiselect('folders',folders,default=folders) def highlight_cell(val): if val < 20: @@ -50,10 +75,6 @@ def highlight_row(row): else: return [''] * len(row) -st.set_page_config(page_title="MY GTD DASHBOARD", layout="wide", initial_sidebar_state="collapsed", menu_items=None) - -st.header("🌏 Ken's GTD dashboard",divider="blue") - tab1,tab2,tab3 = st.tabs(['🧑🏽‍💻 daily ops', @@ -62,105 +83,13 @@ def highlight_row(row): ]) -with tab2: - - - @st.cache_data(ttl=datetime.timedelta(hours=1),max_entries=10) - def get_table(query): - return cur.sql(query).df() - def get_table_nocache(query): - return cur.sql(query).df() - - - obt=get_table("select * from obt") - - - with st.sidebar: - if st.button("force script reload"): - st.rerun() - - if st.button("force cache reload"): - st.cache_data.clear() - folders = obt['fld_folder_name'].drop_duplicates().to_list() - filter_folder = st.multiselect('folders',folders,default=folders) - - - st.write("# at a glance") - st.write("## count of clarified and next action") - - - +with tab1: + st.write("# your main metrics") + st.write("*to answer the question, how munch do i have in my head?*") with open(tags_count_path, 'r') as f: tags_query=f.read() - - tags_count = get_table_nocache(tags_query) - try: - colored_tags_count = tags_count.style.map(highlight_text,subset=['clarification_progress']) - except Exception as e: - colored_tags_count = pd.DataFrame() - tags_count_final = colored_tags_count - - st.dataframe( - tags_count_final, - column_config={ - "clarification_progress": st.column_config.ProgressColumn( - "clarification_progress", - format="%f", - min_value=0, - max_value=100 - ), - }, - - hide_index=True, - use_container_width=True - ) - - - - - - - - st.write("# lvl1-lvl2 analytics") - st.write("## progress summary") - lvl1_lvl2_progress = get_table("select * from lvl1_lvl2_progress") - - filtered_lvl1_lvl2_progress = lvl1_lvl2_progress[lvl1_lvl2_progress['fld_folder_name'].isin(filter_folder)] - colored_lvl1_lvl2_progress = filtered_lvl1_lvl2_progress.style.map( - highlight_text,subset=['done_progress','clarify_progress'] - ).apply( - highlight_row,axis=1 - ) - final_lvl1_lvl2_progress = colored_lvl1_lvl2_progress - - st.dataframe( - final_lvl1_lvl2_progress, - column_config={ - "done_progress": st.column_config.ProgressColumn( - "done_progress", - format="%f", - min_value=0, - max_value=100 - ), - "clarify_progress": st.column_config.ProgressColumn( - "clarify_progress", - format="%f", - min_value=0, - max_value=100 - ) - }, - - hide_index=True, - use_container_width=True - ) - - - - -with tab1: - with open(loops_count_path, 'r') as f: loops_query=f.read() @@ -208,8 +137,7 @@ def get_table_nocache(query): today_avg = 8 # TODO : implement average count over dataset. delta_today = today_count - today_avg - st.write("# your main metrics") - st.write("*to answer the question, how munch do i have in my head?*") + col1,col2,col3,col4 = st.columns(4) with col1: st.metric( @@ -285,7 +213,48 @@ def get_table_nocache(query): delta_color="inverse" if clarifyme_count > 0 else "off", ) - st.write('# active plots') + st.divider() + + st.write("## count of clarified and next action") + + try: + colored_tags_count = tags_count.style.map(highlight_text,subset=['clarification_progress']) + except Exception as e: + colored_tags_count = pd.DataFrame() + tags_count_final = colored_tags_count + + st.dataframe( + tags_count_final, + column_config={ + "clarification_progress": st.column_config.ProgressColumn( + "clarification_progress", + format="%f", + min_value=0, + max_value=100 + ), + }, + + hide_index=True, + use_container_width=True + ) + + + + st.divider() + + + + +with tab2: + + + + + + st.write("# at a glance") + + + st.write('## your activities') today = datetime.datetime.now() this_week_begin = today - datetime.timedelta(days=today.weekday()) @@ -302,18 +271,143 @@ def get_table_nocache(query): with open(active_count_path, 'r') as f: active_query=f.read() + with open(created_count_path, 'r') as f: + created_count_path=f.read() + with open(completed_count_path, 'r') as f: + completed_count_path=f.read() 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*') - 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"), - ) + filtered_active_count['group'] = '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"), + # ) + + + created_count = get_table(created_count_path) + filtered_created_count = created_count[(created_count['key'] >= pd.to_datetime(start)) & (created_count['key'] <= pd.to_datetime(end))] + filtered_created_count.sort_values(by=['key'],ascending=True,inplace=True) + filtered_created_count['group'] = 'created' + + # alt_created_count = alt.Chart(filtered_created_count).mark_bar().encode( + # x=alt.X('day_of_year', sort=None, title="Day of week"), + # y=alt.Y('tasks_created', title="Count"), + # ) + + + completed_count = get_table(completed_count_path) + filtered_completed_count = completed_count[(completed_count['key'] >= pd.to_datetime(start)) & (completed_count['key'] <= pd.to_datetime(end))] + filtered_completed_count.sort_values(by=['key'],ascending=True,inplace=True) + filtered_completed_count['group'] = 'completed' + # alt_completed_count = alt.Chart(filtered_completed_count).mark_bar().encode( + # x=alt.X('day_of_year', sort=None, title="Day of week"), + # y=alt.Y('tasks_completed', title="Count"), + # ) + + + + melted_active_count = filtered_active_count.melt(id_vars=['key', 'group','day_of_year'], value_vars=['tasks_active'], var_name='task_type', value_name='count') + melted_created_count = filtered_created_count.melt(id_vars=['key', 'group','day_of_year'], value_vars=['tasks_created'], var_name='task_type', value_name='count') + melted_completed_count = filtered_completed_count.melt(id_vars=['key', 'group','day_of_year'], value_vars=['tasks_completed'], var_name='task_type', value_name='count') + activities = pd.concat([melted_active_count, melted_created_count, melted_completed_count], ignore_index=True) + + # base color "#6281c3", + # Define a color dictionary + color_dict = { + "active": "orange", # base color + "created": "red", + "completed": "#6281c3" + } + + activities_bar = alt.Chart(activities).mark_bar().encode( + x=alt.X('day_of_year:N',sort=None, title="Day of week"), + y=alt.Y('count:Q', title="Count"), + xOffset="group:N", + # color="group:N", + color=alt.Color("group:N", scale=alt.Scale(domain=list(color_dict.keys()), range=list(color_dict.values()))), + ) + + active_line = alt.Chart(melted_active_count).mark_line(color='orange').transform_window( + # The field to average + rolling_mean='mean(count)', + # The number of values before and after the current value to include. + frame=[-5, 0] + ).encode( + x=alt.X('day_of_year:N',sort=None, title="Day of week"), + y=alt.Y('rolling_mean:Q',title="active_average") + ) + + created_line = alt.Chart(melted_created_count).mark_line(color='red').transform_window( + # The field to average + rolling_mean='mean(count)', + # The number of values before and after the current value to include. + frame=[-5, 0] + ).encode( + x=alt.X('day_of_year:N',sort=None, title="Day of week"), + y=alt.Y('rolling_mean:Q',title="created_average") + ) + + completed_line = alt.Chart(melted_completed_count).mark_line(color='#6281c3').transform_window( + # The field to average + rolling_mean='mean(count)', + # The number of values before and after the current value to include. + frame=[-9, 0] + ).encode( + x=alt.X('day_of_year:N',sort=None, title="Day of week"), + y=alt.Y('rolling_mean:Q',title="completed_average") + ) + + + combo_activities = activities_bar+active_line+created_line+completed_line + st.write("## trends over week") + st.altair_chart(combo_activities,use_container_width=True) + + + st.divider() + + + + st.write("# lvl1-lvl2 analytics") + st.write("## progress summary") + lvl1_lvl2_progress = get_table("select * from lvl1_lvl2_progress") + + filtered_lvl1_lvl2_progress = lvl1_lvl2_progress[lvl1_lvl2_progress['fld_folder_name'].isin(filter_folder)] + colored_lvl1_lvl2_progress = filtered_lvl1_lvl2_progress.style.map( + highlight_text,subset=['done_progress','clarify_progress'] + ).apply( + highlight_row,axis=1 + ) + final_lvl1_lvl2_progress = colored_lvl1_lvl2_progress - st.altair_chart(alt_active_count, use_container_width=True) + st.dataframe( + final_lvl1_lvl2_progress, + column_config={ + "done_progress": st.column_config.ProgressColumn( + "done_progress", + format="%f", + min_value=0, + max_value=100 + ), + "clarify_progress": st.column_config.ProgressColumn( + "clarify_progress", + format="%f", + min_value=0, + max_value=100 + ) + }, + + hide_index=True, + use_container_width=True + ) + + + + + with tab3: