-
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.
- Loading branch information
1 parent
8bd24c0
commit 246084d
Showing
7 changed files
with
213 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
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
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
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
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,65 @@ | ||
{{ config(materialized="table", snowflake_warehouse="BAM_TRENDING_WAREHOUSE") }} | ||
|
||
with | ||
last_2_day as ( | ||
select | ||
t.contract_address to_address, | ||
from_address, | ||
date_trunc('day', block_timestamp) date, | ||
tx_fee, | ||
gas_usd, | ||
name, | ||
app as namespace, | ||
friendly_name, | ||
category | ||
from {{ref('fact_mantle_transactions')}} as t | ||
where | ||
t.contract_address is not null | ||
and t.block_timestamp >= dateadd(day, -2, current_date) | ||
), | ||
last_day as ( | ||
select | ||
t.to_address to_address, | ||
count(*) txns, | ||
count(distinct(from_address)) dau, | ||
sum(tx_fee) as gas, | ||
sum(gas_usd) as gas_usd, | ||
max(name) name, | ||
max(namespace) namespace, | ||
max(friendly_name) friendly_name, | ||
max(category) category | ||
from last_2_day as t | ||
where t.to_address is not null and t.date >= dateadd(day, -1, current_date) | ||
group by to_address | ||
), | ||
two_days as ( | ||
select | ||
t.to_address to_address, | ||
count(*) txns, | ||
count(distinct(from_address)) dau, | ||
sum(tx_fee) as gas, | ||
sum(gas_usd) as gas_usd | ||
from last_2_day as t | ||
where | ||
t.to_address is not null | ||
and t.date < dateadd(day, -1, current_date) | ||
and t.date >= dateadd(day, -2, current_date) | ||
group by to_address | ||
) | ||
select | ||
last_day.to_address, | ||
last_day.txns, | ||
last_day.gas, | ||
last_day.gas_usd, | ||
last_day.dau, | ||
two_days.txns prev_txns, | ||
two_days.gas prev_gas, | ||
two_days.gas_usd prev_gas_usd, | ||
two_days.dau prev_dau, | ||
last_day.name, | ||
last_day.namespace, | ||
last_day.friendly_name, | ||
last_day.category, | ||
'daily' as granularity | ||
from last_day | ||
left join two_days on lower(last_day.to_address) = lower(two_days.to_address) |
121 changes: 121 additions & 0 deletions
121
models/staging/mantle/mantle_trending_weekly_monthly.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 |
---|---|---|
@@ -0,0 +1,121 @@ | ||
{{ config(materialized="table", snowflake_warehouse="BAM_TRENDING_WAREHOUSE") }} | ||
|
||
with | ||
last_2_month as ( | ||
select | ||
t.contract_address to_address, | ||
from_address, | ||
date_trunc('day', block_timestamp) date, | ||
tx_fee, | ||
gas_usd, | ||
name, | ||
app as namespace, | ||
friendly_name, | ||
category | ||
from {{ref("fact_mantle_transactions")}} as t | ||
where | ||
t.contract_address is not null | ||
and t.block_timestamp >= dateadd(day, -60, current_date) | ||
), | ||
last_week as ( | ||
select | ||
to_address to_address, | ||
count(*) as txns, | ||
count(distinct(from_address)) dau, | ||
sum(tx_fee) as gas, | ||
sum(gas_usd) as gas_usd, | ||
max(name) name, | ||
max(namespace) namespace, | ||
max(friendly_name) friendly_name, | ||
max(category) category | ||
from last_2_month | ||
where to_address is not null and date >= dateadd(day, -7, current_date) | ||
group by to_address | ||
), | ||
two_week as ( | ||
select | ||
to_address to_address, | ||
count(*) txns, | ||
count(distinct(from_address)) dau, | ||
sum(tx_fee) as gas, | ||
sum(gas_usd) as gas_usd | ||
from last_2_month | ||
where | ||
to_address is not null | ||
and date < dateadd(day, -7, current_date) | ||
and date >= dateadd(day, -14, current_date) | ||
group by to_address | ||
), | ||
trending_week as ( | ||
select | ||
last_week.to_address, | ||
last_week.txns, | ||
last_week.gas, | ||
last_week.gas_usd, | ||
last_week.dau, | ||
two_week.txns prev_txns, | ||
two_week.gas prev_gas, | ||
two_week.gas_usd prev_gas_usd, | ||
two_week.dau prev_dau, | ||
last_week.name, | ||
last_week.namespace, | ||
last_week.friendly_name, | ||
last_week.category, | ||
'weekly' as granularity | ||
from last_week | ||
left join two_week on lower(last_week.to_address) = lower(two_week.to_address) | ||
), | ||
last_month as ( | ||
select | ||
to_address to_address, | ||
count(*) as txns, | ||
count(distinct(from_address)) dau, | ||
sum(tx_fee) as gas, | ||
sum(gas_usd) as gas_usd, | ||
max(name) name, | ||
max(namespace) namespace, | ||
max(friendly_name) friendly_name, | ||
max(category) category | ||
from last_2_month | ||
where to_address is not null and date >= dateadd(day, -30, current_date) | ||
group by to_address | ||
), | ||
two_month as ( | ||
select | ||
to_address to_address, | ||
count(*) txns, | ||
count(distinct(from_address)) dau, | ||
sum(tx_fee) as gas, | ||
sum(gas_usd) as gas_usd | ||
from last_2_month | ||
where | ||
to_address is not null | ||
and date < dateadd(day, -30, current_date) | ||
and date >= dateadd(day, -60, current_date) | ||
group by to_address | ||
), | ||
trending_month as ( | ||
select | ||
last_month.to_address, | ||
last_month.txns, | ||
last_month.gas, | ||
last_month.gas_usd, | ||
last_month.dau, | ||
two_month.txns prev_txns, | ||
two_month.gas prev_gas, | ||
two_month.gas_usd prev_gas_usd, | ||
two_month.dau prev_dau, | ||
last_month.name, | ||
last_month.namespace, | ||
last_month.friendly_name, | ||
last_month.category, | ||
'monthly' as granularity | ||
from last_month | ||
left join | ||
two_month on lower(last_month.to_address) = lower(two_month.to_address) | ||
) | ||
select * | ||
from trending_week | ||
union | ||
select * | ||
from trending_month |
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