Skip to content

Commit

Permalink
Yearly and monthly resolutions (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
tifrel authored Jan 20, 2023
1 parent 5000e83 commit 7487b55
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
table:
schema: analytics_tmp
name: referrer_earnings_monthly
select_permissions:
- role: anonymous
permission:
columns:
- date_trunc
- referrer_id
- sales_count
- total_earned
filter: {}
allow_aggregations: true
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
table:
schema: analytics_tmp
name: referrer_earnings
name: referrer_earnings_yearly
select_permissions:
- role: anonymous
permission:
Expand Down
3 changes: 2 additions & 1 deletion hasura/metadata/databases/minterop/tables/tables.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
- "!include analytics_tmp_referrer_earnings.yaml"
- "!include analytics_tmp_referrer_earnings_monthly.yaml"
- "!include analytics_tmp_referrer_earnings_yearly.yaml"
- "!include mb_views_active_listings_rollup.yaml"
- "!include mb_views_active_listings.yaml"
- "!include mb_views_active_listings_by_contract.yaml"
Expand Down
18 changes: 18 additions & 0 deletions migrations/2023-01-20-122717_analytics-earnings-yearly/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
create view analytics_tmp.referrer_earnings as
select
date_trunc,
receiver_id as referrer_id,
sum(amount) as total_earned,
count(*) as sales_count
from (
select date_trunc('month', timestamp)::date, receiver_id, amount
from nft_earnings
where is_referral = TRUE
and nft_contract_id <> 'deadmau5.mintbase1.near'
) e
group by date_trunc, receiver_id
order by date_trunc, receiver_id
;

drop view analytics_tmp.referrer_earnings_monthly;
drop view analytics_tmp.referrer_earnings_yearly;
31 changes: 31 additions & 0 deletions migrations/2023-01-20-122717_analytics-earnings-yearly/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
create view analytics_tmp.referrer_earnings_monthly as
select
date_trunc,
receiver_id as referrer_id,
sum(amount) as total_earned,
count(*) as sales_count
from (
select date_trunc('month', timestamp)::date, receiver_id, amount
from nft_earnings
where is_referral = TRUE
and nft_contract_id <> 'deadmau5.mintbase1.near'
) e
group by date_trunc, receiver_id
order by date_trunc, receiver_id
;

create view analytics_tmp.referrer_earnings_yearly as
select
date_trunc,
receiver_id as referrer_id,
sum(amount) as total_earned,
count(*) as sales_count
from (
select date_trunc('month', timestamp)::date, receiver_id, amount
from nft_earnings
where is_referral = TRUE
and nft_contract_id <> 'deadmau5.mintbase1.near'
) e
group by date_trunc, receiver_id
order by date_trunc, receiver_id
;

0 comments on commit 7487b55

Please sign in to comment.