diff --git a/warehouse/dbt/models/intermediate/metrics/code/int_code_metric__active_developers.sql b/warehouse/dbt/models/intermediate/metrics/code/int_code_metric__active_developers.sql index fcd6f3720..25c30285d 100644 --- a/warehouse/dbt/models/intermediate/metrics/code/int_code_metric__active_developers.sql +++ b/warehouse/dbt/models/intermediate/metrics/code/int_code_metric__active_developers.sql @@ -1,5 +1,6 @@ select events.project_id, + events.event_source, time_intervals.time_interval, 'active_developer_count' as metric, COUNT(distinct events.from_artifact_id) as amount @@ -10,4 +11,5 @@ where and events.bucket_day >= time_intervals.start_date group by events.project_id, + events.event_source, time_intervals.time_interval diff --git a/warehouse/dbt/models/intermediate/metrics/code/int_code_metric__bus_factor.sql b/warehouse/dbt/models/intermediate/metrics/code/int_code_metric__bus_factor.sql index a5996da23..6db223e41 100644 --- a/warehouse/dbt/models/intermediate/metrics/code/int_code_metric__bus_factor.sql +++ b/warehouse/dbt/models/intermediate/metrics/code/int_code_metric__bus_factor.sql @@ -2,6 +2,7 @@ with all_contributions as ( select project_id, from_artifact_id, + event_source, bucket_month, SUM(amount) as amount from {{ ref('int_events_monthly_to_project') }} @@ -9,6 +10,7 @@ with all_contributions as ( group by project_id, from_artifact_id, + event_source, bucket_month ), @@ -22,6 +24,7 @@ aggregated_contributions as ( select contributions.project_id, contributions.from_artifact_id, + contributions.event_source, time_intervals.time_interval, SUM(contributions.amount) as amount from contributions @@ -32,27 +35,29 @@ aggregated_contributions as ( group by contributions.project_id, contributions.from_artifact_id, + contributions.event_source, time_intervals.time_interval ), ranked_contributions as ( select project_id, + event_source, time_interval, from_artifact_id, amount, RANK() over ( - partition by project_id, time_interval + partition by project_id, event_source, time_interval order by amount desc ) as rank, SUM(amount) over ( - partition by project_id, time_interval + partition by project_id, event_source, time_interval ) as total_project_amount, SUM(amount) over ( - partition by project_id, time_interval + partition by project_id, event_source, time_interval order by amount desc rows between unbounded preceding and current row ) as cumulative_amount @@ -61,6 +66,7 @@ ranked_contributions as ( select project_id, + event_source, time_interval, 'bus_factor' as metric, MAX( @@ -74,4 +80,5 @@ from ranked_contributions group by project_id, + event_source, time_interval diff --git a/warehouse/dbt/models/intermediate/metrics/code/int_code_metric__commits_prs_issues.sql b/warehouse/dbt/models/intermediate/metrics/code/int_code_metric__commits_prs_issues.sql index 634193ef7..f0282850c 100644 --- a/warehouse/dbt/models/intermediate/metrics/code/int_code_metric__commits_prs_issues.sql +++ b/warehouse/dbt/models/intermediate/metrics/code/int_code_metric__commits_prs_issues.sql @@ -1,5 +1,6 @@ select events.project_id, + events.event_source, time_intervals.time_interval, CONCAT(LOWER(events.event_type), '_count') as metric, SUM(events.amount) as amount @@ -16,5 +17,6 @@ where ) group by events.project_id, + events.event_source, time_intervals.time_interval, events.event_type diff --git a/warehouse/dbt/models/intermediate/metrics/code/int_code_metric__contributors.sql b/warehouse/dbt/models/intermediate/metrics/code/int_code_metric__contributors.sql index 3a59fae6e..44e7e7860 100644 --- a/warehouse/dbt/models/intermediate/metrics/code/int_code_metric__contributors.sql +++ b/warehouse/dbt/models/intermediate/metrics/code/int_code_metric__contributors.sql @@ -1,5 +1,6 @@ select events.project_id, + events.event_source, time_intervals.time_interval, 'contributor_count' as metric, COUNT(distinct events.from_artifact_id) as amount @@ -14,4 +15,5 @@ where and events.bucket_day >= time_intervals.start_date group by events.project_id, + events.event_source, time_intervals.time_interval diff --git a/warehouse/dbt/models/intermediate/metrics/code/int_code_metric__fulltime_developers_avg.sql b/warehouse/dbt/models/intermediate/metrics/code/int_code_metric__fulltime_developers_average.sql similarity index 87% rename from warehouse/dbt/models/intermediate/metrics/code/int_code_metric__fulltime_developers_avg.sql rename to warehouse/dbt/models/intermediate/metrics/code/int_code_metric__fulltime_developers_average.sql index 8e1db8fbf..8304886dd 100644 --- a/warehouse/dbt/models/intermediate/metrics/code/int_code_metric__fulltime_developers_avg.sql +++ b/warehouse/dbt/models/intermediate/metrics/code/int_code_metric__fulltime_developers_average.sql @@ -3,6 +3,7 @@ with dev_stats as ( select events.project_id, + events.event_source, time_intervals.time_interval, events.from_artifact_id, TIMESTAMP_TRUNC(events.bucket_day, month) as bucket_month, @@ -14,6 +15,7 @@ with dev_stats as ( and events.bucket_day >= time_intervals.start_date group by events.project_id, + events.event_source, time_intervals.time_interval, events.from_artifact_id, TIMESTAMP_TRUNC(events.bucket_day, month) @@ -21,8 +23,9 @@ with dev_stats as ( select project_id, + event_source, time_interval, - 'fulltime_developer_avg' as metric, + 'fulltime_developer_average' as metric, ( COUNT(distinct from_artifact_id) / COUNT(distinct bucket_month) @@ -31,4 +34,5 @@ from dev_stats where amount >= {{ fulltime_dev_days }} group by project_id, + event_source, time_interval diff --git a/warehouse/dbt/models/intermediate/metrics/code/int_code_metric__new_contributors.sql b/warehouse/dbt/models/intermediate/metrics/code/int_code_metric__new_contributors.sql index 324c25a52..09834d4af 100644 --- a/warehouse/dbt/models/intermediate/metrics/code/int_code_metric__new_contributors.sql +++ b/warehouse/dbt/models/intermediate/metrics/code/int_code_metric__new_contributors.sql @@ -1,6 +1,7 @@ with user_stats as ( select from_artifact_id, + event_source, project_id, min(bucket_day) as first_day from {{ ref('int_events_daily_to_project') }} @@ -12,11 +13,13 @@ with user_stats as ( ) group by from_artifact_id, + event_source, project_id ) select events.project_id, + events.event_source, time_intervals.time_interval, 'new_contributor_count' as metric, count( @@ -31,6 +34,7 @@ inner join user_stats on events.from_artifact_id = user_stats.from_artifact_id and events.project_id = user_stats.project_id + and events.event_source = user_stats.event_source cross join {{ ref('int_time_intervals') }} as time_intervals where events.event_type in ( @@ -41,4 +45,5 @@ where and events.bucket_day >= time_intervals.start_date group by events.project_id, + events.event_source, time_intervals.time_interval diff --git a/warehouse/dbt/models/intermediate/metrics/int_code_metrics_by_project.sql b/warehouse/dbt/models/intermediate/metrics/int_code_metrics_by_project.sql index cfd0e288b..3bf82bba1 100644 --- a/warehouse/dbt/models/intermediate/metrics/int_code_metrics_by_project.sql +++ b/warehouse/dbt/models/intermediate/metrics/int_code_metrics_by_project.sql @@ -5,7 +5,8 @@ with metrics as ( union all select * from {{ ref('int_code_metric__contributors') }} union all - select * from {{ ref('int_code_metric__fulltime_developers_avg') }} + select * + from {{ ref('int_code_metric__fulltime_developers_average') }} union all select * from {{ ref('int_code_metric__new_contributors') }} ), @@ -13,6 +14,7 @@ with metrics as ( aggs as ( select project_id, + event_source, SUM( case when @@ -97,19 +99,22 @@ aggs as ( SUM( case when - metric = 'fulltime_developer_avg' + metric = 'fulltime_developer_average' and time_interval = '6 MONTHS' then amount else 0 end - ) as fulltime_developer_avg_6_months + ) as fulltime_developer_average_6_months from metrics - group by project_id + group by + project_id, + event_source ), repos as ( select project_id, + artifact_source as event_source, MIN(first_commit_time) as first_commit_date, MAX(last_commit_time) as last_commit_date, COUNT(distinct artifact_id) as repository_count, @@ -117,33 +122,58 @@ repos as ( SUM(fork_count) as fork_count from {{ ref('int_repo_metrics_by_project') }} --WHERE r.is_fork = false - group by project_id + group by + project_id, + artifact_source +), + +code_metrics as ( + select + repos.*, + aggs.* except (project_id, event_source) + from repos + left join aggs + on + repos.project_id = aggs.project_id + and repos.event_source = aggs.event_source +), + +project_metadata as ( + select + project_id, + project_source, + project_namespace, + project_name, + display_name, + 'GITHUB' as event_source + from {{ ref('int_projects') }} + ) select - int_projects.project_id, - int_projects.project_source, - int_projects.project_namespace, - int_projects.project_name, - int_projects.display_name, - repos.first_commit_date, - repos.last_commit_date, - repos.repository_count, - repos.star_count, - repos.fork_count, - aggs.contributor_count, - aggs.contributor_count_6_months, - aggs.new_contributor_count_6_months, - aggs.fulltime_developer_avg_6_months, - aggs.active_developer_count_6_months, - aggs.commit_count_6_months, - aggs.opened_pull_request_count_6_months, - aggs.merged_pull_request_count_6_months, - aggs.opened_issue_count_6_months, - aggs.closed_issue_count_6_months, - 'GITHUB' as repository_source -from {{ ref('int_projects') }} -left join aggs - on int_projects.project_id = aggs.project_id -left join repos - on int_projects.project_id = repos.project_id + project_metadata.project_id, + project_metadata.project_source, + project_metadata.project_namespace, + project_metadata.project_name, + project_metadata.display_name, + project_metadata.event_source, + code_metrics.first_commit_date, + code_metrics.last_commit_date, + code_metrics.repository_count, + code_metrics.star_count, + code_metrics.fork_count, + code_metrics.contributor_count, + code_metrics.contributor_count_6_months, + code_metrics.new_contributor_count_6_months, + code_metrics.fulltime_developer_average_6_months, + code_metrics.active_developer_count_6_months, + code_metrics.commit_count_6_months, + code_metrics.opened_pull_request_count_6_months, + code_metrics.merged_pull_request_count_6_months, + code_metrics.opened_issue_count_6_months, + code_metrics.closed_issue_count_6_months +from project_metadata +left join code_metrics + on + project_metadata.project_id = code_metrics.project_id + and project_metadata.event_source = code_metrics.event_source diff --git a/warehouse/dbt/models/intermediate/metrics/int_onchain_metrics_by_project.sql b/warehouse/dbt/models/intermediate/metrics/int_onchain_metrics_by_project.sql index 3488e3a73..221a7be56 100644 --- a/warehouse/dbt/models/intermediate/metrics/int_onchain_metrics_by_project.sql +++ b/warehouse/dbt/models/intermediate/metrics/int_onchain_metrics_by_project.sql @@ -32,7 +32,7 @@ with metrics as ( aggs as ( select project_id, - network, + event_source, SUM( case when @@ -162,7 +162,7 @@ aggs as ( from metrics group by project_id, - network + event_source ) select diff --git a/warehouse/dbt/models/intermediate/metrics/int_repo_metrics_by_project.sql b/warehouse/dbt/models/intermediate/metrics/int_repo_metrics_by_project.sql index 7d0d1b593..760e6490f 100644 --- a/warehouse/dbt/models/intermediate/metrics/int_repo_metrics_by_project.sql +++ b/warehouse/dbt/models/intermediate/metrics/int_repo_metrics_by_project.sql @@ -46,6 +46,7 @@ select int_artifacts_by_project.artifact_id, int_artifacts_by_project.artifact_namespace, int_artifacts_by_project.artifact_name, + int_artifacts_by_project.artifact_source, repo_snapshot.is_fork, repo_snapshot.fork_count, repo_snapshot.star_count, diff --git a/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__active_addresses.sql b/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__active_addresses.sql index d7348c244..16a3b3aa0 100644 --- a/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__active_addresses.sql +++ b/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__active_addresses.sql @@ -1,6 +1,6 @@ select events.project_id, - events.event_source as network, + events.event_source, time_intervals.time_interval, 'address_count' as metric, COUNT(distinct events.from_artifact_id) as amount diff --git a/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__active_contracts.sql b/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__active_contracts.sql index 727b7b7f4..37fc0a883 100644 --- a/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__active_contracts.sql +++ b/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__active_contracts.sql @@ -1,6 +1,6 @@ select events.project_id, - events.event_source as network, + events.event_source, time_intervals.time_interval, 'active_contract_count' as metric, COUNT(distinct events.to_artifact_id) as amount diff --git a/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__days_since_first_transaction.sql b/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__days_since_first_transaction.sql index fe51b41c4..b3f11b472 100644 --- a/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__days_since_first_transaction.sql +++ b/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__days_since_first_transaction.sql @@ -1,6 +1,6 @@ select events.project_id, - events.event_source as network, + events.event_source, time_intervals.time_interval, 'days_since_first_transaction' as metric, MAX( diff --git a/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__gas_fees.sql b/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__gas_fees.sql index df222bdda..4fdb1ad27 100644 --- a/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__gas_fees.sql +++ b/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__gas_fees.sql @@ -1,6 +1,6 @@ select events.project_id, - events.event_source as network, + events.event_source, time_intervals.time_interval, 'gas_fees' as metric, SUM(events.amount / 1e18) as amount diff --git a/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__high_low_activity_addresses.sql b/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__high_low_activity_addresses.sql index a5491ca09..d4be07671 100644 --- a/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__high_low_activity_addresses.sql +++ b/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__high_low_activity_addresses.sql @@ -5,7 +5,7 @@ with user_txn_totals as ( select events.from_artifact_id, - events.event_source as network, + events.event_source, events.project_id, time_intervals.time_interval, SUM(events.amount) as amount @@ -24,7 +24,7 @@ with user_txn_totals as ( high_activity as ( select project_id, - network, + event_source, time_interval, 'high_activity_address_count' as metric, COUNT(distinct from_artifact_id) as amount @@ -32,14 +32,14 @@ high_activity as ( where amount >= {{ high_activity_thresh }} group by project_id, - network, + event_source, time_interval ), low_activity as ( select project_id, - network, + event_source, time_interval, 'low_activity_address_count' as metric, COUNT(distinct from_artifact_id) as amount @@ -49,14 +49,14 @@ low_activity as ( and amount >= {{ low_activity_thresh }} group by project_id, - network, + event_source, time_interval ), medium_activity as ( select project_id, - network, + event_source, time_interval, 'medium_activity_address_count' as metric, COUNT(distinct from_artifact_id) as amount @@ -66,7 +66,7 @@ medium_activity as ( and amount >= {{ med_activity_thresh }} group by project_id, - network, + event_source, time_interval ) diff --git a/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__multi_project_addresses.sql b/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__multi_project_addresses.sql index 12adc43d2..ce272431a 100644 --- a/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__multi_project_addresses.sql +++ b/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__multi_project_addresses.sql @@ -1,7 +1,7 @@ with user_stats as ( select events.from_artifact_id, - events.event_source as network, + events.event_source, time_intervals.time_interval, COUNT(distinct events.project_id) as project_count from {{ ref('int_events_daily_to_project') }} as events @@ -17,7 +17,7 @@ with user_stats as ( select events.project_id, - events.event_source as network, + events.event_source, time_intervals.time_interval, 'multi_project_address_count' as metric, COUNT(distinct events.from_artifact_id) as amount @@ -26,7 +26,7 @@ cross join {{ ref('int_time_intervals') }} as time_intervals left join user_stats on events.from_artifact_id = user_stats.from_artifact_id - and events.event_source = user_stats.network + and events.event_source = user_stats.event_source and time_intervals.time_interval = user_stats.time_interval where events.event_type = 'CONTRACT_INVOCATION_SUCCESS_DAILY_COUNT' diff --git a/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__new_addresses.sql b/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__new_addresses.sql index dd459768e..634bcd2a3 100644 --- a/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__new_addresses.sql +++ b/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__new_addresses.sql @@ -1,7 +1,7 @@ with user_stats as ( select from_artifact_id, - event_source as network, + event_source, project_id, min(bucket_day) as first_day from {{ ref('int_events_daily_to_project') }} @@ -15,7 +15,7 @@ with user_stats as ( select events.project_id, - events.event_source as network, + events.event_source, time_intervals.time_interval, 'new_address_count' as metric, count( @@ -29,7 +29,7 @@ from {{ ref('int_events_daily_to_project') }} as events inner join user_stats on events.from_artifact_id = user_stats.from_artifact_id - and events.event_source = user_stats.network + and events.event_source = user_stats.event_source and events.project_id = user_stats.project_id cross join {{ ref('int_time_intervals') }} as time_intervals where diff --git a/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__returning_addresses.sql b/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__returning_addresses.sql index e89d8977c..05deeb3dc 100644 --- a/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__returning_addresses.sql +++ b/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__returning_addresses.sql @@ -1,7 +1,7 @@ with user_stats as ( select from_artifact_id, - event_source as network, + event_source, project_id, min(bucket_day) as first_day from {{ ref('int_events_daily_to_project') }} @@ -15,7 +15,7 @@ with user_stats as ( select events.project_id, - events.event_source as network, + events.event_source, time_intervals.time_interval, 'returning_address_count' as metric, count( @@ -29,7 +29,7 @@ from {{ ref('int_events_daily_to_project') }} as events inner join user_stats on events.from_artifact_id = user_stats.from_artifact_id - and events.event_source = user_stats.network + and events.event_source = user_stats.event_source and events.project_id = user_stats.project_id cross join {{ ref('int_time_intervals') }} as time_intervals where diff --git a/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__transactions.sql b/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__transactions.sql index 6f8bd5fd7..c33a8c292 100644 --- a/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__transactions.sql +++ b/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__transactions.sql @@ -1,6 +1,6 @@ select events.project_id, - events.event_source as network, + events.event_source, time_intervals.time_interval, 'transaction_count' as metric, SUM(events.amount) as amount diff --git a/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__trusted_transactions.sql b/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__trusted_transactions.sql index e17e6711f..08a6b713e 100644 --- a/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__trusted_transactions.sql +++ b/warehouse/dbt/models/intermediate/metrics/onchain/int_onchain_metric__trusted_transactions.sql @@ -1,6 +1,6 @@ select events.project_id, - events.event_source as network, + events.event_source, time_intervals.time_interval, 'transaction_count' as metric, SUM(events.amount) as amount diff --git a/warehouse/dbt/models/marts/metrics/code_metrics_by_project_v1.sql b/warehouse/dbt/models/marts/metrics/code_metrics_by_project_v1.sql index b572bd785..7ce6c9fad 100644 --- a/warehouse/dbt/models/marts/metrics/code_metrics_by_project_v1.sql +++ b/warehouse/dbt/models/marts/metrics/code_metrics_by_project_v1.sql @@ -10,7 +10,7 @@ select project_namespace, project_name, display_name, - repository_source, + event_source, repository_count, first_commit_date, last_commit_date, @@ -19,7 +19,7 @@ select contributor_count, contributor_count_6_months, new_contributor_count_6_months, - fulltime_developer_avg_6_months, + fulltime_developer_average_6_months, active_developer_count_6_months, commit_count_6_months, opened_pull_request_count_6_months, diff --git a/warehouse/dbt/models/marts/metrics/onchain_metrics_by_project_v1.sql b/warehouse/dbt/models/marts/metrics/onchain_metrics_by_project_v1.sql index 23b413dfb..3f229ef1c 100644 --- a/warehouse/dbt/models/marts/metrics/onchain_metrics_by_project_v1.sql +++ b/warehouse/dbt/models/marts/metrics/onchain_metrics_by_project_v1.sql @@ -10,7 +10,7 @@ select project_namespace, project_name, display_name, - network, + event_source, days_since_first_transaction, active_contract_count_90_days, transaction_count,