Skip to content

Commit

Permalink
Look for workflow_save and workflow_enable workflow IDs in other places
Browse files Browse the repository at this point in the history
  • Loading branch information
JonCrawford committed Jul 16, 2024
1 parent f908ba2 commit 43e8d24
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Trigger dbt cloud job to prep views and build docs
on:
push:
branches: [ main ]
branches: [main]

jobs:
prep:
Expand Down
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ repos:
- id: check-script-semicolon
files: ^models
- id: check-model-has-properties-file
files: ^models
exclude: ^custom_tests
- id: check-script-has-no-table-name
files: ^models
- id: generate-model-properties-file
Expand Down
47 changes: 47 additions & 0 deletions custom_tests/workflow_enables_count_proportion.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
-- tests/workflow_enables_count_proportion.sql
{% set lookback_window_days = 30 %}
{% set min_enable_percent = 0.05 %}

WITH filtered_data AS (
SELECT
*
FROM
{{ ref('workflows') }}
WHERE
created_at_pt >= CURRENT_DATE - INTERVAL '30 days'
AND enable_count >= 1
),

total_count AS (
SELECT
COUNT(*) AS total
FROM
{{ ref('workflows') }}
),

filtered_count AS (
SELECT
COUNT(*) AS filtered
FROM
filtered_data
),

proportion_data AS (
SELECT
filtered::FLOAT / total AS proportion
FROM
(SELECT filtered FROM filtered_count) AS fc,
(SELECT total FROM total_count) AS tc
)

SELECT
'The proportion of workflows enabled in the last '
|| {{ lookback_window_days }}
|| ' days is below '
|| {{ min_enable_percent * 100 }}
|| '%' AS error_message,
proportion
FROM
proportion_data
WHERE
proportion < {{ min_enable_percent }}
43 changes: 43 additions & 0 deletions custom_tests/workflow_saves_count_proportion.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
-- tests/workflow_saves_count_proportion.sql
{% set lookback_window_days = 30 %}
{% set min_save_percent = 0.05 %}

WITH filtered_data AS (
SELECT
*
FROM
{{ ref('workflows') }}
WHERE
created_at_pt >= CURRENT_DATE - INTERVAL '{{ lookback_window_days }} days'
AND save_count >= 1
),

total_count AS (
SELECT
COUNT(*) AS total
FROM
{{ ref('workflows') }}
),

filtered_count AS (
SELECT
COUNT(*) AS filtered
FROM
filtered_data
),

proportion_data AS (
SELECT
filtered::FLOAT / total AS proportion
FROM
(SELECT filtered FROM filtered_count) AS fc,
(SELECT total FROM total_count) AS tc
)

SELECT
'The proportion of workflows saved in the last {{ lookback_window_days }} days is below {{ min_save_percent * 100 }}%' AS error_message,
proportion
FROM
proportion_data
WHERE
proportion < {{ min_save_percent }}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ WITH
-- URL parts
CASE WHEN page_location ILIKE 'http%'
THEN PARSE_URL(page_location)
ELSE NULL
ELSE NULL
END AS parsed_url,
parsed_url:host || '/' || parsed_url:path AS page_url,
parsed_url:host::STRING AS page_host,
Expand Down
8 changes: 8 additions & 0 deletions models/mesa/int_shop_weeks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
models:
- name: int_shop_weeks
columns:
- name: week
- name: shop_subdomain
- name: inc_amount
- name: first_week
1 change: 1 addition & 0 deletions models/mesa/marts/_workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ models:
description: The number of times the workflow has been enabled.
data_tests:
- not_null

- name: save_count
description: The number of times the workflow has been saved.
data_tests:
Expand Down
6 changes: 4 additions & 2 deletions models/mesa/marts/workflows.sql
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ workflow_saves AS (
SELECT
workflow_id,
COALESCE(
COUNT_IF(event_id IN ('workflow_save', 'dashboard_workflow_edit') AND properties_workflow_id = workflow_id),
COUNT_IF(event_id IN ('workflow_save', 'dashboard_workflow_edit') AND workflow_id IN (properties_workflow_id, properties_id)),
0)
AS save_count,
save_count > 0 AS has_edited_or_saved_workflow
Expand All @@ -106,7 +106,7 @@ workflow_enables AS (

SELECT
workflow_id,
COALESCE(COUNT_IF(event_id = 'workflow_enable' AND workflow_id = properties_workflow_id), 0) AS enable_count,
COALESCE(COUNT_IF(event_id = 'workflow_enable' AND workflow_id IN (properties_workflow_id, properties_id)), 0) AS enable_count,
enable_count > 0 AS has_enabled_workflow
FROM workflows
LEFT JOIN {{ ref('int_mesa_flow_events') }} USING (shop_subdomain)
Expand Down Expand Up @@ -153,3 +153,5 @@ final AS (

SELECT *
FROM final
WHERE created_at_pt > '2024-05-01'
AND save_count > 0
24 changes: 24 additions & 0 deletions models/mesa/stg_ga_session_starts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: 2
models:
- name: stg_ga_session_starts
columns:
- name: user_pseudo_id
- name: page_location
- name: event_timestamp_pt
- name: page_url
- name: page_host
- name: page_path
- name: page_query
- name: utm_campaign
- name: utm_medium
- name: utm_source
- name: device_category
- name: utm_content
- name: utm_term
- name: app_store_surface_detail
- name: app_store_surface_type
- name: app_store_surface_intra_position
- name: app_store_surface_inter_position
- name: app_store_locale
- name: shopify_id
- name: shop_subdomain
2 changes: 1 addition & 1 deletion seeds/staff_subdomains.csv
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ ahn-devstore
shoppad321
kalen-jordan-dev
anh-devstore
shoppad-jen
shoppad-jen

0 comments on commit 43e8d24

Please sign in to comment.