From e283e9e794666093da873f9df6d2ae87d9e7cd09 Mon Sep 17 00:00:00 2001 From: WHYTEWYLL Date: Tue, 7 Nov 2023 14:18:53 -0300 Subject: [PATCH] mma --- models/silver/atlas/silver__atlas_mma.sql | 38 +++++++++++++++++++ .../atlas/silver__atlas_nft_30_trailing.sql | 2 +- .../atlas/silver__atlas_nft_30_trailing.yml | 2 - .../silver/atlas/silver__atlas_nft_table.yml | 5 +-- .../atlas/silver__atlas_nft_transactions.yml | 16 ++++---- 5 files changed, 49 insertions(+), 14 deletions(-) create mode 100644 models/silver/atlas/silver__atlas_mma.sql diff --git a/models/silver/atlas/silver__atlas_mma.sql b/models/silver/atlas/silver__atlas_mma.sql new file mode 100644 index 0000000..f08de40 --- /dev/null +++ b/models/silver/atlas/silver__atlas_mma.sql @@ -0,0 +1,38 @@ +{{ config( + materialized = 'incremental', + unique_key = 'day', + incremental_strategy = 'delete+insert', + tags = ['atlas'] +) }} + +WITH date_range AS ( + SELECT + date_day as day + FROM {{ ref('silver__dates') }} + WHERE + {% if is_incremental() %} + date_day >= SYSDATE() - INTERVAL '3 DAY' + {% else %} + date_day >= '2021-01-01' -- first day of data + {% endif %} + AND date_day <= SYSDATE()::DATE +) + + +SELECT day, + COUNT(DISTINCT tx_signer) - COUNT(DISTINCT CASE WHEN first_tx >= day - INTERVAL '30 Days' AND first_tx < day THEN wallet END) AS Returning_MAAs, + COUNT(DISTINCT CASE WHEN first_tx >= day - INTERVAL '30 Days' AND first_tx < day THEN wallet END) AS New_MAAs, + COUNT(DISTINCT tx_signer) AS MAAs +FROM date_range a +LEFT OUTER JOIN (SELECT DISTINCT tx_signer, block_timestamp::date AS active_day + FROM {{ ref('silver__streamline_transactions_final') }}) b + ON active_day >= day - INTERVAL '30 DAYS' + AND active_day < day +JOIN (SELECT tx_signer AS wallet, MIN(block_timestamp) AS first_tx FROM {{ ref('silver__streamline_transactions_final') }} tr GROUP BY 1) c + ON b.tx_signer = c.wallet +GROUP BY 1 +ORDER BY 1 DESC + + +-- 4.20 Mins all +-- 2.5 mins incremental diff --git a/models/silver/atlas/silver__atlas_nft_30_trailing.sql b/models/silver/atlas/silver__atlas_nft_30_trailing.sql index 4dc90b5..ca9229c 100644 --- a/models/silver/atlas/silver__atlas_nft_30_trailing.sql +++ b/models/silver/atlas/silver__atlas_nft_30_trailing.sql @@ -13,7 +13,7 @@ WITH date_range AS ( {% if is_incremental() %} date_day >= SYSDATE() - INTERVAL '3 DAY' {% else %} - date_day >= '2021-05-01' -- first day of data + date_day >= '2021-01-01' -- first day of data {% endif %} AND date_day <= SYSDATE()::DATE ) diff --git a/models/silver/atlas/silver__atlas_nft_30_trailing.yml b/models/silver/atlas/silver__atlas_nft_30_trailing.yml index 0f2a1b9..57192d4 100644 --- a/models/silver/atlas/silver__atlas_nft_30_trailing.yml +++ b/models/silver/atlas/silver__atlas_nft_30_trailing.yml @@ -15,5 +15,3 @@ models: description: "{{ doc('tx_count')}}" tests: - not_null - - dbt_expectations.expect_column_values_to_be_of_type: - type: integer diff --git a/models/silver/atlas/silver__atlas_nft_table.yml b/models/silver/atlas/silver__atlas_nft_table.yml index 9eef890..b43272c 100644 --- a/models/silver/atlas/silver__atlas_nft_table.yml +++ b/models/silver/atlas/silver__atlas_nft_table.yml @@ -7,13 +7,12 @@ models: columns: - name: receiver_id - description: { { doc('receiver_id') } } + description: "{ { doc('receiver_id')}}" tests: - not_null - - unique - name: tokens - description: { { doc('token_id ') } } + description: "The count of unique tokens that have been received by the receiver_id." tests: - not_null diff --git a/models/silver/atlas/silver__atlas_nft_transactions.yml b/models/silver/atlas/silver__atlas_nft_transactions.yml index 3022a0f..d2b56ff 100644 --- a/models/silver/atlas/silver__atlas_nft_transactions.yml +++ b/models/silver/atlas/silver__atlas_nft_transactions.yml @@ -7,19 +7,19 @@ models: columns: - name: action_id - description: { { doc('action_id') } } + description: "{{doc('action_id')}}" tests: - unique - not_null - name: day - description: { { doc('date') } } + description: "{{doc('date')}}" tests: - not_null - dbt_expectations.expect_column_values_to_be_date - name: tx_hash - description: { { doc('tx_hash') } } + description: "{{doc('tx_hash')}}" tests: - not_null @@ -29,27 +29,27 @@ models: - not_null - name: receiver_id - description: { { doc('receiver_id') } } + description: "{{doc('receiver_id')}}" tests: - not_null - name: signer_id - description: { { doc('signer_id') } } + description: "{{doc('signer_id')}}" tests: - not_null - name: owner - description: { { doc('owner') } } + description: "The owner of the token, which is the signer_id for minting events and the receiver_id for transfers." tests: - not_null - name: token_id - description: { { doc('token_id') } } + description: "{{doc('token_id')}}" tests: - not_null - name: _inserted_timestamp - description: { { doc('_inserted_timestamp') } } + description: "{{doc('_inserted_timestamp')}}" tests: - not_null - dbt_expectations.expect_column_values_to_be_increasing