From 78b0f30040e804b207656e6eac84787a5b4a8c8b Mon Sep 17 00:00:00 2001 From: marcus-snx Date: Tue, 29 Oct 2024 17:03:07 +0200 Subject: [PATCH 1/5] Add models --- ...perp_account_activity_arbitrum_mainnet.sql | 84 +++++++++++++++++++ .../marts/arbitrum/mainnet/perp/schema.yml | 27 ++++++ ...perp_account_activity_arbitrum_sepolia.sql | 84 +++++++++++++++++++ .../marts/arbitrum/sepolia/perp/schema.yml | 27 ++++++ ...fct_perp_account_activity_base_mainnet.sql | 84 +++++++++++++++++++ .../models/marts/base/mainnet/perp/schema.yml | 27 ++++++ ...fct_perp_account_activity_base_sepolia.sql | 84 +++++++++++++++++++ .../models/marts/base/sepolia/perp/schema.yml | 27 ++++++ 8 files changed, 444 insertions(+) create mode 100644 transformers/synthetix/models/marts/arbitrum/mainnet/perp/fct_perp_account_activity_arbitrum_mainnet.sql create mode 100644 transformers/synthetix/models/marts/arbitrum/sepolia/perp/fct_perp_account_activity_arbitrum_sepolia.sql create mode 100644 transformers/synthetix/models/marts/base/mainnet/perp/fct_perp_account_activity_base_mainnet.sql create mode 100644 transformers/synthetix/models/marts/base/sepolia/perp/fct_perp_account_activity_base_sepolia.sql diff --git a/transformers/synthetix/models/marts/arbitrum/mainnet/perp/fct_perp_account_activity_arbitrum_mainnet.sql b/transformers/synthetix/models/marts/arbitrum/mainnet/perp/fct_perp_account_activity_arbitrum_mainnet.sql new file mode 100644 index 00000000..6b5e24a0 --- /dev/null +++ b/transformers/synthetix/models/marts/arbitrum/mainnet/perp/fct_perp_account_activity_arbitrum_mainnet.sql @@ -0,0 +1,84 @@ +{{ config( + materialized = "view", + tags = ["perp", "account_activity", "arbitrum", "mainnet"] +) }} + +with active_accounts as ( + select distinct + date_trunc('day', ts) as activity_date, + account_id + from {{ ref('fct_perp_trades_arbitrum_mainnet') }} +), + +date_range as ( + select generate_series( + date(min(activity_date)), + date(max(activity_date)), + interval '1 day' + )::date as activity_date + from active_accounts +), + +active_accounts_daily as ( + select + date_range.activity_date, + count(distinct account_id) as active_accounts + from date_range + left join active_accounts using(activity_date) + group by date_range.activity_date +), + +active_accounts_monthly as ( + select + date_range.activity_date, + count(distinct active_accounts.account_id) as active_accounts + from date_range + left join active_accounts + on active_accounts.activity_date >= date_range.activity_date - interval '27 days' + and active_accounts.activity_date <= date_range.activity_date + group by date_range.activity_date +), + +new_accounts as ( + select + min(activity_date) as start_date, + account_id + from active_accounts + group by account_id +), + +new_accounts_daily as ( + select + activity_date, + count(account_id) as new_accounts + from date_range + left join new_accounts on activity_date = start_date + group by activity_date, start_date +), + +new_accounts_monthly as ( + select distinct + activity_date, + sum(new_accounts) over ( + order by activity_date + range between interval '27 days' preceding and current row + ) as new_accounts + from new_accounts_daily +) + +select + dr.activity_date as date, + dau.active_accounts as dau, + mau.active_accounts as mau, + new_accounts_daily.new_accounts as new_accounts_daily, + new_accounts_monthly.new_accounts as new_accounts_monthly +from date_range as dr +left join active_accounts_daily as dau + on dr.activity_date = dau.activity_date +left join active_accounts_monthly as mau + on dr.activity_date = mau.activity_date +left join new_accounts_daily + on dr.activity_date = new_accounts_daily.activity_date +left join new_accounts_monthly + on dr.activity_date = new_accounts_monthly.activity_date +order by date desc \ No newline at end of file diff --git a/transformers/synthetix/models/marts/arbitrum/mainnet/perp/schema.yml b/transformers/synthetix/models/marts/arbitrum/mainnet/perp/schema.yml index 23810db4..7bd60e42 100644 --- a/transformers/synthetix/models/marts/arbitrum/mainnet/perp/schema.yml +++ b/transformers/synthetix/models/marts/arbitrum/mainnet/perp/schema.yml @@ -1,4 +1,31 @@ models: + - name: fct_perp_account_activity_arbitrum_mainnet + columns: + - name: date + description: "Activity date" + data_type: date + tests: + - not_null + - name: dau + description: "Daily active users" + data_type: integer + tests: + - not_null + - name: mau + description: "Monthly active users" + data_type: integer + tests: + - not_null + - name: new_accounts_daily + description: "Daily new accounts" + data_type: integer + tests: + - not_null + - name: new_accounts_monthly + description: "Monthly new accounts" + data_type: integer + tests: + - not_null - name: fct_perp_interest_charged_arbitrum_mainnet columns: - name: id diff --git a/transformers/synthetix/models/marts/arbitrum/sepolia/perp/fct_perp_account_activity_arbitrum_sepolia.sql b/transformers/synthetix/models/marts/arbitrum/sepolia/perp/fct_perp_account_activity_arbitrum_sepolia.sql new file mode 100644 index 00000000..8231c815 --- /dev/null +++ b/transformers/synthetix/models/marts/arbitrum/sepolia/perp/fct_perp_account_activity_arbitrum_sepolia.sql @@ -0,0 +1,84 @@ +{{ config( + materialized = "view", + tags = ["perp", "account_activity", "arbitrum", "sepolia"] +) }} + +with active_accounts as ( + select distinct + date_trunc('day', ts) as activity_date, + account_id + from {{ ref('fct_perp_trades_arbitrum_sepolia') }} +), + +date_range as ( + select generate_series( + date(min(activity_date)), + date(max(activity_date)), + interval '1 day' + )::date as activity_date + from active_accounts +), + +active_accounts_daily as ( + select + date_range.activity_date, + count(distinct account_id) as active_accounts + from date_range + left join active_accounts using(activity_date) + group by date_range.activity_date +), + +active_accounts_monthly as ( + select + date_range.activity_date, + count(distinct active_accounts.account_id) as active_accounts + from date_range + left join active_accounts + on active_accounts.activity_date >= date_range.activity_date - interval '27 days' + and active_accounts.activity_date <= date_range.activity_date + group by date_range.activity_date +), + +new_accounts as ( + select + min(activity_date) as start_date, + account_id + from active_accounts + group by account_id +), + +new_accounts_daily as ( + select + activity_date, + count(account_id) as new_accounts + from date_range + left join new_accounts on activity_date = start_date + group by activity_date, start_date +), + +new_accounts_monthly as ( + select distinct + activity_date, + sum(new_accounts) over ( + order by activity_date + range between interval '27 days' preceding and current row + ) as new_accounts + from new_accounts_daily +) + +select + dr.activity_date as date, + dau.active_accounts as dau, + mau.active_accounts as mau, + new_accounts_daily.new_accounts as new_accounts_daily, + new_accounts_monthly.new_accounts as new_accounts_monthly +from date_range as dr +left join active_accounts_daily as dau + on dr.activity_date = dau.activity_date +left join active_accounts_monthly as mau + on dr.activity_date = mau.activity_date +left join new_accounts_daily + on dr.activity_date = new_accounts_daily.activity_date +left join new_accounts_monthly + on dr.activity_date = new_accounts_monthly.activity_date +order by date desc \ No newline at end of file diff --git a/transformers/synthetix/models/marts/arbitrum/sepolia/perp/schema.yml b/transformers/synthetix/models/marts/arbitrum/sepolia/perp/schema.yml index 134a94c4..91031943 100644 --- a/transformers/synthetix/models/marts/arbitrum/sepolia/perp/schema.yml +++ b/transformers/synthetix/models/marts/arbitrum/sepolia/perp/schema.yml @@ -1,4 +1,31 @@ models: + - name: fct_perp_account_activity_arbitrum_sepolia + columns: + - name: date + description: "Activity date" + data_type: date + tests: + - not_null + - name: dau + description: "Daily active users" + data_type: integer + tests: + - not_null + - name: mau + description: "Monthly active users" + data_type: integer + tests: + - not_null + - name: new_accounts_daily + description: "Daily new accounts" + data_type: integer + tests: + - not_null + - name: new_accounts_monthly + description: "Monthly new accounts" + data_type: integer + tests: + - not_null - name: fct_perp_interest_charged_arbitrum_sepolia columns: - name: id diff --git a/transformers/synthetix/models/marts/base/mainnet/perp/fct_perp_account_activity_base_mainnet.sql b/transformers/synthetix/models/marts/base/mainnet/perp/fct_perp_account_activity_base_mainnet.sql new file mode 100644 index 00000000..8c1cf4e2 --- /dev/null +++ b/transformers/synthetix/models/marts/base/mainnet/perp/fct_perp_account_activity_base_mainnet.sql @@ -0,0 +1,84 @@ +{{ config( + materialized = "view", + tags = ["perp", "account_activity", "base", "mainnet"] +) }} + +with active_accounts as ( + select distinct + date_trunc('day', ts) as activity_date, + account_id + from {{ ref('fct_perp_trades_base_mainnet') }} +), + +date_range as ( + select generate_series( + date(min(activity_date)), + date(max(activity_date)), + interval '1 day' + )::date as activity_date + from active_accounts +), + +active_accounts_daily as ( + select + date_range.activity_date, + count(distinct account_id) as active_accounts + from date_range + left join active_accounts using(activity_date) + group by date_range.activity_date +), + +active_accounts_monthly as ( + select + date_range.activity_date, + count(distinct active_accounts.account_id) as active_accounts + from date_range + left join active_accounts + on active_accounts.activity_date >= date_range.activity_date - interval '27 days' + and active_accounts.activity_date <= date_range.activity_date + group by date_range.activity_date +), + +new_accounts as ( + select + min(activity_date) as start_date, + account_id + from active_accounts + group by account_id +), + +new_accounts_daily as ( + select + activity_date, + count(account_id) as new_accounts + from date_range + left join new_accounts on activity_date = start_date + group by activity_date, start_date +), + +new_accounts_monthly as ( + select distinct + activity_date, + sum(new_accounts) over ( + order by activity_date + range between interval '27 days' preceding and current row + ) as new_accounts + from new_accounts_daily +) + +select + dr.activity_date as date, + dau.active_accounts as dau, + mau.active_accounts as mau, + new_accounts_daily.new_accounts as new_accounts_daily, + new_accounts_monthly.new_accounts as new_accounts_monthly +from date_range as dr +left join active_accounts_daily as dau + on dr.activity_date = dau.activity_date +left join active_accounts_monthly as mau + on dr.activity_date = mau.activity_date +left join new_accounts_daily + on dr.activity_date = new_accounts_daily.activity_date +left join new_accounts_monthly + on dr.activity_date = new_accounts_monthly.activity_date +order by date desc \ No newline at end of file diff --git a/transformers/synthetix/models/marts/base/mainnet/perp/schema.yml b/transformers/synthetix/models/marts/base/mainnet/perp/schema.yml index fe0a8ce1..209170a7 100644 --- a/transformers/synthetix/models/marts/base/mainnet/perp/schema.yml +++ b/transformers/synthetix/models/marts/base/mainnet/perp/schema.yml @@ -1,4 +1,31 @@ models: + - name: fct_perp_account_activity_base_mainnet + columns: + - name: date + description: "Activity date" + data_type: date + tests: + - not_null + - name: dau + description: "Daily active users" + data_type: integer + tests: + - not_null + - name: mau + description: "Monthly active users" + data_type: integer + tests: + - not_null + - name: new_accounts_daily + description: "Daily new accounts" + data_type: integer + tests: + - not_null + - name: new_accounts_monthly + description: "Monthly new accounts" + data_type: integer + tests: + - not_null - name: fct_perp_interest_charged_base_mainnet columns: - name: id diff --git a/transformers/synthetix/models/marts/base/sepolia/perp/fct_perp_account_activity_base_sepolia.sql b/transformers/synthetix/models/marts/base/sepolia/perp/fct_perp_account_activity_base_sepolia.sql new file mode 100644 index 00000000..39bcb29b --- /dev/null +++ b/transformers/synthetix/models/marts/base/sepolia/perp/fct_perp_account_activity_base_sepolia.sql @@ -0,0 +1,84 @@ +{{ config( + materialized = "view", + tags = ["perp", "account_activity", "base", "sepolia"] +) }} + +with active_accounts as ( + select distinct + date_trunc('day', ts) as activity_date, + account_id + from {{ ref('fct_perp_trades_base_sepolia') }} +), + +date_range as ( + select generate_series( + date(min(activity_date)), + date(max(activity_date)), + interval '1 day' + )::date as activity_date + from active_accounts +), + +active_accounts_daily as ( + select + date_range.activity_date, + count(distinct account_id) as active_accounts + from date_range + left join active_accounts using(activity_date) + group by date_range.activity_date +), + +active_accounts_monthly as ( + select + date_range.activity_date, + count(distinct active_accounts.account_id) as active_accounts + from date_range + left join active_accounts + on active_accounts.activity_date >= date_range.activity_date - interval '27 days' + and active_accounts.activity_date <= date_range.activity_date + group by date_range.activity_date +), + +new_accounts as ( + select + min(activity_date) as start_date, + account_id + from active_accounts + group by account_id +), + +new_accounts_daily as ( + select + activity_date, + count(account_id) as new_accounts + from date_range + left join new_accounts on activity_date = start_date + group by activity_date, start_date +), + +new_accounts_monthly as ( + select distinct + activity_date, + sum(new_accounts) over ( + order by activity_date + range between interval '27 days' preceding and current row + ) as new_accounts + from new_accounts_daily +) + +select + dr.activity_date as date, + dau.active_accounts as dau, + mau.active_accounts as mau, + new_accounts_daily.new_accounts as new_accounts_daily, + new_accounts_monthly.new_accounts as new_accounts_monthly +from date_range as dr +left join active_accounts_daily as dau + on dr.activity_date = dau.activity_date +left join active_accounts_monthly as mau + on dr.activity_date = mau.activity_date +left join new_accounts_daily + on dr.activity_date = new_accounts_daily.activity_date +left join new_accounts_monthly + on dr.activity_date = new_accounts_monthly.activity_date +order by date desc \ No newline at end of file diff --git a/transformers/synthetix/models/marts/base/sepolia/perp/schema.yml b/transformers/synthetix/models/marts/base/sepolia/perp/schema.yml index bef97ab0..04c582ca 100644 --- a/transformers/synthetix/models/marts/base/sepolia/perp/schema.yml +++ b/transformers/synthetix/models/marts/base/sepolia/perp/schema.yml @@ -1,4 +1,31 @@ models: + - name: fct_perp_account_activity_base_sepolia + columns: + - name: date + description: "Activity date" + data_type: date + tests: + - not_null + - name: dau + description: "Daily active users" + data_type: integer + tests: + - not_null + - name: mau + description: "Monthly active users" + data_type: integer + tests: + - not_null + - name: new_accounts_daily + description: "Daily new accounts" + data_type: integer + tests: + - not_null + - name: new_accounts_monthly + description: "Monthly new accounts" + data_type: integer + tests: + - not_null - name: fct_perp_interest_charged_base_sepolia columns: - name: id From ad9366eeec7686cfdecf38baaa780f9e68574076 Mon Sep 17 00:00:00 2001 From: marcus-snx Date: Tue, 29 Oct 2024 18:18:19 +0200 Subject: [PATCH 2/5] Fix linting --- ...perp_account_activity_arbitrum_mainnet.sql | 65 ++++++++++--------- .../marts/arbitrum/mainnet/perp/schema.yml | 2 +- ...perp_account_activity_arbitrum_sepolia.sql | 65 ++++++++++--------- .../marts/arbitrum/sepolia/perp/schema.yml | 2 +- ...fct_perp_account_activity_base_mainnet.sql | 65 ++++++++++--------- .../models/marts/base/mainnet/perp/schema.yml | 2 +- ...fct_perp_account_activity_base_sepolia.sql | 65 ++++++++++--------- 7 files changed, 143 insertions(+), 123 deletions(-) diff --git a/transformers/synthetix/models/marts/arbitrum/mainnet/perp/fct_perp_account_activity_arbitrum_mainnet.sql b/transformers/synthetix/models/marts/arbitrum/mainnet/perp/fct_perp_account_activity_arbitrum_mainnet.sql index 6b5e24a0..2317c3aa 100644 --- a/transformers/synthetix/models/marts/arbitrum/mainnet/perp/fct_perp_account_activity_arbitrum_mainnet.sql +++ b/transformers/synthetix/models/marts/arbitrum/mainnet/perp/fct_perp_account_activity_arbitrum_mainnet.sql @@ -11,31 +11,35 @@ with active_accounts as ( ), date_range as ( - select generate_series( - date(min(activity_date)), - date(max(activity_date)), - interval '1 day' - )::date as activity_date - from active_accounts + select + generate_series( + date(min(activity_date)), + date(max(activity_date)), + interval '1 day' + )::date as activity_date + from active_accounts ), active_accounts_daily as ( - select - date_range.activity_date, - count(distinct account_id) as active_accounts - from date_range - left join active_accounts using(activity_date) - group by date_range.activity_date + select + date_range.activity_date, + count(distinct active_accounts.account_id) as active_accounts + from date_range + left join active_accounts + on date_range.activity_date = active_accounts.activity_date + group by date_range.activity_date ), active_accounts_monthly as ( - select + select date_range.activity_date, count(distinct active_accounts.account_id) as active_accounts from date_range - left join active_accounts - on active_accounts.activity_date >= date_range.activity_date - interval '27 days' - and active_accounts.activity_date <= date_range.activity_date + left join active_accounts + on + date_range.activity_date - interval '27 days' + <= active_accounts.activity_date + and date_range.activity_date >= active_accounts.activity_date group by date_range.activity_date ), @@ -45,40 +49,41 @@ new_accounts as ( account_id from active_accounts group by account_id -), +), new_accounts_daily as ( select - activity_date, - count(account_id) as new_accounts + date_range.activity_date, + count(new_accounts.account_id) as new_accounts from date_range - left join new_accounts on activity_date = start_date - group by activity_date, start_date + left join new_accounts + on date_range.activity_date = new_accounts.start_date + group by date_range.activity_date, new_accounts.start_date ), new_accounts_monthly as ( select distinct - activity_date, - sum(new_accounts) over ( - order by activity_date - range between interval '27 days' preceding and current row - ) as new_accounts - from new_accounts_daily + activity_date, + sum(new_accounts) over ( + order by activity_date + range between interval '27 days' preceding and current row + ) as new_accounts + from new_accounts_daily ) select - dr.activity_date as date, + dr.activity_date, dau.active_accounts as dau, mau.active_accounts as mau, new_accounts_daily.new_accounts as new_accounts_daily, new_accounts_monthly.new_accounts as new_accounts_monthly from date_range as dr left join active_accounts_daily as dau - on dr.activity_date = dau.activity_date + on dr.activity_date = dau.activity_date left join active_accounts_monthly as mau on dr.activity_date = mau.activity_date left join new_accounts_daily on dr.activity_date = new_accounts_daily.activity_date left join new_accounts_monthly on dr.activity_date = new_accounts_monthly.activity_date -order by date desc \ No newline at end of file +order by activity_date desc \ No newline at end of file diff --git a/transformers/synthetix/models/marts/arbitrum/mainnet/perp/schema.yml b/transformers/synthetix/models/marts/arbitrum/mainnet/perp/schema.yml index 7bd60e42..3802ac5e 100644 --- a/transformers/synthetix/models/marts/arbitrum/mainnet/perp/schema.yml +++ b/transformers/synthetix/models/marts/arbitrum/mainnet/perp/schema.yml @@ -1,7 +1,7 @@ models: - name: fct_perp_account_activity_arbitrum_mainnet columns: - - name: date + - name: activity_date description: "Activity date" data_type: date tests: diff --git a/transformers/synthetix/models/marts/arbitrum/sepolia/perp/fct_perp_account_activity_arbitrum_sepolia.sql b/transformers/synthetix/models/marts/arbitrum/sepolia/perp/fct_perp_account_activity_arbitrum_sepolia.sql index 8231c815..076635ff 100644 --- a/transformers/synthetix/models/marts/arbitrum/sepolia/perp/fct_perp_account_activity_arbitrum_sepolia.sql +++ b/transformers/synthetix/models/marts/arbitrum/sepolia/perp/fct_perp_account_activity_arbitrum_sepolia.sql @@ -11,31 +11,35 @@ with active_accounts as ( ), date_range as ( - select generate_series( - date(min(activity_date)), - date(max(activity_date)), - interval '1 day' - )::date as activity_date - from active_accounts + select + generate_series( + date(min(activity_date)), + date(max(activity_date)), + interval '1 day' + )::date as activity_date + from active_accounts ), active_accounts_daily as ( - select - date_range.activity_date, - count(distinct account_id) as active_accounts - from date_range - left join active_accounts using(activity_date) - group by date_range.activity_date + select + date_range.activity_date, + count(distinct active_accounts.account_id) as active_accounts + from date_range + left join active_accounts + on date_range.activity_date = active_accounts.activity_date + group by date_range.activity_date ), active_accounts_monthly as ( - select + select date_range.activity_date, count(distinct active_accounts.account_id) as active_accounts from date_range - left join active_accounts - on active_accounts.activity_date >= date_range.activity_date - interval '27 days' - and active_accounts.activity_date <= date_range.activity_date + left join active_accounts + on + date_range.activity_date - interval '27 days' + <= active_accounts.activity_date + and date_range.activity_date >= active_accounts.activity_date group by date_range.activity_date ), @@ -45,40 +49,41 @@ new_accounts as ( account_id from active_accounts group by account_id -), +), new_accounts_daily as ( select - activity_date, - count(account_id) as new_accounts + date_range.activity_date, + count(new_accounts.account_id) as new_accounts from date_range - left join new_accounts on activity_date = start_date - group by activity_date, start_date + left join new_accounts + on date_range.activity_date = new_accounts.start_date + group by date_range.activity_date, new_accounts.start_date ), new_accounts_monthly as ( select distinct - activity_date, - sum(new_accounts) over ( - order by activity_date - range between interval '27 days' preceding and current row - ) as new_accounts - from new_accounts_daily + activity_date, + sum(new_accounts) over ( + order by activity_date + range between interval '27 days' preceding and current row + ) as new_accounts + from new_accounts_daily ) select - dr.activity_date as date, + dr.activity_date, dau.active_accounts as dau, mau.active_accounts as mau, new_accounts_daily.new_accounts as new_accounts_daily, new_accounts_monthly.new_accounts as new_accounts_monthly from date_range as dr left join active_accounts_daily as dau - on dr.activity_date = dau.activity_date + on dr.activity_date = dau.activity_date left join active_accounts_monthly as mau on dr.activity_date = mau.activity_date left join new_accounts_daily on dr.activity_date = new_accounts_daily.activity_date left join new_accounts_monthly on dr.activity_date = new_accounts_monthly.activity_date -order by date desc \ No newline at end of file +order by activity_date desc \ No newline at end of file diff --git a/transformers/synthetix/models/marts/arbitrum/sepolia/perp/schema.yml b/transformers/synthetix/models/marts/arbitrum/sepolia/perp/schema.yml index 91031943..a13a1522 100644 --- a/transformers/synthetix/models/marts/arbitrum/sepolia/perp/schema.yml +++ b/transformers/synthetix/models/marts/arbitrum/sepolia/perp/schema.yml @@ -1,7 +1,7 @@ models: - name: fct_perp_account_activity_arbitrum_sepolia columns: - - name: date + - name: activity_date description: "Activity date" data_type: date tests: diff --git a/transformers/synthetix/models/marts/base/mainnet/perp/fct_perp_account_activity_base_mainnet.sql b/transformers/synthetix/models/marts/base/mainnet/perp/fct_perp_account_activity_base_mainnet.sql index 8c1cf4e2..a31f4a9f 100644 --- a/transformers/synthetix/models/marts/base/mainnet/perp/fct_perp_account_activity_base_mainnet.sql +++ b/transformers/synthetix/models/marts/base/mainnet/perp/fct_perp_account_activity_base_mainnet.sql @@ -11,31 +11,35 @@ with active_accounts as ( ), date_range as ( - select generate_series( - date(min(activity_date)), - date(max(activity_date)), - interval '1 day' - )::date as activity_date - from active_accounts + select + generate_series( + date(min(activity_date)), + date(max(activity_date)), + interval '1 day' + )::date as activity_date + from active_accounts ), active_accounts_daily as ( - select - date_range.activity_date, - count(distinct account_id) as active_accounts - from date_range - left join active_accounts using(activity_date) - group by date_range.activity_date + select + date_range.activity_date, + count(distinct active_accounts.account_id) as active_accounts + from date_range + left join active_accounts + on date_range.activity_date = active_accounts.activity_date + group by date_range.activity_date ), active_accounts_monthly as ( - select + select date_range.activity_date, count(distinct active_accounts.account_id) as active_accounts from date_range - left join active_accounts - on active_accounts.activity_date >= date_range.activity_date - interval '27 days' - and active_accounts.activity_date <= date_range.activity_date + left join active_accounts + on + date_range.activity_date - interval '27 days' + <= active_accounts.activity_date + and date_range.activity_date >= active_accounts.activity_date group by date_range.activity_date ), @@ -45,40 +49,41 @@ new_accounts as ( account_id from active_accounts group by account_id -), +), new_accounts_daily as ( select - activity_date, - count(account_id) as new_accounts + date_range.activity_date, + count(new_accounts.account_id) as new_accounts from date_range - left join new_accounts on activity_date = start_date - group by activity_date, start_date + left join new_accounts + on date_range.activity_date = new_accounts.start_date + group by date_range.activity_date, new_accounts.start_date ), new_accounts_monthly as ( select distinct - activity_date, - sum(new_accounts) over ( - order by activity_date - range between interval '27 days' preceding and current row - ) as new_accounts - from new_accounts_daily + activity_date, + sum(new_accounts) over ( + order by activity_date + range between interval '27 days' preceding and current row + ) as new_accounts + from new_accounts_daily ) select - dr.activity_date as date, + dr.activity_date, dau.active_accounts as dau, mau.active_accounts as mau, new_accounts_daily.new_accounts as new_accounts_daily, new_accounts_monthly.new_accounts as new_accounts_monthly from date_range as dr left join active_accounts_daily as dau - on dr.activity_date = dau.activity_date + on dr.activity_date = dau.activity_date left join active_accounts_monthly as mau on dr.activity_date = mau.activity_date left join new_accounts_daily on dr.activity_date = new_accounts_daily.activity_date left join new_accounts_monthly on dr.activity_date = new_accounts_monthly.activity_date -order by date desc \ No newline at end of file +order by activity_date desc \ No newline at end of file diff --git a/transformers/synthetix/models/marts/base/mainnet/perp/schema.yml b/transformers/synthetix/models/marts/base/mainnet/perp/schema.yml index 209170a7..3f326992 100644 --- a/transformers/synthetix/models/marts/base/mainnet/perp/schema.yml +++ b/transformers/synthetix/models/marts/base/mainnet/perp/schema.yml @@ -1,7 +1,7 @@ models: - name: fct_perp_account_activity_base_mainnet columns: - - name: date + - name: activity_date description: "Activity date" data_type: date tests: diff --git a/transformers/synthetix/models/marts/base/sepolia/perp/fct_perp_account_activity_base_sepolia.sql b/transformers/synthetix/models/marts/base/sepolia/perp/fct_perp_account_activity_base_sepolia.sql index 39bcb29b..9930ff26 100644 --- a/transformers/synthetix/models/marts/base/sepolia/perp/fct_perp_account_activity_base_sepolia.sql +++ b/transformers/synthetix/models/marts/base/sepolia/perp/fct_perp_account_activity_base_sepolia.sql @@ -11,31 +11,35 @@ with active_accounts as ( ), date_range as ( - select generate_series( - date(min(activity_date)), - date(max(activity_date)), - interval '1 day' - )::date as activity_date - from active_accounts + select + generate_series( + date(min(activity_date)), + date(max(activity_date)), + interval '1 day' + )::date as activity_date + from active_accounts ), active_accounts_daily as ( - select - date_range.activity_date, - count(distinct account_id) as active_accounts - from date_range - left join active_accounts using(activity_date) - group by date_range.activity_date + select + date_range.activity_date, + count(distinct active_accounts.account_id) as active_accounts + from date_range + left join active_accounts + on date_range.activity_date = active_accounts.activity_date + group by date_range.activity_date ), active_accounts_monthly as ( - select + select date_range.activity_date, count(distinct active_accounts.account_id) as active_accounts from date_range - left join active_accounts - on active_accounts.activity_date >= date_range.activity_date - interval '27 days' - and active_accounts.activity_date <= date_range.activity_date + left join active_accounts + on + date_range.activity_date - interval '27 days' + <= active_accounts.activity_date + and date_range.activity_date >= active_accounts.activity_date group by date_range.activity_date ), @@ -45,40 +49,41 @@ new_accounts as ( account_id from active_accounts group by account_id -), +), new_accounts_daily as ( select - activity_date, - count(account_id) as new_accounts + date_range.activity_date, + count(new_accounts.account_id) as new_accounts from date_range - left join new_accounts on activity_date = start_date - group by activity_date, start_date + left join new_accounts + on date_range.activity_date = new_accounts.start_date + group by date_range.activity_date, new_accounts.start_date ), new_accounts_monthly as ( select distinct - activity_date, - sum(new_accounts) over ( - order by activity_date - range between interval '27 days' preceding and current row - ) as new_accounts - from new_accounts_daily + activity_date, + sum(new_accounts) over ( + order by activity_date + range between interval '27 days' preceding and current row + ) as new_accounts + from new_accounts_daily ) select - dr.activity_date as date, + dr.activity_date, dau.active_accounts as dau, mau.active_accounts as mau, new_accounts_daily.new_accounts as new_accounts_daily, new_accounts_monthly.new_accounts as new_accounts_monthly from date_range as dr left join active_accounts_daily as dau - on dr.activity_date = dau.activity_date + on dr.activity_date = dau.activity_date left join active_accounts_monthly as mau on dr.activity_date = mau.activity_date left join new_accounts_daily on dr.activity_date = new_accounts_daily.activity_date left join new_accounts_monthly on dr.activity_date = new_accounts_monthly.activity_date -order by date desc \ No newline at end of file +order by activity_date desc \ No newline at end of file From a9e704e558b83d1d1ca82deafd9ffe73d23b2c0c Mon Sep 17 00:00:00 2001 From: marcus-snx Date: Tue, 29 Oct 2024 18:20:52 +0200 Subject: [PATCH 3/5] Fix linting --- .../mainnet/perp/fct_perp_account_activity_arbitrum_mainnet.sql | 2 +- .../sepolia/perp/fct_perp_account_activity_arbitrum_sepolia.sql | 2 +- .../mainnet/perp/fct_perp_account_activity_base_mainnet.sql | 2 +- .../sepolia/perp/fct_perp_account_activity_base_sepolia.sql | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/transformers/synthetix/models/marts/arbitrum/mainnet/perp/fct_perp_account_activity_arbitrum_mainnet.sql b/transformers/synthetix/models/marts/arbitrum/mainnet/perp/fct_perp_account_activity_arbitrum_mainnet.sql index 2317c3aa..063ebf84 100644 --- a/transformers/synthetix/models/marts/arbitrum/mainnet/perp/fct_perp_account_activity_arbitrum_mainnet.sql +++ b/transformers/synthetix/models/marts/arbitrum/mainnet/perp/fct_perp_account_activity_arbitrum_mainnet.sql @@ -86,4 +86,4 @@ left join new_accounts_daily on dr.activity_date = new_accounts_daily.activity_date left join new_accounts_monthly on dr.activity_date = new_accounts_monthly.activity_date -order by activity_date desc \ No newline at end of file +order by dr.activity_date desc diff --git a/transformers/synthetix/models/marts/arbitrum/sepolia/perp/fct_perp_account_activity_arbitrum_sepolia.sql b/transformers/synthetix/models/marts/arbitrum/sepolia/perp/fct_perp_account_activity_arbitrum_sepolia.sql index 076635ff..b5130a4e 100644 --- a/transformers/synthetix/models/marts/arbitrum/sepolia/perp/fct_perp_account_activity_arbitrum_sepolia.sql +++ b/transformers/synthetix/models/marts/arbitrum/sepolia/perp/fct_perp_account_activity_arbitrum_sepolia.sql @@ -86,4 +86,4 @@ left join new_accounts_daily on dr.activity_date = new_accounts_daily.activity_date left join new_accounts_monthly on dr.activity_date = new_accounts_monthly.activity_date -order by activity_date desc \ No newline at end of file +order by dr.activity_date desc diff --git a/transformers/synthetix/models/marts/base/mainnet/perp/fct_perp_account_activity_base_mainnet.sql b/transformers/synthetix/models/marts/base/mainnet/perp/fct_perp_account_activity_base_mainnet.sql index a31f4a9f..c16a5e4c 100644 --- a/transformers/synthetix/models/marts/base/mainnet/perp/fct_perp_account_activity_base_mainnet.sql +++ b/transformers/synthetix/models/marts/base/mainnet/perp/fct_perp_account_activity_base_mainnet.sql @@ -86,4 +86,4 @@ left join new_accounts_daily on dr.activity_date = new_accounts_daily.activity_date left join new_accounts_monthly on dr.activity_date = new_accounts_monthly.activity_date -order by activity_date desc \ No newline at end of file +order by dr.activity_date desc diff --git a/transformers/synthetix/models/marts/base/sepolia/perp/fct_perp_account_activity_base_sepolia.sql b/transformers/synthetix/models/marts/base/sepolia/perp/fct_perp_account_activity_base_sepolia.sql index 9930ff26..6b919b11 100644 --- a/transformers/synthetix/models/marts/base/sepolia/perp/fct_perp_account_activity_base_sepolia.sql +++ b/transformers/synthetix/models/marts/base/sepolia/perp/fct_perp_account_activity_base_sepolia.sql @@ -86,4 +86,4 @@ left join new_accounts_daily on dr.activity_date = new_accounts_daily.activity_date left join new_accounts_monthly on dr.activity_date = new_accounts_monthly.activity_date -order by activity_date desc \ No newline at end of file +order by dr.activity_date desc From f518e2968f86efdef38c18649622b8d360d05149 Mon Sep 17 00:00:00 2001 From: marcus-snx Date: Tue, 29 Oct 2024 18:38:31 +0200 Subject: [PATCH 4/5] Fix column name in schema --- .../synthetix/models/marts/base/sepolia/perp/schema.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/transformers/synthetix/models/marts/base/sepolia/perp/schema.yml b/transformers/synthetix/models/marts/base/sepolia/perp/schema.yml index 04c582ca..d45506fa 100644 --- a/transformers/synthetix/models/marts/base/sepolia/perp/schema.yml +++ b/transformers/synthetix/models/marts/base/sepolia/perp/schema.yml @@ -1,7 +1,7 @@ models: - name: fct_perp_account_activity_base_sepolia columns: - - name: date + - name: activity_date description: "Activity date" data_type: date tests: From 2cfd97597f5b076cbdd9d6d8dac71cfd95720fe9 Mon Sep 17 00:00:00 2001 From: marcus-snx Date: Tue, 29 Oct 2024 22:35:38 +0200 Subject: [PATCH 5/5] Rename column --- .../perp/fct_perp_account_activity_arbitrum_mainnet.sql | 4 ++-- .../synthetix/models/marts/arbitrum/mainnet/perp/schema.yml | 2 +- .../perp/fct_perp_account_activity_arbitrum_sepolia.sql | 4 ++-- .../synthetix/models/marts/arbitrum/sepolia/perp/schema.yml | 2 +- .../mainnet/perp/fct_perp_account_activity_base_mainnet.sql | 4 ++-- .../synthetix/models/marts/base/mainnet/perp/schema.yml | 2 +- .../sepolia/perp/fct_perp_account_activity_base_sepolia.sql | 4 ++-- .../synthetix/models/marts/base/sepolia/perp/schema.yml | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/transformers/synthetix/models/marts/arbitrum/mainnet/perp/fct_perp_account_activity_arbitrum_mainnet.sql b/transformers/synthetix/models/marts/arbitrum/mainnet/perp/fct_perp_account_activity_arbitrum_mainnet.sql index 063ebf84..1663321c 100644 --- a/transformers/synthetix/models/marts/arbitrum/mainnet/perp/fct_perp_account_activity_arbitrum_mainnet.sql +++ b/transformers/synthetix/models/marts/arbitrum/mainnet/perp/fct_perp_account_activity_arbitrum_mainnet.sql @@ -72,7 +72,7 @@ new_accounts_monthly as ( ) select - dr.activity_date, + dr.activity_date as ts, dau.active_accounts as dau, mau.active_accounts as mau, new_accounts_daily.new_accounts as new_accounts_daily, @@ -86,4 +86,4 @@ left join new_accounts_daily on dr.activity_date = new_accounts_daily.activity_date left join new_accounts_monthly on dr.activity_date = new_accounts_monthly.activity_date -order by dr.activity_date desc +order by ts desc diff --git a/transformers/synthetix/models/marts/arbitrum/mainnet/perp/schema.yml b/transformers/synthetix/models/marts/arbitrum/mainnet/perp/schema.yml index 3802ac5e..634c382f 100644 --- a/transformers/synthetix/models/marts/arbitrum/mainnet/perp/schema.yml +++ b/transformers/synthetix/models/marts/arbitrum/mainnet/perp/schema.yml @@ -1,7 +1,7 @@ models: - name: fct_perp_account_activity_arbitrum_mainnet columns: - - name: activity_date + - name: ts description: "Activity date" data_type: date tests: diff --git a/transformers/synthetix/models/marts/arbitrum/sepolia/perp/fct_perp_account_activity_arbitrum_sepolia.sql b/transformers/synthetix/models/marts/arbitrum/sepolia/perp/fct_perp_account_activity_arbitrum_sepolia.sql index b5130a4e..024ead34 100644 --- a/transformers/synthetix/models/marts/arbitrum/sepolia/perp/fct_perp_account_activity_arbitrum_sepolia.sql +++ b/transformers/synthetix/models/marts/arbitrum/sepolia/perp/fct_perp_account_activity_arbitrum_sepolia.sql @@ -72,7 +72,7 @@ new_accounts_monthly as ( ) select - dr.activity_date, + dr.activity_date as ts, dau.active_accounts as dau, mau.active_accounts as mau, new_accounts_daily.new_accounts as new_accounts_daily, @@ -86,4 +86,4 @@ left join new_accounts_daily on dr.activity_date = new_accounts_daily.activity_date left join new_accounts_monthly on dr.activity_date = new_accounts_monthly.activity_date -order by dr.activity_date desc +order by ts desc diff --git a/transformers/synthetix/models/marts/arbitrum/sepolia/perp/schema.yml b/transformers/synthetix/models/marts/arbitrum/sepolia/perp/schema.yml index a13a1522..1b624a35 100644 --- a/transformers/synthetix/models/marts/arbitrum/sepolia/perp/schema.yml +++ b/transformers/synthetix/models/marts/arbitrum/sepolia/perp/schema.yml @@ -1,7 +1,7 @@ models: - name: fct_perp_account_activity_arbitrum_sepolia columns: - - name: activity_date + - name: ts description: "Activity date" data_type: date tests: diff --git a/transformers/synthetix/models/marts/base/mainnet/perp/fct_perp_account_activity_base_mainnet.sql b/transformers/synthetix/models/marts/base/mainnet/perp/fct_perp_account_activity_base_mainnet.sql index c16a5e4c..f54a9258 100644 --- a/transformers/synthetix/models/marts/base/mainnet/perp/fct_perp_account_activity_base_mainnet.sql +++ b/transformers/synthetix/models/marts/base/mainnet/perp/fct_perp_account_activity_base_mainnet.sql @@ -72,7 +72,7 @@ new_accounts_monthly as ( ) select - dr.activity_date, + dr.activity_date as ts, dau.active_accounts as dau, mau.active_accounts as mau, new_accounts_daily.new_accounts as new_accounts_daily, @@ -86,4 +86,4 @@ left join new_accounts_daily on dr.activity_date = new_accounts_daily.activity_date left join new_accounts_monthly on dr.activity_date = new_accounts_monthly.activity_date -order by dr.activity_date desc +order by ts desc diff --git a/transformers/synthetix/models/marts/base/mainnet/perp/schema.yml b/transformers/synthetix/models/marts/base/mainnet/perp/schema.yml index 3f326992..0a5f24bc 100644 --- a/transformers/synthetix/models/marts/base/mainnet/perp/schema.yml +++ b/transformers/synthetix/models/marts/base/mainnet/perp/schema.yml @@ -1,7 +1,7 @@ models: - name: fct_perp_account_activity_base_mainnet columns: - - name: activity_date + - name: ts description: "Activity date" data_type: date tests: diff --git a/transformers/synthetix/models/marts/base/sepolia/perp/fct_perp_account_activity_base_sepolia.sql b/transformers/synthetix/models/marts/base/sepolia/perp/fct_perp_account_activity_base_sepolia.sql index 6b919b11..a214c3f8 100644 --- a/transformers/synthetix/models/marts/base/sepolia/perp/fct_perp_account_activity_base_sepolia.sql +++ b/transformers/synthetix/models/marts/base/sepolia/perp/fct_perp_account_activity_base_sepolia.sql @@ -72,7 +72,7 @@ new_accounts_monthly as ( ) select - dr.activity_date, + dr.activity_date as ts, dau.active_accounts as dau, mau.active_accounts as mau, new_accounts_daily.new_accounts as new_accounts_daily, @@ -86,4 +86,4 @@ left join new_accounts_daily on dr.activity_date = new_accounts_daily.activity_date left join new_accounts_monthly on dr.activity_date = new_accounts_monthly.activity_date -order by dr.activity_date desc +order by ts desc diff --git a/transformers/synthetix/models/marts/base/sepolia/perp/schema.yml b/transformers/synthetix/models/marts/base/sepolia/perp/schema.yml index d45506fa..1dbca19d 100644 --- a/transformers/synthetix/models/marts/base/sepolia/perp/schema.yml +++ b/transformers/synthetix/models/marts/base/sepolia/perp/schema.yml @@ -1,7 +1,7 @@ models: - name: fct_perp_account_activity_base_sepolia columns: - - name: activity_date + - name: ts description: "Activity date" data_type: date tests: