From ed6a2f796355bb0e62bc781fc9ef0d9b1d48e5d7 Mon Sep 17 00:00:00 2001 From: luutuankiet Date: Sun, 25 Feb 2024 16:44:47 +0700 Subject: [PATCH] source metrics : added max column --- app/charts/main.py | 12 +++++++++++- dbt_project/analyses/completed_counts.sql | 24 ++++++++++++++--------- dbt_project/analyses/created_counts.sql | 24 ++++++++++++++--------- dbt_project/analyses/modified_counts.sql | 11 ++++++++--- 4 files changed, 49 insertions(+), 22 deletions(-) diff --git a/app/charts/main.py b/app/charts/main.py index 8025e6f..47c3b27 100644 --- a/app/charts/main.py +++ b/app/charts/main.py @@ -314,6 +314,14 @@ def highlight_row(row): completed_count_grouped['group'] = 'completed' + st.write(filtered_created_count) + st.write(created_count_grouped) + + + + + + # TODO : refactor using 3 queries to one cause they use same base except for the datestamp field. @@ -322,6 +330,7 @@ def highlight_row(row): melted_completed_count = completed_count_grouped.melt(id_vars=['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) + st.write(melted_created_count) # base color "#6281c3", # Define a color dictionary @@ -369,7 +378,8 @@ def highlight_row(row): 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) diff --git a/dbt_project/analyses/completed_counts.sql b/dbt_project/analyses/completed_counts.sql index d7cd795..0bd4355 100644 --- a/dbt_project/analyses/completed_counts.sql +++ b/dbt_project/analyses/completed_counts.sql @@ -3,22 +3,26 @@ with source as ( select coalesce(fld_folder_name,'Default') as fld_folder_name, coalesce(l_list_name,'Inbox') as l_list_name, -datepart('day',active) as day, -datepart('month',active) as month, -datepart('year',active) as year, +datepart('day',completed) as day, +datepart('month',completed) as month, +datepart('year',completed) as year, +max_day_completed_timestamp, count(*) as cnt from ( select -td_completed_time::timestamp as active, +td_completed_time::timestamp as completed, +max(completed) over(partition by fld_folder_name,l_list_name,datepart('day',completed),datepart('month',completed),datepart('year',completed)) as max_day_completed_timestamp, + * from obt) a group by fld_folder_name, l_list_name, -datepart('day',active), -datepart('month',active), -datepart('year',active) +datepart('day',completed), +datepart('month',completed), +datepart('year',completed), +max_day_completed_timestamp ), task_level as ( @@ -26,9 +30,11 @@ task_level as ( select fld_folder_name, l_list_name, -sum(cnt) as tasks_completed, day,month,year +sum(cnt) as tasks_completed, +max_day_completed_timestamp, + day,month,year -from source group by day,month,year,l_list_name,fld_folder_name +from source group by day,month,year,l_list_name,fld_folder_name,max_day_completed_timestamp ) diff --git a/dbt_project/analyses/created_counts.sql b/dbt_project/analyses/created_counts.sql index 6c7632d..8efd3df 100644 --- a/dbt_project/analyses/created_counts.sql +++ b/dbt_project/analyses/created_counts.sql @@ -3,22 +3,26 @@ with source as ( select coalesce(fld_folder_name,'Default') as fld_folder_name, coalesce(l_list_name,'Inbox') as l_list_name, -datepart('day',active) as day, -datepart('month',active) as month, -datepart('year',active) as year, +datepart('day',created) as day, +datepart('month',created) as month, +datepart('year',created) as year, +max_day_created_timestamp, count(*) as cnt from ( select -td_created_time::timestamp as active, +td_created_time::timestamp as created, +max(created) over(partition by fld_folder_name,l_list_name,datepart('day',created),datepart('month',created),datepart('year',created)) as max_day_created_timestamp, + * from obt) a group by fld_folder_name, l_list_name, -datepart('day',active), -datepart('month',active), -datepart('year',active) +datepart('day',created), +datepart('month',created), +datepart('year',created), +max_day_created_timestamp ), task_level as ( @@ -26,9 +30,11 @@ task_level as ( select fld_folder_name, l_list_name, -sum(cnt) as tasks_created, day,month,year +sum(cnt) as tasks_created, +max_day_created_timestamp, + day,month,year -from source group by day,month,year,l_list_name,fld_folder_name +from source group by day,month,year,l_list_name,fld_folder_name,max_day_created_timestamp ) diff --git a/dbt_project/analyses/modified_counts.sql b/dbt_project/analyses/modified_counts.sql index b6a63ab..bef7b3e 100644 --- a/dbt_project/analyses/modified_counts.sql +++ b/dbt_project/analyses/modified_counts.sql @@ -6,11 +6,13 @@ coalesce(l_list_name,'Inbox') as l_list_name, datepart('day',active) as day, datepart('month',active) as month, datepart('year',active) as year, +max_day_active_timestamp, count(*) as cnt from ( select td_modified_time::timestamp as active, +max(active) over(partition by fld_folder_name,l_list_name,datepart('day',active),datepart('month',active),datepart('year',active)) as max_day_active_timestamp, * from obt ) a @@ -19,16 +21,19 @@ fld_folder_name, l_list_name, datepart('day',active), datepart('month',active), -datepart('year',active) +datepart('year',active), +max_day_active_timestamp ), task_level as ( select fld_folder_name, l_list_name, -sum(cnt) as tasks_active, day,month,year +sum(cnt) as tasks_active, +max_day_active_timestamp, + day,month,year -from source group by day,month,year,l_list_name,fld_folder_name +from source group by day,month,year,l_list_name,fld_folder_name,max_day_active_timestamp )