Skip to content

Commit

Permalink
feat: create funding_metrics_by_project_v1 mart (#2331)
Browse files Browse the repository at this point in the history
* 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
Jabolol authored Oct 8, 2024
1 parent 12756b2 commit a51536c
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 1 deletion.
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
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') }}
37 changes: 36 additions & 1 deletion warehouse/dbt/models/marts/metrics/metrics_v1__schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,39 @@ models:
**Low Activity Address Count (90 Days)**: Number of low activity addresses in the last 90 days.
- name: multi_project_address_count_90_days
description: >
**Multi-Project Address Count (90 Days)**: Number of addresses interacting with multiple projects in the last 90 days.
**Multi-Project Address Count (90 Days)**: Number of addresses interacting with multiple projects in the last 90 days.
- name: funding_metrics_by_project_v1
meta:
#...
contributors: oso-team
config:
tags: ['funding-metrics', 'impact-metrics']
description: "Funding metrics for open source software projects, organized by project and funding source."
columns:
- name: project_id
description: >
**Project ID**: A unique project id (generated by OSO).
- name: project_source
description: >
**Project Source**: The source of where the project is named and defined.
- name: project_namespace
description: >
**Project Namespace**: The namespace of the user or team that has defined the project.
- name: project_name
description: >
**Project Name**: A unique human-readable project name.
- name: display_name
description: >
**Display Name**: The display name of the project.
- name: event_source
description: >
**Event Source**: The source of the event data.
- name: total_funders_count
description: >
**Total Funders Count**: Total number of distinct funders.
- name: total_funding_received_usd
description: >
**Total Funding Received**: All-time total funding received in USD.
- name: total_funding_received_usd_6_months
description: >
**Total Funding Received (6 Months)**: Total funding received in the last 6 months in USD.

0 comments on commit a51536c

Please sign in to comment.