-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
63 additions
and
825 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
74 changes: 62 additions & 12 deletions
74
dbt_subprojects/daily_spellbook/models/_metrics/dune_index/metrics_dune_index_daily.sql
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 |
---|---|---|
@@ -1,21 +1,71 @@ | ||
{{ config( | ||
schema = 'metrics' | ||
, alias = 'dune_index_daily' | ||
, materialized = 'view' | ||
, materialized = 'incremental' | ||
, file_format = 'delta' | ||
, incremental_strategy = 'merge' | ||
, unique_key = ['blockchain', 'block_date'] | ||
, incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')] | ||
) | ||
}} | ||
|
||
{% set baseline_date = '2018-01-01' %} | ||
{% set start_date = '2015-08-21' %} | ||
|
||
with | ||
fees as ( | ||
select | ||
blockchain | ||
, block_date | ||
, gas_fees_usd | ||
, (gas_fees_usd / (select sum(gas_fees_usd) from {{ ref('metrics_gas_fees_daily') }} where block_date = date '{{ baseline_date }}')) * 10 as fees_index | ||
from | ||
{{ ref('metrics_gas_fees_daily') }} | ||
where | ||
block_date >= date '{{ start_date }}' | ||
{% if is_incremental() %} | ||
and {{ incremental_predicate('block_date') }} | ||
{% endif %} | ||
), | ||
transactions as ( | ||
select | ||
blockchain | ||
, block_date | ||
, tx_count | ||
, (tx_count / cast(select sum(tx_count) from {{ ref('metrics_transactions_daily') }} where block_date = date '{{ baseline_date }}' as double)) * 10 as tx_index | ||
from | ||
{{ ref('metrics_transactions_daily') }} | ||
where | ||
block_date >= date '{{ start_date }}' | ||
{% if is_incremental() %} | ||
and {{ incremental_predicate('block_date') }} | ||
{% endif %} | ||
) | ||
,transfers as ( | ||
select | ||
blockchain | ||
, block_date | ||
, net_transfer_amount_usd | ||
, (net_transfer_amount_usd / cast(select sum(net_transfer_amount_usd) from {{ ref('metrics_transfers_daily') }} where block_date = date '{{ baseline_date }}' as double)) * 10 as transfers_index | ||
from | ||
{{ ref('metrics_transfers_daily') }} | ||
where | ||
block_date >= date '{{ start_date }}' | ||
{% if is_incremental() %} | ||
and {{ incremental_predicate('block_date') }} | ||
{% endif %} | ||
) | ||
|
||
select | ||
blockchain | ||
, block_date | ||
, coalesce(f.fees_index,0) as fees_index | ||
, coalesce(tr.transfers_index,0) as transfers_index | ||
, coalesce(tx.tx_index,0) as tx_index | ||
, coalesce(f.fees_index,0)*0.45 + coalesce(tr.transfers_index,0)*0.45 + coalesce(tx.tx_index,0)*0.10 as dune_index | ||
from {{ ref('metrics_fees_index_daily') }} as f | ||
left join | ||
{{ ref('metrics_transfers_index_daily') }} as tr | ||
using (blockchain, block_date) | ||
left join | ||
{{ ref('metrics_transactions_index_daily') }} as tx | ||
using (blockchain, block_date) | ||
, 0.45 * coalesce(fees_index,0) + 0.45 * coalesce(transfers_index,0) + 0.10 * coalesce(tx_index,0) as dune_index | ||
, coalesce(fees_index,0) as fees_index | ||
, coalesce(transfers_index,0) as transfers_index | ||
, coalesce(tx_index,0) as tx_index | ||
, gas_fees_usd | ||
, tx_count | ||
, net_transfer_amount_usd | ||
from fees | ||
left join transfers using (blockchain, block_date) | ||
left join transactions using (blockchain, block_date) |
160 changes: 0 additions & 160 deletions
160
dbt_subprojects/daily_spellbook/models/_metrics/dune_index/metrics_dune_index_stats.sql
This file was deleted.
Oops, something went wrong.
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
38 changes: 0 additions & 38 deletions
38
dbt_subprojects/daily_spellbook/models/_metrics/fees/metrics_fees_index_daily.sql
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.