diff --git a/library/blocks/chinh_test_table.block.tpl.aml b/library/blocks/chinh_test_table.block.tpl.aml new file mode 100644 index 0000000..8bdd7fa --- /dev/null +++ b/library/blocks/chinh_test_table.block.tpl.aml @@ -0,0 +1,82 @@ +// This is a library dashboard block. For more details, visit https://docs.holistics.io/docs/canvas-dashboard/guides/build-library-blocks +@template( + title='Chinh Test Table', + description='', + thumbnail='', + metadata={ + group: '' + block_width: 1260 + block_height: 680 + } +) +Func block_chinh_test_table() { + VizBlock { + label: 'Table' + viz: DataTable { + dataset: ticket_23584 + fields: [ + VizFieldFull { + ref: r(chinh_dim_date.date) + format { + type: 'date' + } + uname: 'chinh_dim_date_date' + }, + VizFieldFull { + ref: r(chinh_dim_category.category) + format { + type: 'text' + } + uname: 'chinh_dim_category_category_1' + }, + VizFieldFull { + ref: r(ticket_23584, chinh_dim_category.active_category) + format { + type: 'number' + pattern: 'inherited' + } + hidden: true + }, + VizFieldFull { + ref: r(ticket_23584.total_amount) + format { + type: 'number' + pattern: 'inherited' + } + } + ] + settings { + show_row_number: true + sorts: [ + SortSetting { + key: 'chinh_dim_date_date' + direction: 'desc' + }, + SortSetting { + key: 'chinh_dim_category_category_1' + direction: 'asc' + } + ] + conditional_formats: [ + ConditionalFormat { + key: 'chinh_dim_date_date' + format: SingleFormat { + condition { + operator: 'before' + value: '2023-12-31' + } + text_color: '#BF0E08' + background_color: '#FAD2D1' + apply_to_row: true + } + } + ] + row_limit: 5000 + aggregate_awareness { + enabled: true + debug_comments: true + } + } + } + } +} \ No newline at end of file diff --git a/team-folders/Chinh/dashboards/chinh_sandbox.page.aml b/team-folders/Chinh/dashboards/chinh_sandbox.page.aml index 44140c0..f2f8c8c 100644 --- a/team-folders/Chinh/dashboards/chinh_sandbox.page.aml +++ b/team-folders/Chinh/dashboards/chinh_sandbox.page.aml @@ -1,27 +1,94 @@ +@template( + title='View Template', + description='', + thumbnail='', + metadata={ + } +) +Func view_template() { + TabLayout { + label: 'View 1' + tab tab1: CanvasLayout { + label: 'Tab 1' + width: 1300 + height: 1500 + grid_size: 20 + auto_expand_vertically: true + block v_0m6g { + position: pos(20, 100, 1260, 680) + layer: 1 + } + block f_nfvl { + position: pos(20, 20, 300, 80) + layer: 2 + } + block f_dtbw { + position: pos(340, 20, 300, 80) + layer: 3 + } + block v_sfkb { + position: pos(20, 800, 1260, 2000) + layer: 4 + } + mobile { + mode: 'auto' + } + } + tab tab2: CanvasLayout { + label: 'Tab 2' + width: 2000 + height: 800 + grid_size: 20 + auto_expand_vertically: true + mobile { + mode: 'auto' + } + } + } +} + Dashboard chinh_sandbox { title: 'Chinh Sandbox' description: '' - view: CanvasLayout { + // view: view_template() + view: TabLayout { label: 'View 1' - width: 1300 - height: 900 - grid_size: 20 - auto_expand_vertically: true - mobile { - mode: 'auto' - } - block v_0m6g { - position: pos(20, 100, 1260, 680) - layer: 1 - } - block f_nfvl { - position: pos(20, 20, 300, 80) - layer: 2 + tab tab1: CanvasLayout { + label: 'Tab 1' + width: 1300 + height: 1500 + grid_size: 20 + auto_expand_vertically: true + block v_0m6g { + position: pos(20, 100, 1260, 680) + layer: 1 + } + block f_nfvl { + position: pos(20, 20, 300, 80) + layer: 2 + } + block f_dtbw { + position: pos(340, 20, 300, 80) + layer: 3 + } + block v_sfkb { + position: pos(20, 800, 1260, 680) + layer: 4 + } + mobile { + mode: 'auto' + } } - block f_dtbw { - position: pos(340, 20, 300, 80) - layer: 3 + tab tab2: CanvasLayout { + label: 'Tab 2' + width: 2000 + height: 800 + grid_size: 20 + auto_expand_vertically: true + mobile { + mode: 'auto' + } } } @@ -51,6 +118,7 @@ Dashboard chinh_sandbox { type: 'number' pattern: 'inherited' } + hidden: true }, VizFieldFull { ref: r(ticket_23584.total_amount) @@ -95,7 +163,7 @@ Dashboard chinh_sandbox { } } block f_nfvl: FilterBlock { - label: 'Category' + label: 'All Category' type: 'field' source: FieldFilterSource { dataset: ticket_23584 @@ -118,6 +186,7 @@ Dashboard chinh_sandbox { value: [] } } + block v_sfkb: block_chinh_test_table() interactions: [ FilterInteraction { from: 'f_nfvl' diff --git a/team-folders/Chinh/dashboards/chinh_template.page.aml b/team-folders/Chinh/dashboards/chinh_template.page.aml new file mode 100644 index 0000000..f036a46 --- /dev/null +++ b/team-folders/Chinh/dashboards/chinh_template.page.aml @@ -0,0 +1,73 @@ +Dashboard chinh_template { + title: 'chinh_template' + description: '' + owner: 'chinh.dm@holistics.io' + + view: TabLayout { + label: 'View 1' + tab tab1: CanvasLayout { + label: 'Tab 1' + width: 1300 + height: 675 + grid_size: 25 + auto_expand_vertically: true + auto_expand_horizontally: true + block v_lm5d { + position: pos(25, 125, 1250, 525) + layer: 1 + } + block t_uu5o { + position: pos(25, 25, 425, 50) + layer: 2 + } + mobile { + mode: 'auto' + } + } + tab tab2: CanvasLayout { + label: 'Tab 2' + width: 1300 + height: 800 + grid_size: 20 + auto_expand_vertically: true + mobile { + mode: 'auto' + } + } + } + + theme: H.themes.vanilla + block v_lm5d: VizBlock { + label: 'Total Value by Month' + viz: AreaChart { + dataset: chinh_dynamic_dataset + x_axis: VizFieldFull { + ref: r(chinh_dynamic_dim_model.order_created_at) + transformation: 'datetrunc month' + format { + type: 'date' + pattern: 'LLL yyyy' + } + } + y_axis { + series { + field: r(chinh_dynamic_dataset.total_value) + settings { + color_palette: 0 + } + } + } + settings { + row_limit: 5000 + x_axis_show_null_datetime: false + aggregate_awareness { + enabled: true + debug_comments: true + } + } + } + } + block t_uu5o: TextBlock { + content: @md This is the template dashboard.;; + } +} \ No newline at end of file diff --git a/team-folders/Chinh/dashboards/derived_chinh_template.page.aml b/team-folders/Chinh/dashboards/derived_chinh_template.page.aml new file mode 100644 index 0000000..114c20e --- /dev/null +++ b/team-folders/Chinh/dashboards/derived_chinh_template.page.aml @@ -0,0 +1 @@ +PartialDashboard derived_chinh_template = chinh_template.extend({}) \ No newline at end of file diff --git a/team-folders/Chinh/datasets/chinh_23949_dataset.dataset.aml b/team-folders/Chinh/datasets/chinh_23949_dataset.dataset.aml new file mode 100644 index 0000000..9cee35d --- /dev/null +++ b/team-folders/Chinh/datasets/chinh_23949_dataset.dataset.aml @@ -0,0 +1,73 @@ +Dataset chinh_23949_dataset { + label: 'chinh_23949_dataset' + description: '' + data_source_name: 'demodb' + models: [ + chinh_23949 + ] + + relationships: [ + relationship(chinh_23949.user_agent_id - chinh_23949.user_agent_id, false) + ] + + dimension is_user_converted { + label: "Is User Converted" + type: "number" + hidden: false + description: "" + definition: @aql + dimensionalize( + count_if(chinh_23949.order_id is not null) + , chinh_23949.user_agent_id + ) + ;; + model: chinh_23949 + } + + metric conversion_rate { + label: "Conversion Rate" + type: "number" + hidden: false + description: "" + definition: @aql + safe_divide( + coalesce( + count_distinct(chinh_23949.user_agent_id) | where(chinh_23949.is_user_converted == 1) + , 0 + ) + , count_distinct(chinh_23949.user_agent_id) + ) + ;; + } + + metric list_user_id { + label: "List User Id" + type: "json" + description: "" + definition: @aql unique(chinh_23949.user_agent_id);; + } + + metric nominator { + label: "Nominator" + type: "number" + hidden: false + description: "" + definition: @aql coalesce(count_distinct(chinh_23949.user_agent_id) | where(chinh_23949.is_user_converted == 1), 0);; + } + + metric denominator { + label: "Denominator" + type: "number" + description: "" + definition: @aql count_distinct(chinh_23949.user_agent_id);; + } + metric old_conversion_rate { + label: "Old Conversion Rate" + type: "number" + description: "" + definition: @aql safe_divide( + count_distinct(chinh_23949.order_id) * 1.0, + count_distinct(chinh_23949.user_agent_id) +);; + } +} \ No newline at end of file diff --git a/team-folders/Chinh/datasets/ticket_23584.dataset.aml b/team-folders/Chinh/datasets/ticket_23584.dataset.aml index 970bb66..5a157b7 100644 --- a/team-folders/Chinh/datasets/ticket_23584.dataset.aml +++ b/team-folders/Chinh/datasets/ticket_23584.dataset.aml @@ -1,13 +1,21 @@ Dataset ticket_23584 { label: 'ticket_23584' - description: '' + description: ''' +In the dashboard, which includes a Category filter, only display categories that have had non-zero sales in the last 2 years, +so users aren't forced to scroll through outdated or irrelevant categories. + +"Unused categories" = categories with 0 total sales amount over the past 2 years +=> 1. Filtering logic: total sales amount over the past 2 years +=> 2. Roll it up to the Dim Category's grain +=> 3. Then apply a case when to take the categories' name, Active Category +''' data_source_name: 'demodb' models: [ chinh_dim_date, chinh_dim_category, chinh_dim_product, - chinh_fact_sales + chinh_fact_sales, ] relationships: [ @@ -19,19 +27,20 @@ Dataset ticket_23584 { metric total_amount { label: 'Total Amount' type: 'number' - definition: @aql sum(chinh_fact_sales.sales_amount) ;; + definition: @aql + coalesce(sum(chinh_fact_sales.sales_amount), 0) + ;; } - dimension products_ordered_within_2_years { + dimension amount_per_product_ordered_within_2_years { // calculated field model: chinh_dim_category - label: 'Products (ordered within 2 years)' + label: 'Amount per Products (ordered within 2 years)' type: 'number' definition: @aql dimensionalize( - chinh_fact_sales - | filter(chinh_fact_sales.created_at > @(last 2 years)) - | count(chinh_dim_product.product_id) - , chinh_dim_category.category_id + total_amount + | where(chinh_fact_sales.created_at > @(last 2 years)), + chinh_dim_category.category_id ) ;; } @@ -42,7 +51,9 @@ Dataset ticket_23584 { type: 'text' definition: @aql case( - when: chinh_dim_category.products_ordered_within_2_years > 0, then: chinh_dim_category.category, + when: chinh_dim_category.amount_per_product_ordered_within_2_years > 0, + then: chinh_dim_category.category, // category name + else: null ) ;; diff --git a/team-folders/Chinh/models/chinh_23949.model.aml b/team-folders/Chinh/models/chinh_23949.model.aml new file mode 100644 index 0000000..ebd8de0 --- /dev/null +++ b/team-folders/Chinh/models/chinh_23949.model.aml @@ -0,0 +1,77 @@ +Model chinh_23949 { + type: 'query' + label: 'Chinh 23949' + description: '' + data_source_name: 'demodb' + dimension user_agent_id { + label: 'User Agent Id' + type: 'text' + description: "" + hidden: false + definition: @sql {{ #SOURCE.user_agent_id }};; + primary_key: true + } + dimension event_name { + label: 'Event Name' + type: 'text' + hidden: false + definition: @sql {{ #SOURCE.event_name }};; + } + dimension order_id { + label: 'Order Id' + type: 'text' + hidden: false + definition: @sql {{ #SOURCE.order_id }};; + } + + owner: 'chinh.dm@holistics.io' + query: @sql + WITH raw_table AS ( + -- USER 1001 (Converter - Used Recs) + SELECT 'u_1001' AS user_agent_id, 'view_homepage' AS event_name, NULL AS order_id UNION ALL + SELECT 'u_1001', 'view_outfit_recommendation', NULL UNION ALL + SELECT 'u_1001', 'add_to_cart', NULL UNION ALL + SELECT 'u_1001', 'purchase', 'ord_5501' UNION ALL + + -- USER 1002 (Non-Converter - Browse Only) + SELECT 'u_1002', 'view_homepage', NULL UNION ALL + SELECT 'u_1002', 'search_items', NULL UNION ALL + + -- USER 1003 (Converter - Used Recs) + SELECT 'u_1003', 'view_outfit_recommendation', NULL UNION ALL + SELECT 'u_1003', 'add_to_cart', NULL UNION ALL + SELECT 'u_1003', 'purchase', 'ord_5502' UNION ALL + + -- USER 1004 (Converter - Direct Purchase, NO Recs) -> Excluded from Denominator (User Pool) + SELECT 'u_1004', 'view_homepage', NULL UNION ALL + SELECT 'u_1004', 'view_product', NULL UNION ALL + SELECT 'u_1004', 'purchase', 'ord_5503' UNION ALL + + -- USER 1005 (Non-Converter - High Intent, Used Recs) -> Included in Denominator, Excluded from Numerator (Order Count) + SELECT 'u_1005', 'complete_style_quiz', NULL UNION ALL + SELECT 'u_1005', 'view_outfit_recommendation', NULL UNION ALL + SELECT 'u_1005', 'add_to_cart', NULL UNION ALL + + -- USER 1006 (Converter - Used Recs) + SELECT 'u_1006', 'view_outfit_recommendation', NULL UNION ALL + SELECT 'u_1006', 'purchase', 'ord_5504' UNION ALL + + -- USER 1007 (Non-Converter - High Intent, Used Recs) + SELECT 'u_1007', 'view_outfit_recommendation', NULL UNION ALL + SELECT 'u_1007', 'view_product', NULL UNION ALL + + -- USER 1008 (Converter - Used Recs for a second time) + SELECT 'u_1008', 'view_product', NULL UNION ALL + SELECT 'u_1008', 'view_outfit_recommendation', NULL UNION ALL + SELECT 'u_1008', 'purchase', 'ord_5505' UNION ALL + + -- USER 1009 (Non-Converter - Did NOT use Recs) + SELECT 'u_1009', 'view_category_shoes', NULL UNION ALL + SELECT 'u_1009', 'view_product', NULL UNION ALL + SELECT 'u_1009', 'add_to_cart', NULL + ) + SELECT * FROM raw_table + ;; + models: [ + ] +} \ No newline at end of file