forked from FlipsideCrypto/xyz-models
-
Notifications
You must be signed in to change notification settings - Fork 1
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 #54 from FlipsideCrypto/AN-4040-AURORA-MAA
AN-4040/Aurora MAAs
- Loading branch information
Showing
19 changed files
with
229 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,34 @@ | ||
name: dbt_run_atlas | ||
run-name: dbt_run_atlas | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
# Runs once per day at 0 UTC | ||
- cron: "0 0 * * *" | ||
|
||
env: | ||
USE_VARS: "${{ vars.USE_VARS }}" | ||
DBT_PROFILES_DIR: "${{ vars.DBT_PROFILES_DIR }}" | ||
DBT_VERSION: "${{ vars.DBT_VERSION }}" | ||
ACCOUNT: "${{ vars.ACCOUNT }}" | ||
ROLE: "${{ vars.ROLE }}" | ||
USER: "${{ vars.USER }}" | ||
PASSWORD: "${{ secrets.PASSWORD }}" | ||
REGION: "${{ vars.REGION }}" | ||
DATABASE: "${{ vars.DATABASE }}" | ||
WAREHOUSE: "${{ vars.WAREHOUSE }}" | ||
SCHEMA: "${{ vars.SCHEMA }}" | ||
|
||
concurrency: | ||
group: ${{ github.workflow }} | ||
|
||
jobs: | ||
called_workflow_template: | ||
uses: FlipsideCrypto/analytics-workflow-templates/.github/workflows/dbt_run_template.yml@main | ||
with: | ||
dbt_command: > | ||
dbt run -s tag:atlas | ||
environment: workflow_prod | ||
warehouse: ${{ vars.WAREHOUSE }} | ||
secrets: inherit |
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,5 @@ | ||
{% docs active_day %} | ||
|
||
Date of activity. | ||
|
||
{% enddocs %} |
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,5 @@ | ||
{% docs id %} | ||
|
||
A unique identifier for the record. | ||
|
||
{% enddocs %} |
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,5 @@ | ||
{% docs inserted_timestamp %} | ||
|
||
The timestamp at which the record was initially created and inserted into this table. | ||
|
||
{% enddocs %} |
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,5 @@ | ||
{% docs invocation_id %} | ||
|
||
A job ID to identify the run that last modified a record. | ||
|
||
{% enddocs %} |
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,5 @@ | ||
{% docs maa %} | ||
|
||
Monthly Active Accounts (wallets), as determined by transaction signers. | ||
|
||
{% enddocs %} |
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,5 @@ | ||
{% docs modified_timestamp %} | ||
|
||
The timestamp at which this record was last modified by an internal process. | ||
|
||
{% enddocs %} |
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,13 @@ | ||
{{ config( | ||
materialized = 'view', | ||
tags = ['atlas'] | ||
) }} | ||
|
||
SELECT | ||
atlas_maa_id AS fact_maas_id, | ||
day, | ||
maa, | ||
inserted_timestamp, | ||
modified_timestamp | ||
FROM | ||
{{ ref('silver__atlas_maa') }} |
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,34 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: atlas__fact_maas | ||
description: |- | ||
Monthly Active Accounts (wallets) on Aurora, calculated over a rolling 30 day window. An active account, here, is defined as the signing of at least one transaction. | ||
columns: | ||
- name: fact_maas_id | ||
description: "{{ doc('id') }}" | ||
tests: | ||
- not_null | ||
- unique | ||
|
||
- name: day | ||
description: "{{ doc('active_day') }}" | ||
tests: | ||
- not_null | ||
- unique | ||
|
||
- name: maa | ||
description: "{{ doc('maa')}}" | ||
tests: | ||
- not_null | ||
|
||
- name: inserted_timestamp | ||
description: "{{ doc('inserted_timestamp') }}" | ||
tests: | ||
- not_null | ||
|
||
- name: modified_timestamp | ||
description: "{{ doc('modified_timestamp') }}" | ||
tests: | ||
- not_null |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 @@ | ||
{{ config( | ||
materialized = 'incremental', | ||
incremental_stratege = 'merge', | ||
merge_exclude_columns = ["inserted_timestamp"], | ||
unique_key = 'day', | ||
tags = ['atlas'] | ||
) }} | ||
|
||
WITH dates AS ( | ||
|
||
SELECT | ||
date_day AS DAY | ||
FROM | ||
{{ source( | ||
'crosschain', | ||
'dim_dates' | ||
) }} | ||
|
||
{% if is_incremental() %} | ||
WHERE | ||
date_day > ( | ||
SELECT | ||
MAX(DAY) | ||
FROM | ||
{{ this }} | ||
) | ||
AND date_day < SYSDATE() :: DATE | ||
{% else %} | ||
WHERE | ||
date_day BETWEEN '2020-07-22' | ||
AND SYSDATE() :: DATE | ||
{% endif %} | ||
), | ||
txns AS ( | ||
SELECT | ||
block_timestamp :: DATE AS active_day, | ||
from_address | ||
FROM | ||
{{ ref('silver__transactions') }} | ||
|
||
{% if is_incremental() %} | ||
WHERE | ||
block_timestamp :: DATE >= ( | ||
SELECT | ||
MAX(DAY) | ||
FROM | ||
{{ this }} | ||
) - INTERVAL '30 days' | ||
{% endif %} | ||
), | ||
FINAL AS ( | ||
SELECT | ||
DAY, | ||
COUNT( | ||
DISTINCT from_address | ||
) AS maa | ||
FROM | ||
dates d | ||
LEFT JOIN txns t | ||
ON t.active_day < d.day | ||
AND t.active_day >= d.day - INTERVAL '30 day' | ||
WHERE | ||
DAY != CURRENT_DATE() | ||
GROUP BY | ||
1 | ||
ORDER BY | ||
1 DESC | ||
) | ||
SELECT | ||
{{ dbt_utils.generate_surrogate_key( | ||
['day'] | ||
) }} AS atlas_maa_id, | ||
DAY, | ||
maa, | ||
SYSDATE() AS inserted_timestamp, | ||
SYSDATE() AS modified_timestamp, | ||
'{{ invocation_id }}' AS invocation_id | ||
FROM | ||
FINAL |
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,39 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: silver__atlas_maa | ||
description: |- | ||
Monthly Active Accounts (wallets) on Aurora, calculated over a rolling 30 day window. An active account, here, is defined as the signing of at least one transaction. | ||
columns: | ||
- name: atlas_maa_id | ||
description: "{{ doc('id') }}" | ||
tests: | ||
- not_null | ||
- unique | ||
|
||
- name: day | ||
description: "{{ doc('active_day') }}" | ||
tests: | ||
- not_null | ||
- unique | ||
|
||
- name: maa | ||
description: "{{ doc('maa')}}" | ||
tests: | ||
- not_null | ||
|
||
- name: inserted_timestamp | ||
description: "{{ doc('inserted_timestamp') }}" | ||
tests: | ||
- not_null | ||
|
||
- name: modified_timestamp | ||
description: "{{ doc('modified_timestamp') }}" | ||
tests: | ||
- not_null | ||
|
||
- name: invocation_id | ||
description: "{{ doc('invocation_id') }}" | ||
tests: | ||
- not_null |