diff --git a/warehouse/dbt/models/intermediate/metrics/int_funding_metrics_by_project.sql b/warehouse/dbt/models/intermediate/metrics/int_funding_metrics_by_project.sql new file mode 100644 index 000000000..c9031888b --- /dev/null +++ b/warehouse/dbt/models/intermediate/metrics/int_funding_metrics_by_project.sql @@ -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 diff --git a/warehouse/dbt/models/marts/metrics/funding_metrics_by_project_v1.sql b/warehouse/dbt/models/marts/metrics/funding_metrics_by_project_v1.sql new file mode 100644 index 000000000..224c51a77 --- /dev/null +++ b/warehouse/dbt/models/marts/metrics/funding_metrics_by_project_v1.sql @@ -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') }} diff --git a/warehouse/dbt/models/marts/metrics/metrics_v1__schema.yml b/warehouse/dbt/models/marts/metrics/metrics_v1__schema.yml index c2104e4d0..f449afef3 100644 --- a/warehouse/dbt/models/marts/metrics/metrics_v1__schema.yml +++ b/warehouse/dbt/models/marts/metrics/metrics_v1__schema.yml @@ -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. \ No newline at end of file + **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.