Skip to content

Commit

Permalink
feat: additional rf4 repo eligibility checks (#1535)
Browse files Browse the repository at this point in the history
* feat: additional rf4 repo eligibility checks

* chore: add repo checks to overall project checks

* fix: clean up todos

* fix: handling empty arrays
  • Loading branch information
ccerv1 authored May 27, 2024
1 parent ddbfbdb commit e1f317c
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ repo_stats as (
MIN(time) as first_commit_time,
MAX(time) as last_commit_time,
COUNT(distinct TIMESTAMP_TRUNC(time, day)) as days_with_commits_count,
COUNT(distinct from_artifact_id) as contributors_to_repo_count
COUNT(distinct from_artifact_id) as contributors_to_repo_count,
SUM(amount) as commit_count
from {{ ref('int_events_to_project') }}
where event_type = 'COMMIT_CODE'
group by
Expand All @@ -58,7 +59,8 @@ select
repo_stats.first_commit_time,
repo_stats.last_commit_time,
repo_stats.days_with_commits_count,
repo_stats.contributors_to_repo_count
repo_stats.contributors_to_repo_count,
repo_stats.commit_count
from {{ ref('int_artifacts_by_project') }}
left join repo_snapshot
on int_artifacts_by_project.artifact_id = repo_snapshot.artifact_id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{# TODO: double check the math on total_months #}
with txns as (
select
project_id,
Expand All @@ -21,9 +22,7 @@ maas as (
),

total_months as (
select
{# TODO: double check this math #}
(DATE_DIFF(max_month, min_month, day) + 30) / 30 as months
select (DATE_DIFF(max_month, min_month, day) + 30) / 30 as months
from (
select
MIN(bucket_month) as min_month,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{# TODO: double check the math on total_months #}
with txns as (
select
project_id,
Expand All @@ -22,9 +23,7 @@ maus as (
),

total_months as (
select
{# TODO: double check this math #}
(DATE_DIFF(max_month, min_month, day) + 30) / 30 as months
select (DATE_DIFF(max_month, min_month, day) + 30) / 30 as months
from (
select
MIN(bucket_month) as min_month,
Expand Down
59 changes: 46 additions & 13 deletions warehouse/dbt/models/marts/superchain/rf4_project_verification.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,23 @@
- Review thresholds for unique_addresses, date_first_transaction, and
days_with_onchain_activity_in_range.
- Filter on contracts that are linked to Retro Funding applications (from Agora data)
- Integrate with repo_stats_by_project to check licensing and other repo requirements.
#}

with project_stats as (
with repo_stats as (
select
project_id,
ARRAY_AGG(repo_name) as eligible_repos
from (
select
project_id,
CONCAT(artifact_namespace, '/', artifact_name) as repo_name
from {{ ref('rf4_repo_stats_by_project') }}
where approval_status = 'approved'
)
group by project_id
),

onchain_stats as (
select
project_id,
project_name,
Expand All @@ -23,23 +36,38 @@ with project_stats as (
from {{ ref('rf4_events_daily_to_project') }}
where
event_type = 'CONTRACT_INVOCATION_SUCCESS_DAILY_COUNT'
and bucket_day >= '2024-01-01'
and bucket_day >= '2023-10-01'
group by
project_id,
project_name
),

tests as (
project_stats as (
select
onchain_stats.*,
COALESCE(repo_stats.eligible_repos, array<STRING>[]) as eligible_repos
from onchain_stats
left join repo_stats
on onchain_stats.project_id = repo_stats.project_id
left join {{ ref('projects_by_collection_v1') }}
on onchain_stats.project_id = projects_by_collection_v1.project_id
where
projects_by_collection_v1.collection_name = 'op-onchain'
),

checks as (
select
project_id,
project_name,
eligible_repos,
unique_addresses,
date_first_transaction,
days_with_onchain_activity_in_range,
unique_addresses >= 420 as test_unique_addresses,
date_first_transaction < '2024-03-01' as test_date_first_transaction,
ARRAY_LENGTH(eligible_repos) >= 1 as check_eligible_repos,
unique_addresses >= 420 as check_unique_addresses,
date_first_transaction < '2024-03-01' as check_date_first_transaction,
days_with_onchain_activity_in_range >= 10
as test_days_with_onchain_activity_in_range
as check_days_with_onchain_activity_in_range
from project_stats
)

Expand All @@ -49,9 +77,14 @@ select
unique_addresses,
date_first_transaction,
days_with_onchain_activity_in_range,
test_unique_addresses,
test_date_first_transaction,
test_days_with_onchain_activity_in_range,
test_unique_addresses and test_date_first_transaction
and test_days_with_onchain_activity_in_range as test_all
from tests
check_eligible_repos,
check_unique_addresses,
check_date_first_transaction,
check_days_with_onchain_activity_in_range,
(
check_eligible_repos
and check_unique_addresses
and check_date_first_transaction
and check_days_with_onchain_activity_in_range
) as meets_all_requirements
from checks
96 changes: 61 additions & 35 deletions warehouse/dbt/models/marts/superchain/rf4_repo_stats_by_project.sql
Original file line number Diff line number Diff line change
@@ -1,42 +1,68 @@
{# TODO: Review licenses https://spdx.org/licenses/ for OSI Approved #}
{# TODO: update with actual collection for RF4 #}
with repo_snapshot as (
select
project_id,
artifact_namespace,
artifact_name,
is_fork,
fork_count,
star_count,
first_commit_time,
last_commit_time,
days_with_commits_count,
commit_count,
language,
license_spdx_id,
case
when license_spdx_id in (
'MIT', 'MIT-0', 'Apache-2.0', 'Unlicense',
'BSD-2-Clause', 'BSD-3-Clause', 'BSD-3-Clause-Clear',
'AGPL-3.0', 'GPL-3.0', 'LGPL-3.0', 'GPL-2.0', 'MPL-2.0', 'LGPL-2.1',
'OFL-1.1', 'EPL-1.0', 'EPL-2.0', 'OFL-1.1', 'EUPL-1.2', 'OSL-3.0',
'ISC', '0BSD', 'NCSA', 'Zlib'
) then 'Permissive'
when license_spdx_id in (
'BSD-4-Clause', 'WTFPL',
'CC0-1.0', 'CC-BY-SA-4.0', 'CC-BY-4.0'
) then 'Restrictive'
when license_spdx_id = 'NOASSERTION'
then 'Custom'
else 'Unspecified'
end as license_type
from {{ ref('int_repo_metrics_by_project') }}
)

select
int_repo_metrics_by_project.project_id,
int_repo_metrics_by_project.artifact_id,
repo_snapshot.project_id,
projects_v1.project_name,
int_repo_metrics_by_project.artifact_namespace,
int_repo_metrics_by_project.artifact_name,
int_repo_metrics_by_project.is_fork,
int_repo_metrics_by_project.fork_count,
int_repo_metrics_by_project.star_count,
--int_repo_metrics_by_project.first_commit_time,
--int_repo_metrics_by_project.last_commit_time,
--int_repo_metrics_by_project.days_with_commits_count,
--int_repo_metrics_by_project.contributors_to_repo_count,
int_repo_metrics_by_project.language,
int_repo_metrics_by_project.license_spdx_id,
repo_snapshot.artifact_namespace,
repo_snapshot.artifact_name,
repo_snapshot.is_fork,
repo_snapshot.fork_count,
repo_snapshot.star_count,
repo_snapshot.first_commit_time,
repo_snapshot.last_commit_time,
repo_snapshot.days_with_commits_count,
repo_snapshot.commit_count,
repo_snapshot.language,
repo_snapshot.license_spdx_id,
repo_snapshot.license_type,
case
{# TODO: Review licenses https://spdx.org/licenses/ for OSI Approved #}
when int_repo_metrics_by_project.license_spdx_id in (
'MIT', 'MIT-0', 'Apache-2.0', 'Unlicense',
'BSD-2-Clause', 'BSD-3-Clause', 'BSD-3-Clause-Clear',
'AGPL-3.0', 'GPL-3.0', 'LGPL-3.0', 'GPL-2.0', 'MPL-2.0', 'LGPL-2.1',
'OFL-1.1', 'EPL-1.0', 'EPL-2.0', 'OFL-1.1', 'EUPL-1.2', 'OSL-3.0',
'ISC', '0BSD', 'NCSA', 'Zlib'
) then 'Permissive'
when int_repo_metrics_by_project.license_spdx_id in (
'BSD-4-Clause', 'WTFPL',
'CC0-1.0', 'CC-BY-SA-4.0', 'CC-BY-4.0'
) then 'Restrictive'
when int_repo_metrics_by_project.license_spdx_id = 'NOASSERTION'
then 'Custom'
else 'Unspecified'
end as license_type
from {{ ref('int_repo_metrics_by_project') }}
when (
repo_snapshot.commit_count >= 10
and repo_snapshot.days_with_commits_count >= 3
and repo_snapshot.first_commit_time < '2024-05-01'
and repo_snapshot.star_count >= 10
and repo_snapshot.language in ('Solidity', 'JavaScript', 'TypeScript')
) then 'approved'
else 'review'
end as approval_status
from repo_snapshot
left join {{ ref('projects_v1') }}
on int_repo_metrics_by_project.project_id = projects_v1.project_id
on repo_snapshot.project_id = projects_v1.project_id
left join {{ ref('projects_by_collection_v1') }}
on
int_repo_metrics_by_project.project_id
= projects_by_collection_v1.project_id
on repo_snapshot.project_id = projects_by_collection_v1.project_id
where
{# TODO: update with actual collection for RF4 #}
projects_by_collection_v1.collection_name = 'op-onchain'
and repo_snapshot.license_type != 'Unspecified'

0 comments on commit e1f317c

Please sign in to comment.