From a480a7e011b4fece84a9df19effc074f8f19ca47 Mon Sep 17 00:00:00 2001 From: Frank Bertsch Date: Thu, 11 Mar 2021 21:21:50 +0000 Subject: [PATCH] Use event_types for cohort analyses --- user_journey/user_journey.model.lkml | 43 +++++++--- .../clients_last_seen.view.lkml | 26 +++--- .../cohort_analysis/cohort_analysis.view.lkml | 29 ++++--- .../cohort_event_types.view.lkml | 81 +++++++++++++++++++ .../cohort_analysis/message_ids.view.lkml | 24 ------ user_journey/views/event_type.view.lkml | 1 + 6 files changed, 142 insertions(+), 62 deletions(-) create mode 100644 user_journey/views/cohort_analysis/cohort_event_types.view.lkml delete mode 100644 user_journey/views/cohort_analysis/message_ids.view.lkml diff --git a/user_journey/user_journey.model.lkml b/user_journey/user_journey.model.lkml index c1da764..3a9b883 100644 --- a/user_journey/user_journey.model.lkml +++ b/user_journey/user_journey.model.lkml @@ -75,10 +75,26 @@ explore: funnel_analysis { } explore: cohort_analysis { - view_label: " User-Days" + view_label: " User Properties" from: cohort - join: message_ids { - relationship: many_to_one + join: cohort_event_type_1 { + view_label: "Cohort 1" + relationship: one_to_one + type: cross + } + join: cohort_event_type_2 { + view_label: "Cohort 2" + relationship: one_to_one + type: cross + } + join: cohort_event_type_3 { + view_label: "Cohort 3" + relationship: one_to_one + type: cross + } + join: cohort_event_type_4 { + view_label: "Cohort 4" + relationship: one_to_one type: cross } join: days_since_message { @@ -86,7 +102,7 @@ explore: cohort_analysis { type: cross } join: clients_last_seen { - view_label: "Days of Use" + fields: [] relationship: one_to_one type: left_outer sql_on: ${cohort_analysis.sample_id} = ${clients_last_seen.sample_id} @@ -100,19 +116,28 @@ explore: cohort_analysis { filters: [ date: "14 days", days_since_message.time_period: "7", - message_ids.message_event: "ABOUT^_WELCOME - IMPRESSION", + cohort_event_type_1.event_type: "IMPRESSION", + cohort_event_type_1.message_id: "ABOUT^_WELCOME", ] } query: about_welcome_cohorts { - pivots: [message_ids.message_event] - dimensions: [days_since_message.days_since_message, message_ids.message_event] - measures: [clients_last_seen.average_days_of_use] + dimensions: [days_since_message.days_since_message] + measures: [ + cohort_event_type_1.average_days_of_use, + cohort_event_type_2.average_days_of_use, + cohort_event_type_3.average_days_of_use, + ] label: "About Welcome - Cohorts" description: "Average days of use for two weeks" filters: [ date: "21 days", days_since_message.time_period: "14", - message_ids.message_event: "ABOUT^_WELCOME - IMPRESSION,ABOUT^_WELCOME - CLICK^_BUTTON,ABOUT^_WELCOME - SESSION^_END" + cohort_event_type_1.event_type: "IMPRESSION", + cohort_event_type_1.message_id: "ABOUT^_WELCOME", + cohort_event_type_2.event_type: "CLICK^_BUTTON", + cohort_event_type_2.message_id: "ABOUT^_WELCOME", + cohort_event_type_3.event_type: "SESSION^_END", + cohort_event_type_3.message_id: "ABOUT^_WELCOME", ] limit: 100 } diff --git a/user_journey/views/cohort_analysis/clients_last_seen.view.lkml b/user_journey/views/cohort_analysis/clients_last_seen.view.lkml index 85da338..d0ed313 100644 --- a/user_journey/views/cohort_analysis/clients_last_seen.view.lkml +++ b/user_journey/views/cohort_analysis/clients_last_seen.view.lkml @@ -7,7 +7,15 @@ view: clients_last_seen { `moz-fx-data-shared-prod`.search.search_clients_last_seen AS clients_last_seen WHERE {% condition cohort_analysis.date %} CAST(DATE_SUB(clients_last_seen.submission_date, INTERVAL 56 DAY) AS TIMESTAMP) {% endcondition %} - OR clients_last_seen.submission_date = DATE_SUB(current_date, INTERVAL 2 DAY);; + OR clients_last_seen.submission_date = DATE_SUB(current_date, INTERVAL 2 DAY) + AND {% if days_since_message.days_since_message._is_selected %} + TRUE + {% else %} + ERROR(""" + Must use the days_since_mesage.days_since_message dimension in this explore. + This explore CROSS JOINS with all possible days. Unless we GROUP BY each of those days, + we'll get incorrect results for the outputted measures.""") + {% endif %};; } dimension: submission_date { @@ -52,20 +60,4 @@ view: clients_last_seen { sql: BIT_COUNT(${days_seen_bits}) ;; hidden: yes } - - measure: total_days_of_use { - type: sum - sql: ${days_of_use} ;; - filters: [ - cohort_analysis.completed_message_id_event: "yes" - ] - } - - measure: average_days_of_use { - type: average - sql: ${days_of_use} ;; - filters: [ - cohort_analysis.completed_message_id_event: "yes" - ] - } } diff --git a/user_journey/views/cohort_analysis/cohort_analysis.view.lkml b/user_journey/views/cohort_analysis/cohort_analysis.view.lkml index a53d690..3ceac40 100644 --- a/user_journey/views/cohort_analysis/cohort_analysis.view.lkml +++ b/user_journey/views/cohort_analysis/cohort_analysis.view.lkml @@ -8,11 +8,24 @@ view: cohort { sql: {% condition date %} CAST(cohort_analysis.submission_date AS TIMESTAMP) {% endcondition %} ;; } - dimension: completed_message_id_event { + dimension: completed_event_1 { type: yesno - sql: REGEXP_CONTAINS(${TABLE}.events, mozfun.event_analysis.create_funnel_regex([ - ${message_ids.match_string}], - True)) ;; + sql: REGEXP_CONTAINS(${TABLE}.events, ${cohort_event_type_1.match_string}) ;; + } + + dimension: completed_event_2 { + type: yesno + sql: REGEXP_CONTAINS(${TABLE}.events, ${cohort_event_type_2.match_string}) ;; + } + + dimension: completed_event_3 { + type: yesno + sql: REGEXP_CONTAINS(${TABLE}.events, ${cohort_event_type_3.match_string}) ;; + } + + dimension: completed_event_4 { + type: yesno + sql: REGEXP_CONTAINS(${TABLE}.events, ${cohort_event_type_4.match_string}) ;; } measure: total_user_days { @@ -20,13 +33,5 @@ view: cohort { hidden: yes } - measure: count_user_days_completed_message_id_event { - label: "Count of User-Days" - type: count - filters: { - field: completed_message_id_event - value: "yes" - } - } } diff --git a/user_journey/views/cohort_analysis/cohort_event_types.view.lkml b/user_journey/views/cohort_analysis/cohort_event_types.view.lkml new file mode 100644 index 0000000..91c0aed --- /dev/null +++ b/user_journey/views/cohort_analysis/cohort_event_types.view.lkml @@ -0,0 +1,81 @@ +include: "/user_journey/views/event_type.view.lkml" + +view: cohort_event_type_1 { + extends: [event_type] + + measure: total_days_of_use { + type: sum + sql: ${clients_last_seen.days_of_use} ;; + filters: [ + cohort_analysis.completed_event_1: "yes" + ] + } + + measure: average_days_of_use { + type: average + sql: ${clients_last_seen.days_of_use} ;; + filters: [ + cohort_analysis.completed_event_1: "yes" + ] + } +} + +view: cohort_event_type_2 { + extends: [event_type] + + measure: total_days_of_use { + type: sum + sql: ${clients_last_seen.days_of_use} ;; + filters: [ + cohort_analysis.completed_event_2: "yes" + ] + } + + measure: average_days_of_use { + type: average + sql: ${clients_last_seen.days_of_use} ;; + filters: [ + cohort_analysis.completed_event_2: "yes" + ] + } +} + +view: cohort_event_type_3 { + extends: [event_type] + + measure: total_days_of_use { + type: sum + sql: ${clients_last_seen.days_of_use} ;; + filters: [ + cohort_analysis.completed_event_3: "yes" + ] + } + + measure: average_days_of_use { + type: average + sql: ${clients_last_seen.days_of_use} ;; + filters: [ + cohort_analysis.completed_event_3: "yes" + ] + } +} + +view: cohort_event_type_4 { + extends: [event_type] + + measure: total_days_of_use { + type: sum + sql: ${clients_last_seen.days_of_use} ;; + filters: [ + cohort_analysis.completed_event_4: "yes" + ] + } + + measure: average_days_of_use { + type: average + sql: ${clients_last_seen.days_of_use} ;; + filters: [ + cohort_analysis.completed_event_4: "yes" + ] + } +} diff --git a/user_journey/views/cohort_analysis/message_ids.view.lkml b/user_journey/views/cohort_analysis/message_ids.view.lkml deleted file mode 100644 index 53827e6..0000000 --- a/user_journey/views/cohort_analysis/message_ids.view.lkml +++ /dev/null @@ -1,24 +0,0 @@ -view: message_ids { - derived_table: { - sql: - SELECT - CONCAT(category, ' - ', event) AS message_event, - mozfun.event_analysis.event_index_to_match_string(index) AS match_string, - FROM - mozdata.messaging_system.event_types event_types - WHERE - {% condition message_ids.message_event %} - CONCAT(event_types.category, ' - ', event_types.event) - {% endcondition %};; - } - - dimension: message_event { - type: string - sql: ${TABLE}.message_event ;; - } - - dimension: match_string { - hidden: yes - sql: ${TABLE}.match_string ;; - } -} diff --git a/user_journey/views/event_type.view.lkml b/user_journey/views/event_type.view.lkml index d1fde71..c92304f 100644 --- a/user_journey/views/event_type.view.lkml +++ b/user_journey/views/event_type.view.lkml @@ -139,5 +139,6 @@ view: event_type { dimension: match_string { hidden: yes sql: ${TABLE}.match_string ;; + primary_key: yes } }