-
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.
feat: create
funding_metrics_by_project_v1
mart (#2331)
* feat: create `funding_metrics_by_project` mart * fix: only use `deposit` events for `funding` * fix: use `placeholder` as project namespace * fix: place `placeholder` in the correct spot
- Loading branch information
Showing
3 changed files
with
134 additions
and
1 deletion.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
warehouse/dbt/models/intermediate/metrics/int_funding_metrics_by_project.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,81 @@ | ||
{{ | ||
config( | ||
materialized='table' | ||
) | ||
}} | ||
|
||
with open_collective_funding_events as ( | ||
select * | ||
from {{ ref('int_events') }} | ||
where | ||
event_source = 'OPEN_COLLECTIVE' | ||
and event_type = 'CREDIT' | ||
), | ||
|
||
oss_grants_funding_events as ( | ||
select * | ||
from {{ ref('int_oss_funding_grants_to_project') }} | ||
), | ||
|
||
all_funding_events as ( | ||
select | ||
TIMESTAMP_TRUNC(`time`, day) as `time`, | ||
to_artifact_id as project_id, | ||
event_source as project_source, | ||
to_artifact_namespace as project_namespace, | ||
to_artifact_name as project_name, | ||
to_artifact_name as display_name, | ||
event_source, | ||
from_artifact_id, | ||
amount | ||
from open_collective_funding_events | ||
union all | ||
select | ||
TIMESTAMP_TRUNC(`time`, day) as `time`, | ||
to_project_id as project_id, | ||
event_source as project_source, | ||
'UNSPECIFIED' as project_namespace, | ||
to_project_name as project_name, | ||
to_project_name as display_name, | ||
event_source, | ||
from_project_id as from_artifact_id, | ||
amount | ||
from oss_grants_funding_events | ||
), | ||
|
||
final_funding_metrics as ( | ||
select | ||
project_id, | ||
project_source, | ||
project_namespace, | ||
project_name, | ||
display_name, | ||
event_source, | ||
COUNT(distinct from_artifact_id) as total_funders_count, | ||
SUM(amount) as total_funding_received_usd, | ||
SUM(case | ||
when `time` >= TIMESTAMP(DATE_SUB(CURRENT_DATE(), interval 6 month)) then amount | ||
else 0 | ||
end) as total_funding_received_usd_6_months | ||
from all_funding_events | ||
group by | ||
project_id, | ||
project_source, | ||
project_namespace, | ||
project_name, | ||
display_name, | ||
event_source | ||
) | ||
|
||
select | ||
project_id, | ||
project_source, | ||
project_namespace, | ||
project_name, | ||
display_name, | ||
event_source, | ||
total_funders_count, | ||
total_funding_received_usd, | ||
total_funding_received_usd_6_months | ||
from final_funding_metrics | ||
where total_funding_received_usd > 0 |
17 changes: 17 additions & 0 deletions
17
warehouse/dbt/models/marts/metrics/funding_metrics_by_project_v1.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,17 @@ | ||
{{ | ||
config(meta = { | ||
'sync_to_db': True | ||
}) | ||
}} | ||
|
||
select | ||
project_id, | ||
project_source, | ||
project_namespace, | ||
project_name, | ||
display_name, | ||
event_source, | ||
total_funders_count, | ||
total_funding_received_usd, | ||
total_funding_received_usd_6_months | ||
from {{ ref('int_funding_metrics_by_project') }} |
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