Skip to content

Commit

Permalink
refactor: finalize funding event data
Browse files Browse the repository at this point in the history
  • Loading branch information
ccerv1 committed Dec 3, 2024
1 parent 3442467 commit 9dce10f
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ with donations as (
select
transaction_hash,
donation_timestamp as event_time,
round_id,
round_number,
gitcoin_round_id,
coalesce(round_number, -1) as round_number,
chain_id,
gitcoin_project_id,

project_application_title,
project_recipient_address,
donor_address,
amount_in_usd,
'DONATIONS' as funding_type
Expand All @@ -21,27 +22,31 @@ with donations as (

matching as (
select
null as transaction_hash,
cast(null as string) as transaction_hash,
funding_rounds.date_round_ended as event_time,
round_id,
round_number,
chain_id,
gitcoin_project_id,
null as donor_address,
amount_in_usd,
matching_data.gitcoin_round_id,
matching_data.round_number,
matching_data.chain_id,
matching_data.gitcoin_project_id,
matching_data.project_application_title,
matching_data.project_recipient_address,
cast(null as string) as donor_address,
matching_data.amount_in_usd,
'MATCHING' as funding_type
from (
select
round_id,
gitcoin_round_id,
coalesce(round_number, -1) as round_number,
chain_id,
gitcoin_project_id,
project_application_title,
project_recipient_address,
amount_in_usd
from {{ ref('stg_gitcoin__matching') }}
) as matching_data
left join {{ ref('int_gitcoin_funding_rounds') }} as funding_rounds
on
matching_data.round_id = funding_rounds.round_id
matching_data.gitcoin_round_id = funding_rounds.gitcoin_round_id
and matching_data.round_number = funding_rounds.round_number
),

Expand All @@ -61,14 +66,15 @@ project_directory_joined as (
where amount_in_usd > 0
),

final as (
events as (
select
{{ oso_id("'GITCOIN'", 'round_id', 'round_number') }}
{{ oso_id("'GITCOIN'", 'gitcoin_round_id', 'round_number') }}
as funding_round_id,
round_id,
gitcoin_round_id,
round_number,
chain_id,
gitcoin_project_id,
project_application_title,
oso_project_id,
donor_address,
amount_in_usd,
Expand All @@ -79,18 +85,23 @@ final as (
)

select
funding_round_id,
round_id,
round_number,
chain_id,
gitcoin_project_id,
oso_project_id,
events.funding_round_id,
events.gitcoin_round_id,
events.round_number,
funding_rounds.round_name,
events.chain_id,
events.gitcoin_project_id,
events.project_application_title,
events.oso_project_id,
projects.project_name as oso_project_name,
donor_address,
amount_in_usd,
funding_type,
event_time,
transaction_hash
from final
left join {{ ref('projects_v') }} as projects
on final.oso_project_id = projects.project_id
projects.display_name as oso_display_name,
events.donor_address,
events.amount_in_usd,
events.funding_type,
events.event_time,
events.transaction_hash
from events
left join {{ ref('projects_v1') }} as projects
on events.oso_project_id = projects.project_id
left join {{ ref('int_gitcoin_funding_rounds') }} as funding_rounds
on events.funding_round_id = funding_rounds.funding_round_id
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,32 @@ with round_dates as (

round_details as (
select
round_id,
gitcoin_round_id,
round_name,
coalesce(round_number, -1) as round_number,
min(donation_timestamp) as date_round_started,
max(donation_timestamp) as date_round_ended
from {{ ref('stg_gitcoin__donations') }}
group by round_id, round_number, round_name
group by gitcoin_round_id, round_number, round_name
),

matching as (
select
round_id,
gitcoin_round_id,
chain_id,
coalesce(round_number, -1) as round_number,
sum(amount_in_usd) as matching_amount_in_usd
from {{ ref('stg_gitcoin__matching') }}
group by round_id, round_number, chain_id
group by gitcoin_round_id, round_number, chain_id
),

combined as (
select
matching.round_id,
matching.gitcoin_round_id,
matching.round_number,
matching.chain_id,
matching.matching_amount_in_usd,
coalesce(round_details.round_name, matching.round_id)
coalesce(round_details.round_name, matching.gitcoin_round_id)
as round_name,
coalesce(round_details.date_round_started, round_dates.date_round_started)
as date_round_started,
Expand All @@ -64,17 +64,17 @@ combined as (
from matching
left join round_details
on
matching.round_id = round_details.round_id
matching.gitcoin_round_id = round_details.gitcoin_round_id
and matching.round_number = round_details.round_number
left join round_dates
on matching.round_number = round_dates.round_number
order by date_round_ended
)

select
{{ oso_id("'GITCOIN'", 'round_id', 'round_number') }}
{{ oso_id("'GITCOIN'", 'gitcoin_round_id', 'round_number') }}
as funding_round_id,
round_id as gitcoin_round_id,
gitcoin_round_id,
round_number,
round_name,
chain_id,
Expand Down
19 changes: 13 additions & 6 deletions warehouse/dbt/models/staging/gitcoin/stg_gitcoin__donations.sql
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
with max_dlt as (
select max(_dlt_load_id) as max_dlt_load_id
from {{ source("gitcoin", "all_donations") }}
)

select distinct
`source` as gitcoin_data_source,
`timestamp` as donation_timestamp,
round_id,
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
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
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)
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ with max_dlt as (
)

select distinct
round_id as round_id,
round_id as gitcoin_round_id,
round_num as round_number,
chain_id,
project_id as gitcoin_project_id,
match_amount_in_usd as amount_in_usd,
`timestamp`,
trim(title) as application_title,
trim(title) as project_application_title,
lower(recipient_address) as project_recipient_address
from {{ source("gitcoin", "all_matching") }}
where
Expand Down

0 comments on commit 9dce10f

Please sign in to comment.