-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: include timestamp in matching data * chore: add round data as static source * feat(dbt): gitcoin funding rounds * fix: application title * fix: linting error * fix: add round name to staging * temp: save progress * refactor: use round names from donations table * refactor: finalize funding event data * fix: final refactor of all models * fix: linting error * feat: gitcoin mart model
- Loading branch information
Showing
8 changed files
with
216 additions
and
92 deletions.
There are no files selected for viewing
108 changes: 56 additions & 52 deletions
108
warehouse/dbt/models/intermediate/funding/int_gitcoin_funding_events.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,65 +1,69 @@ | ||
{# | ||
This model combines the donations and matching grants data to create a single table of funding events. | ||
The `funding_type` column is used to differentiate between donations and matching grants. | ||
The `event_time` data has some issues. It is missing for matching grants, so we use the most recent donation timestamp as a placeholder. To the cGrants data, we use a placeholder date of 2023-07-01. | ||
#} | ||
|
||
|
||
with last_donation_by_round as ( | ||
select | ||
round_id, | ||
round_number, | ||
gitcoin_project_id, | ||
max(donation_timestamp) as assumed_event_time | ||
from {{ ref('stg_gitcoin__donations') }} | ||
group by | ||
round_id, | ||
round_number, | ||
gitcoin_project_id | ||
with unioned_funding_events as ( | ||
select * from {{ ref('stg_gitcoin__donations') }} | ||
union all | ||
select * from {{ ref('stg_gitcoin__matching') }} | ||
), | ||
|
||
unioned_events as ( | ||
labeled_funding_events as ( | ||
select | ||
transaction_hash, | ||
donation_timestamp as event_time, | ||
round_id, | ||
round_number, | ||
chain_id, | ||
gitcoin_project_id, | ||
donor_address, | ||
amount_in_usd, | ||
'DONATIONS' as funding_type | ||
from {{ ref('stg_gitcoin__donations') }} | ||
|
||
union all | ||
*, | ||
case | ||
when ( | ||
gitcoin_data_source in ('MatchFunding', 'CGrants') | ||
and round_number between 1 and 15 | ||
) then concat('GG-', lpad(cast(round_number as string), 2, '0')) | ||
when ( | ||
gitcoin_data_source in ('MatchFunding', 'Alpha') | ||
and round_number = 16 | ||
) then 'GG-16' | ||
when ( | ||
gitcoin_data_source in ('MatchFunding', 'GrantsStack') | ||
and round_number is not null | ||
) then concat('GG-', lpad(cast(round_number as string), 2, '0')) | ||
end as main_round_label, | ||
case | ||
when ( | ||
gitcoin_data_source = 'CGrants' | ||
and round_number is null | ||
) then 'DirectDonations' | ||
when ( | ||
gitcoin_data_source in ('MatchFunding', 'GrantsStack') | ||
and round_number is null | ||
) then 'PartnerRound' | ||
else 'MainRound' | ||
end as round_type | ||
from unioned_funding_events | ||
), | ||
|
||
joined_events as ( | ||
select | ||
null as transaction_hash, | ||
last_donation_by_round.assumed_event_time as event_time, | ||
matching.round_id, | ||
matching.round_number, | ||
matching.chain_id, | ||
matching.gitcoin_project_id, | ||
null as donor_address, | ||
matching.amount_in_usd, | ||
'MATCHING' as funding_type | ||
from {{ ref('stg_gitcoin__matching') }} as matching | ||
left join last_donation_by_round | ||
on | ||
matching.round_id = last_donation_by_round.round_id | ||
and matching.round_number = last_donation_by_round.round_number | ||
and matching.gitcoin_project_id = last_donation_by_round.gitcoin_project_id | ||
labeled_funding_events.*, | ||
directory.oso_project_id, | ||
projects.project_name as oso_project_name, | ||
projects.display_name as oso_display_name | ||
from labeled_funding_events | ||
left join {{ ref('int_gitcoin_project_directory') }} as directory | ||
on labeled_funding_events.gitcoin_project_id = directory.gitcoin_project_id | ||
left join {{ ref('projects_v1') }} as projects | ||
on directory.oso_project_id = projects.project_id | ||
where amount_in_usd > 0 | ||
) | ||
|
||
select | ||
transaction_hash, | ||
round_id, | ||
event_time, | ||
gitcoin_data_source, | ||
gitcoin_round_id, | ||
round_number, | ||
round_type, | ||
main_round_label, | ||
round_name, | ||
chain_id, | ||
gitcoin_project_id, | ||
project_application_title, | ||
oso_project_id, | ||
oso_project_name, | ||
oso_display_name, | ||
donor_address, | ||
amount_in_usd, | ||
funding_type, | ||
coalesce(event_time, timestamp('2023-07-01')) as event_time | ||
from unioned_events | ||
where amount_in_usd > 0 | ||
transaction_hash | ||
from joined_events |
42 changes: 42 additions & 0 deletions
42
warehouse/dbt/models/intermediate/funding/int_gitcoin_funding_rounds.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,42 @@ | ||
with partner_rounds as ( | ||
select * | ||
from {{ ref('int_gitcoin_funding_events') }} | ||
where | ||
round_type = 'PartnerRound' | ||
and round_name is not null | ||
), | ||
|
||
main_rounds as ( | ||
select * | ||
from {{ ref('int_gitcoin_funding_events') }} | ||
where round_type = 'MainRound' | ||
), | ||
|
||
unioned as ( | ||
select * from partner_rounds | ||
union all | ||
select * from main_rounds | ||
) | ||
|
||
select | ||
gitcoin_data_source, | ||
gitcoin_round_id, | ||
round_number, | ||
round_name, | ||
round_type, | ||
main_round_label, | ||
array_agg(distinct chain_id) as chain_ids, | ||
sum(amount_in_usd) as total_amount_in_usd, | ||
count(distinct gitcoin_project_id) as count_projects | ||
from unioned | ||
group by | ||
gitcoin_data_source, | ||
gitcoin_round_id, | ||
round_number, | ||
round_name, | ||
round_type, | ||
main_round_label | ||
order by | ||
round_type asc, | ||
main_round_label desc, | ||
gitcoin_round_id asc |
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
31 changes: 31 additions & 0 deletions
31
warehouse/dbt/models/marts/gitcoin/gitcoin_funding_events_by_project_v0.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,31 @@ | ||
select | ||
event_time, | ||
gitcoin_data_source, | ||
gitcoin_round_id, | ||
round_number, | ||
round_type, | ||
main_round_label, | ||
round_name, | ||
gitcoin_project_id, | ||
project_application_title, | ||
oso_project_id, | ||
oso_project_name, | ||
oso_display_name, | ||
donor_address, | ||
sum(amount_in_usd) as amount_in_usd | ||
from {{ ref('int_gitcoin_funding_events') }} | ||
where oso_project_id is not null | ||
group by | ||
event_time, | ||
gitcoin_data_source, | ||
gitcoin_round_id, | ||
round_number, | ||
round_type, | ||
main_round_label, | ||
round_name, | ||
gitcoin_project_id, | ||
project_application_title, | ||
oso_project_id, | ||
oso_project_name, | ||
oso_display_name, | ||
donor_address |
26 changes: 17 additions & 9 deletions
26
warehouse/dbt/models/staging/gitcoin/stg_gitcoin__donations.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,14 +1,22 @@ | ||
select distinct | ||
with max_dlt as ( | ||
select max(_dlt_load_id) as max_dlt_load_id | ||
from {{ source("gitcoin", "all_donations") }} | ||
) | ||
|
||
select distinct -- noqa: ST06 | ||
`source` as gitcoin_data_source, | ||
`timestamp` as donation_timestamp, | ||
round_id, | ||
`timestamp` as event_time, | ||
round_id as gitcoin_round_id, | ||
round_num as round_number, | ||
round_name, | ||
chain_id, | ||
project_id as gitcoin_project_id, | ||
amount_in_usd, | ||
LOWER(recipient_address) as project_recipient_address, | ||
LOWER(donor_address) as donor_address, | ||
LOWER(transaction_hash) as transaction_hash, | ||
TRIM(project_name) as project_application_title | ||
trim(project_name) as project_application_title, | ||
lower(recipient_address) as project_recipient_address, | ||
lower(donor_address) as donor_address, | ||
lower(transaction_hash) as transaction_hash, | ||
amount_in_usd | ||
from {{ source("gitcoin", "all_donations") }} | ||
where amount_in_usd > 0 | ||
where | ||
amount_in_usd > 0 | ||
and _dlt_load_id = (select max_dlt.max_dlt_load_id from max_dlt) |
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