-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from Artemis-xyz/son/chain-retention
Added Retention for Activity Monitor chains except solana
- Loading branch information
Showing
11 changed files
with
195 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
{% macro get_cohort_retention(chain) %} | ||
with | ||
min_date as ( | ||
select | ||
date_trunc('month', min(raw_date)) as first_month | ||
from {{ ref( "ez_" ~ chain ~ "_transactions") }} | ||
), | ||
base_table as( | ||
select | ||
date_trunc('month', raw_date) as base_month, | ||
from_address as address | ||
from {{ ref( "ez_" ~ chain ~ "_transactions") }} | ||
group by 1,2 | ||
), | ||
-- from user_cohorts onward, should be able to reuse ctes on any chain | ||
|
||
-- grab each users first action timestamp on chain | ||
user_cohorts as ( | ||
select | ||
address, | ||
min(base_month) as cohort_month | ||
from | ||
base_table | ||
group by 1 | ||
), | ||
|
||
--compute cohort size per distinct cohort period | ||
cohort_size as ( | ||
select | ||
cohort_month, | ||
count(distinct(address)) as cohort_size | ||
from | ||
user_cohorts | ||
group by 1 | ||
), | ||
|
||
-- determine if/ when users came back for another interaction based on period number | ||
following_months as ( | ||
select | ||
bt.address, | ||
timestampdiff(month, uc.cohort_month, bt.base_month) as month_number | ||
from | ||
base_table as bt | ||
inner join user_cohorts as uc on bt.address = uc.address | ||
where | ||
bt.base_month > uc.cohort_month | ||
group by | ||
bt.address, | ||
month_number | ||
), | ||
--aggregate and calcualte the retained user amount per time period per cohort | ||
retention_data as( | ||
select | ||
uc.cohort_month as cohort_month, | ||
fm.month_number, | ||
count(distinct(fm.address)) as retained_user_count | ||
from | ||
following_months as fm | ||
inner join user_cohorts as uc on fm.address = uc.address | ||
where | ||
cohort_month >= (select first_month from min_date) -- Grab data from the beginning of the month 24 months ago | ||
group by | ||
uc.cohort_month, | ||
fm.month_number | ||
) | ||
select | ||
'{{ chain }}' as chain, | ||
r.cohort_month, | ||
c.cohort_size, | ||
r.month_number, | ||
round(r.retained_user_count::numeric / c.cohort_size::numeric , 2) as retention_ratio | ||
from | ||
retention_data as r | ||
inner join cohort_size as c on r.cohort_month = c.cohort_month | ||
order by | ||
r.cohort_month, | ||
r.month_number | ||
|
||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{{ config(materialized="table", snowflake_warehouse="RETENTION") }} | ||
|
||
{{ | ||
dbt_utils.union_relations( | ||
relations=[ | ||
ref("ez_arbitrum_retention"), | ||
ref("ez_avalanche_retention"), | ||
ref("ez_base_retention"), | ||
ref("ez_bsc_retention"), | ||
ref("ez_ethereum_retention"), | ||
ref("ez_near_retention"), | ||
ref("ez_optimism_retention"), | ||
ref("ez_polygon_retention"), | ||
ref("ez_tron_retention") | ||
], | ||
) | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{{ | ||
config( | ||
materialized="table", | ||
snowflake_warehouse="arbitrum", | ||
database="arbitrum", | ||
schema="core", | ||
alias="ez_cohort_retention", | ||
) | ||
}} | ||
|
||
{{ get_cohort_retention("arbitrum") }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{{ | ||
config( | ||
materialized="table", | ||
snowflake_warehouse="avalanche", | ||
database="avalanche", | ||
schema="core", | ||
alias="ez_cohort_retention", | ||
) | ||
}} | ||
|
||
{{ get_cohort_retention("avalanche") }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{{ | ||
config( | ||
materialized="table", | ||
snowflake_warehouse="base", | ||
database="base", | ||
schema="core", | ||
alias="ez_cohort_retention", | ||
) | ||
}} | ||
|
||
{{ get_cohort_retention("base") }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{{ | ||
config( | ||
materialized="table", | ||
snowflake_warehouse="bsc", | ||
database="bsc", | ||
schema="core", | ||
alias="ez_cohort_retention", | ||
) | ||
}} | ||
|
||
{{ get_cohort_retention("bsc") }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{{ | ||
config( | ||
materialized="table", | ||
snowflake_warehouse="ethereum", | ||
database="ethereum", | ||
schema="core", | ||
alias="ez_cohort_retention", | ||
) | ||
}} | ||
|
||
{{ get_cohort_retention("ethereum") }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{{ | ||
config( | ||
materialized="table", | ||
snowflake_warehouse="near", | ||
database="near", | ||
schema="core", | ||
alias="ez_cohort_retention", | ||
) | ||
}} | ||
|
||
{{ get_cohort_retention("near") }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{{ | ||
config( | ||
materialized="table", | ||
snowflake_warehouse="optimism", | ||
database="optimism", | ||
schema="core", | ||
alias="ez_cohort_retention", | ||
) | ||
}} | ||
|
||
{{ get_cohort_retention("optimism") }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{{ | ||
config( | ||
materialized="table", | ||
snowflake_warehouse="polygon", | ||
database="polygon", | ||
schema="core", | ||
alias="ez_cohort_retention", | ||
) | ||
}} | ||
|
||
{{ get_cohort_retention("polygon") }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{{ | ||
config( | ||
materialized="table", | ||
snowflake_warehouse="tron", | ||
database="tron", | ||
schema="core", | ||
alias="ez_cohort_retention", | ||
) | ||
}} | ||
|
||
{{ get_cohort_retention("tron") }} |