diff --git a/services/libs/tinybird/datasources/org_page_activities_timeseries_copy_ds.datasource b/services/libs/tinybird/datasources/org_page_activities_timeseries_copy_ds.datasource new file mode 100644 index 0000000000..592a7af102 --- /dev/null +++ b/services/libs/tinybird/datasources/org_page_activities_timeseries_copy_ds.datasource @@ -0,0 +1,14 @@ +DESCRIPTION > + Precomputed yearly activity counts per organization for the org page. Rebuilt nightly by org_page_activities_timeseries_copy_pipe. + One row per (organizationId, startDate). Used by org_page_activities_timeseries.pipe for cheap request-time lookups. + +SCHEMA > + `organizationId` String, + `startDate` Date, + `endDate` Date, + `activityCount` UInt64, + `computedAt` DateTime + +ENGINE ReplacingMergeTree +ENGINE_SORTING_KEY organizationId, startDate +ENGINE_VER computedAt diff --git a/services/libs/tinybird/datasources/org_page_contributors_timeseries_copy_ds.datasource b/services/libs/tinybird/datasources/org_page_contributors_timeseries_copy_ds.datasource new file mode 100644 index 0000000000..61641f00b5 --- /dev/null +++ b/services/libs/tinybird/datasources/org_page_contributors_timeseries_copy_ds.datasource @@ -0,0 +1,14 @@ +DESCRIPTION > + Precomputed yearly unique contributor counts per organization for the org page. Rebuilt nightly by org_page_contributors_timeseries_copy_pipe. + One row per (organizationId, startDate). Used by org_page_contributors_timeseries.pipe for cheap request-time lookups. + +SCHEMA > + `organizationId` String, + `startDate` Date, + `endDate` Date, + `contributorCount` UInt64, + `computedAt` DateTime + +ENGINE ReplacingMergeTree +ENGINE_SORTING_KEY organizationId, startDate +ENGINE_VER computedAt diff --git a/services/libs/tinybird/datasources/org_page_kpis_copy_ds.datasource b/services/libs/tinybird/datasources/org_page_kpis_copy_ds.datasource new file mode 100644 index 0000000000..177731c6dc --- /dev/null +++ b/services/libs/tinybird/datasources/org_page_kpis_copy_ds.datasource @@ -0,0 +1,15 @@ +DESCRIPTION > + Precomputed organization-level KPIs for the org page. Rebuilt nightly by org_page_kpis_copy_pipe. + One row per organizationId. Used by org_page_kpis.pipe for cheap request-time lookups. + +SCHEMA > + `organizationId` String, + `activeContributors` UInt64, + `activeContributorsPrevious` UInt64, + `maintainerRoles` UInt64, + `criticalProjects` UInt64, + `computedAt` DateTime + +ENGINE ReplacingMergeTree +ENGINE_SORTING_KEY organizationId +ENGINE_VER computedAt diff --git a/services/libs/tinybird/datasources/org_page_projects_copy_ds.datasource b/services/libs/tinybird/datasources/org_page_projects_copy_ds.datasource new file mode 100644 index 0000000000..8ac6529e0a --- /dev/null +++ b/services/libs/tinybird/datasources/org_page_projects_copy_ds.datasource @@ -0,0 +1,25 @@ +DESCRIPTION > + Precomputed per-org per-project metrics for the org page. Rebuilt nightly by org_page_projects_copy_pipe. + One row per (organizationId, segmentId). Used by org_page_projects.pipe. + +SCHEMA > + `organizationId` String, + `segmentId` String, + `projectSlug` String, + `projectName` String, + `projectLogo` String, + `activityCount` UInt64, + `contributorCount` UInt64, + `maintainersCount` UInt64, + `totalContributors` UInt64, + `orgContributors` UInt64, + `totalCommits` UInt64, + `orgCommits` UInt64, + `totalPrsOpened` UInt64, + `orgPrsOpened` UInt64, + `technicalScore` Float64, + `computedAt` DateTime + +ENGINE ReplacingMergeTree +ENGINE_SORTING_KEY organizationId, segmentId +ENGINE_VER computedAt diff --git a/services/libs/tinybird/pipes/org_page_activities_timeseries.pipe b/services/libs/tinybird/pipes/org_page_activities_timeseries.pipe new file mode 100644 index 0000000000..45e8644268 --- /dev/null +++ b/services/libs/tinybird/pipes/org_page_activities_timeseries.pipe @@ -0,0 +1,18 @@ +DESCRIPTION > + Activity timeseries for a given organization, bucketed by year (all-time). + +TAGS "Organization page" + +NODE org_slug_lookup +SQL > + % + SELECT id + FROM organizations_populated_slug + WHERE slug = {{ String(orgSlug, '', description="Organization slug", required=True) }} + +NODE org_page_activities_timeseries_data +SQL > + SELECT startDate, endDate, activityCount + FROM org_page_activities_timeseries_copy_ds FINAL + WHERE organizationId = (SELECT id FROM org_slug_lookup) + ORDER BY startDate diff --git a/services/libs/tinybird/pipes/org_page_activities_timeseries_copy_pipe.pipe b/services/libs/tinybird/pipes/org_page_activities_timeseries_copy_pipe.pipe new file mode 100644 index 0000000000..ec4fb4c61a --- /dev/null +++ b/services/libs/tinybird/pipes/org_page_activities_timeseries_copy_pipe.pipe @@ -0,0 +1,22 @@ +DESCRIPTION > + Nightly copy pipe that precomputes yearly activity counts per organization for the org page. + Writes one row per (organizationId, startDate) into org_page_activities_timeseries_copy_ds. + +TAGS "Organization page" + +NODE org_page_activities_timeseries_copy_pipe_data +SQL > + SELECT + organizationId, + toStartOfYear(timestamp) AS startDate, + toDate(toStartOfYear(timestamp) + INTERVAL 1 YEAR - INTERVAL 1 DAY) AS endDate, + count() AS activityCount, + now() AS computedAt + FROM activityRelations_deduplicated_cleaned_bucket_union + WHERE organizationId != '' AND timestamp >= '2016-01-01' + GROUP BY organizationId, startDate, endDate + +TYPE COPY +TARGET_DATASOURCE org_page_activities_timeseries_copy_ds +COPY_MODE replace +COPY_SCHEDULE 30 1 * * * diff --git a/services/libs/tinybird/pipes/org_page_contributors.pipe b/services/libs/tinybird/pipes/org_page_contributors.pipe new file mode 100644 index 0000000000..672816bbcc --- /dev/null +++ b/services/libs/tinybird/pipes/org_page_contributors.pipe @@ -0,0 +1,74 @@ +DESCRIPTION > + Top contributors for a given organization leaderboard. + Returns members sorted by contribution count within the specified date range. + +TAGS "Organization page" + +NODE org_slug_lookup +SQL > + % + SELECT id + FROM organizations_populated_slug + WHERE slug = {{ String(orgSlug, '', description="Organization slug", required=True) }} + +NODE org_page_contributors_activity_aggregates +SQL > + % + {% if Boolean(count, false) %} + SELECT count(distinct memberId) + FROM activityRelations_deduplicated_cleaned_bucket_union + WHERE + organizationId = (SELECT id FROM org_slug_lookup) + {% if defined(startDate) %} + AND timestamp + >= {{ DateTime(startDate, description="Filter activity timestamp after") }} + {% end %} + {% if defined(endDate) %} + AND timestamp < {{ DateTime(endDate, description="Filter activity timestamp before") }} + {% end %} + {% else %} + SELECT + memberId, + count() as "contributionCount", + ROUND(COUNT(*) * 100.0 / SUM(COUNT(*)) OVER (), 2) as "contributionPercentage" + FROM activityRelations_deduplicated_cleaned_bucket_union + WHERE + organizationId = (SELECT id FROM org_slug_lookup) + {% if defined(startDate) %} + AND timestamp + >= {{ DateTime(startDate, description="Filter activity timestamp after") }} + {% end %} + {% if defined(endDate) %} + AND timestamp < {{ DateTime(endDate, description="Filter activity timestamp before") }} + {% end %} + GROUP BY memberId + ORDER BY contributionCount DESC, memberId DESC + LIMIT {{ Int32(limit, 10) }} + OFFSET {{ Int32(offset, 0) }} + {% end %} + +NODE org_page_contributors_leaderboard +SQL > + % + {% if Boolean(count, false) %} + SELECT count(distinct memberId) as count + FROM activityRelations_deduplicated_cleaned_bucket_union + WHERE + organizationId = (SELECT id FROM org_slug_lookup) + {% if defined(startDate) %} AND timestamp >= {{ DateTime(startDate) }} {% end %} + {% if defined(endDate) %} AND timestamp < {{ DateTime(endDate) }} {% end %} + {% else %} + SELECT + m.id, + m.avatar, + m.displayName, + m.githubHandleArray, + agg.contributionCount, + agg.contributionPercentage, + mr.roles + FROM members_sorted AS m ANY + INNER JOIN org_page_contributors_activity_aggregates agg ON agg.memberId = m.id + LEFT JOIN member_roles mr ON mr.memberId = m.id + WHERE m.id IN (SELECT memberId FROM org_page_contributors_activity_aggregates) + ORDER BY agg.contributionCount DESC + {% end %} diff --git a/services/libs/tinybird/pipes/org_page_contributors_timeseries.pipe b/services/libs/tinybird/pipes/org_page_contributors_timeseries.pipe new file mode 100644 index 0000000000..684edb208d --- /dev/null +++ b/services/libs/tinybird/pipes/org_page_contributors_timeseries.pipe @@ -0,0 +1,18 @@ +DESCRIPTION > + Contributor count timeseries for a given organization, bucketed by year (all-time). + +TAGS "Organization page" + +NODE org_slug_lookup +SQL > + % + SELECT id + FROM organizations_populated_slug + WHERE slug = {{ String(orgSlug, '', description="Organization slug", required=True) }} + +NODE org_page_contributors_timeseries_data +SQL > + SELECT startDate, endDate, contributorCount + FROM org_page_contributors_timeseries_copy_ds FINAL + WHERE organizationId = (SELECT id FROM org_slug_lookup) + ORDER BY startDate diff --git a/services/libs/tinybird/pipes/org_page_contributors_timeseries_copy_pipe.pipe b/services/libs/tinybird/pipes/org_page_contributors_timeseries_copy_pipe.pipe new file mode 100644 index 0000000000..2d594cc229 --- /dev/null +++ b/services/libs/tinybird/pipes/org_page_contributors_timeseries_copy_pipe.pipe @@ -0,0 +1,22 @@ +DESCRIPTION > + Nightly copy pipe that precomputes yearly unique contributor counts per organization for the org page. + Writes one row per (organizationId, startDate) into org_page_contributors_timeseries_copy_ds. + +TAGS "Organization page" + +NODE org_page_contributors_timeseries_copy_pipe_data +SQL > + SELECT + organizationId, + toStartOfYear(timestamp) AS startDate, + toDate(toStartOfYear(timestamp) + INTERVAL 1 YEAR - INTERVAL 1 DAY) AS endDate, + uniq(memberId) AS contributorCount, + now() AS computedAt + FROM activityRelations_deduplicated_cleaned_bucket_union + WHERE organizationId != '' AND timestamp >= '2016-01-01' + GROUP BY organizationId, startDate, endDate + +TYPE COPY +TARGET_DATASOURCE org_page_contributors_timeseries_copy_ds +COPY_MODE replace +COPY_SCHEDULE 45 1 * * * diff --git a/services/libs/tinybird/pipes/org_page_kpis.pipe b/services/libs/tinybird/pipes/org_page_kpis.pipe new file mode 100644 index 0000000000..b28bdb973b --- /dev/null +++ b/services/libs/tinybird/pipes/org_page_kpis.pipe @@ -0,0 +1,34 @@ +DESCRIPTION > + Returns KPIs for a given organization from the precomputed org_page_kpis_copy_ds. + Includes trend calculations comparing current to previous 365-day period. + +TAGS "Organization page" + +NODE org_slug_lookup +SQL > + % + SELECT id + FROM organizations_populated_slug + WHERE slug = {{ String(orgSlug, '', description="Organization slug", required=True) }} + +NODE org_page_kpis_main +SQL > + SELECT + activeContributors, + if( + activeContributorsPrevious = 0, + 0, + round( + (toInt64(activeContributors) - toInt64(activeContributorsPrevious)) + / activeContributorsPrevious + * 100, + 1 + ) + ) AS activeContributorsTrend, + toInt64(activeContributors) + - toInt64(activeContributorsPrevious) AS activeContributorsTrendAbsolute, + activeContributorsPrevious AS activeContributorsTrendPrevious, + maintainerRoles, + criticalProjects + FROM org_page_kpis_copy_ds FINAL + WHERE organizationId = (SELECT id FROM org_slug_lookup) diff --git a/services/libs/tinybird/pipes/org_page_kpis_copy_pipe.pipe b/services/libs/tinybird/pipes/org_page_kpis_copy_pipe.pipe new file mode 100644 index 0000000000..2424dcf6a2 --- /dev/null +++ b/services/libs/tinybird/pipes/org_page_kpis_copy_pipe.pipe @@ -0,0 +1,84 @@ +DESCRIPTION > + Nightly copy pipe that precomputes org-level KPIs for the org page. + Writes one row per organizationId into org_page_kpis_copy_ds. + +TAGS "Organization page" + +NODE org_page_kpis_current_contributors +DESCRIPTION > + Active contributors per org in the last 365 days + +SQL > + SELECT organizationId, uniq(memberId) AS activeContributors + FROM activityRelations_deduplicated_cleaned_bucket_union + WHERE + organizationId != '' + AND timestamp >= toStartOfDay(now() - toIntervalDay(365)) + AND timestamp < toStartOfDay(now() + toIntervalDay(1)) + GROUP BY organizationId + +NODE org_page_kpis_previous_contributors +DESCRIPTION > + Active contributors per org in the prior 365-day window (for trend calc) + +SQL > + SELECT organizationId, uniq(memberId) AS activeContributorsPrevious + FROM activityRelations_deduplicated_cleaned_bucket_union + WHERE + organizationId != '' + AND timestamp >= toStartOfDay(now() - toIntervalDay(730)) + AND timestamp < toStartOfDay(now() - toIntervalDay(365)) + GROUP BY organizationId + +NODE org_page_kpis_maintainer_roles +DESCRIPTION > + Count of active maintainer role assignments per org + +SQL > + SELECT organizationId, uniq((memberId, insightsProjectId)) AS maintainerRoles + FROM maintainers_roles_copy_ds + WHERE role = 'maintainer' AND toYear(endDate) <= 1970 AND organizationId != '' + GROUP BY organizationId + +NODE org_page_kpis_critical_projects +DESCRIPTION > + Count of distinct projects (segmentIds) an org contributed to in the last 365 days. + Serves as the "critical projects" placeholder until a real criticality filter is added. + +SQL > + SELECT organizationId, uniq(segmentId) AS criticalProjects + FROM activityRelations_deduplicated_cleaned_bucket_union + WHERE + organizationId != '' + AND timestamp >= toStartOfDay(now() - toIntervalDay(365)) + AND timestamp < toStartOfDay(now() + toIntervalDay(1)) + GROUP BY organizationId + +NODE org_page_kpis_final +DESCRIPTION > + Join all nodes into one row per org + +SQL > + SELECT + coalesce( + c.organizationId, p.organizationId, m.organizationId, cp.organizationId + ) AS organizationId, + coalesce(c.activeContributors, 0) AS activeContributors, + coalesce(p.activeContributorsPrevious, 0) AS activeContributorsPrevious, + coalesce(m.maintainerRoles, 0) AS maintainerRoles, + coalesce(cp.criticalProjects, 0) AS criticalProjects, + now() AS computedAt + FROM org_page_kpis_current_contributors c + FULL OUTER JOIN org_page_kpis_previous_contributors p ON c.organizationId = p.organizationId + FULL OUTER JOIN + org_page_kpis_maintainer_roles m + ON coalesce(c.organizationId, p.organizationId) = m.organizationId + FULL OUTER JOIN + org_page_kpis_critical_projects cp + ON coalesce(c.organizationId, p.organizationId, m.organizationId) = cp.organizationId + WHERE organizationId != '' + +TYPE COPY +TARGET_DATASOURCE org_page_kpis_copy_ds +COPY_MODE replace +COPY_SCHEDULE 15 1 * * * diff --git a/services/libs/tinybird/pipes/org_page_profile.pipe b/services/libs/tinybird/pipes/org_page_profile.pipe new file mode 100644 index 0000000000..fc8d76665a --- /dev/null +++ b/services/libs/tinybird/pipes/org_page_profile.pipe @@ -0,0 +1,66 @@ +DESCRIPTION > + Organization profile for the org page. Returns one row for a given orgId. + Joins organizationIdentities for website and domain. + +TAGS "Organization page" + +NODE org_slug_lookup +SQL > + % + SELECT id + FROM organizations_populated_slug + WHERE slug = {{ String(orgSlug, '', description="Organization slug", required=True) }} + +NODE org_page_profile_base +SQL > + SELECT id, displayName, logo, size AS employeeCount, industry, headline AS description + FROM organizations FINAL + WHERE id = (SELECT id FROM org_slug_lookup) + +NODE org_page_profile_website +SQL > + SELECT organizationId, argMax(value, updatedAt) AS website + FROM organizationIdentities FINAL + WHERE organizationId = (SELECT id FROM org_slug_lookup) AND type = 'primary-domain' + GROUP BY organizationId + +NODE org_page_profile_membership +SQL > + SELECT + organizationId, + replaceRegexpOne( + argMax( + if( + tier IN ( + 'Silver Membership', + 'Platinum Membership', + 'Gold Membership', + 'Associate Membership' + ), + tier, + extract(productName, ' - (.+) \\(') + ), + updatedAt + ), + ' Membership$', + '' + ) AS membership + FROM lfxMemberships FINAL + WHERE organizationId = (SELECT id FROM org_slug_lookup) AND project = 'The Linux Foundation' + GROUP BY organizationId + +NODE org_page_profile_final +SQL > + SELECT + b.id, + b.displayName, + b.logo, + b.employeeCount, + b.industry, + b.description, + w.website, + domain(w.website) AS domain, + m.membership + FROM org_page_profile_base b + LEFT JOIN org_page_profile_website w ON b.id = w.organizationId + LEFT JOIN org_page_profile_membership m ON b.id = m.organizationId diff --git a/services/libs/tinybird/pipes/org_page_projects.pipe b/services/libs/tinybird/pipes/org_page_projects.pipe new file mode 100644 index 0000000000..61cfd2fa00 --- /dev/null +++ b/services/libs/tinybird/pipes/org_page_projects.pipe @@ -0,0 +1,35 @@ +DESCRIPTION > + Returns the list of projects an organization contributed to in the last 365 days, + read from the precomputed org_page_projects_copy_ds. + +TAGS "Organization page" + +NODE org_slug_lookup +SQL > + % + SELECT id + FROM organizations_populated_slug + WHERE slug = {{ String(orgSlug, '', description="Organization slug", required=True) }} + +NODE org_page_projects_main +SQL > + % + SELECT + projectSlug, + projectName, + projectLogo, + activityCount, + contributorCount, + maintainersCount, + totalContributors, + orgContributors, + totalCommits, + orgCommits, + totalPrsOpened, + orgPrsOpened, + technicalScore + FROM org_page_projects_copy_ds FINAL + WHERE organizationId = (SELECT id FROM org_slug_lookup) + ORDER BY technicalScore DESC, contributorCount DESC, activityCount DESC + LIMIT {{ Int32(limit, 21, description="Page size + 1 for hasMore detection") }} + OFFSET {{ Int32(offset, 0, description="Pagination offset") }} diff --git a/services/libs/tinybird/pipes/org_page_projects_copy_pipe.pipe b/services/libs/tinybird/pipes/org_page_projects_copy_pipe.pipe new file mode 100644 index 0000000000..36035b0f61 --- /dev/null +++ b/services/libs/tinybird/pipes/org_page_projects_copy_pipe.pipe @@ -0,0 +1,184 @@ +DESCRIPTION > + Nightly copy pipe that precomputes per-org per-project metrics for the org page. + Writes one row per (organizationId, segmentId) into org_page_projects_copy_ds. + +TAGS "Organization page" + +NODE org_page_projects_contribution_activity_types +DESCRIPTION > + Collaboration and code contribution activity types (mirrors leaderboards filter) + +SQL > + SELECT activityType, platform FROM activityTypes FINAL WHERE isCollaboration OR isCodeContribution + +NODE org_page_projects_org_segment_activity +DESCRIPTION > + Collaboration/code activity and contributor counts per org per project segment in the last 365 days + +SQL > + SELECT + ar.organizationId, ar.segmentId, count() AS activityCount, uniq(ar.memberId) AS contributorCount + FROM activityRelations_deduplicated_cleaned_bucket_union ar + INNER JOIN + org_page_projects_contribution_activity_types at + ON ar.type = at.activityType + AND ar.platform = at.platform + WHERE + ar.organizationId != '' + AND ar.timestamp >= toStartOfDay(now() - toIntervalDay(365)) + AND ar.timestamp < toStartOfDay(now() + toIntervalDay(1)) + GROUP BY ar.organizationId, ar.segmentId + +NODE org_page_projects_with_meta +DESCRIPTION > + Enrich with project name, logo, slug, and id from insights_projects_populated_ds + +SQL > + SELECT + a.organizationId, + a.segmentId, + p.id AS projectId, + p.slug AS projectSlug, + p.name AS projectName, + p.logoUrl AS projectLogo, + a.activityCount, + a.contributorCount, + now() AS computedAt + FROM org_page_projects_org_segment_activity a + LEFT JOIN insights_projects_populated_ds p ON a.segmentId = p.segmentId + WHERE p.slug != '' + +NODE org_page_projects_score_project_code_activity +DESCRIPTION > + Project-level code-only activity totals over the last 24 months, used only for the technical score + +SQL > + SELECT + segmentId, + countIf( + case when activityId != '' then activityId else null end, type = 'authored-commit' + ) AS scoreCommits, + countIf( + case when activityId != '' then activityId else null end, + type IN ('pull_request-opened', 'merge_request-opened', 'changeset-created') + ) AS scorePrsOpened, + uniqIf( + memberId, + type + IN ('authored-commit', 'pull_request-opened', 'merge_request-opened', 'changeset-created') + ) AS scoreContributorCount + FROM activityRelations_deduplicated_cleaned_bucket_union + WHERE + timestamp >= toStartOfDay(now() - toIntervalDay(730)) + AND timestamp < toStartOfDay(now() + toIntervalDay(1)) + GROUP BY segmentId + +NODE org_page_projects_score_org_code_activity +DESCRIPTION > + Org-level code-only activity totals over the last 24 months, used only for the technical score + +SQL > + SELECT + segmentId, + organizationId, + countIf( + case when activityId != '' then activityId else null end, type = 'authored-commit' + ) AS scoreOrgCommits, + countIf( + case when activityId != '' then activityId else null end, + type IN ('pull_request-opened', 'merge_request-opened', 'changeset-created') + ) AS scoreOrgPrsOpened, + uniqIf( + memberId, + type + IN ('authored-commit', 'pull_request-opened', 'merge_request-opened', 'changeset-created') + ) AS scoreOrgContributorCount + FROM activityRelations_deduplicated_cleaned_bucket_union + WHERE + organizationId != '' + AND timestamp >= toStartOfDay(now() - toIntervalDay(730)) + AND timestamp < toStartOfDay(now() + toIntervalDay(1)) + GROUP BY segmentId, organizationId + +NODE org_page_projects_score_active_maintainers +DESCRIPTION > + Active maintainers per (insightsProjectId, organizationId): active means started and not ended more than 24 months ago + +SQL > + SELECT insightsProjectId, organizationId, uniq(memberId) AS scoreMaintainersCount + FROM maintainers_roles_copy_ds + WHERE + role = 'maintainer' + AND organizationId != '' + AND startDate <= now() + AND (toYear(endDate) <= 1970 OR endDate >= now() - toIntervalDay(730)) + GROUP BY insightsProjectId, organizationId + +NODE org_page_projects_with_scores +DESCRIPTION > + Compute technical influence score from spec-compliant 24-month code-only inputs. + Display columns (maintainersCount, totalContributors, etc.) remain sourced from org_dash_metric_copy_ds. + +SQL > + SELECT + w.organizationId AS organizationId, + w.segmentId AS segmentId, + w.projectSlug AS projectSlug, + w.projectName AS projectName, + w.projectLogo AS projectLogo, + w.activityCount AS activityCount, + w.contributorCount AS contributorCount, + ifNull(m.maintainersCount, 0) AS maintainersCount, + ifNull(m.contributorCount, 0) AS totalContributors, + ifNull(m.orgContributorCount, 0) AS orgContributors, + ifNull(m.commits, 0) AS totalCommits, + ifNull(m.orgCommits, 0) AS orgCommits, + ifNull(m.prsOpened, 0) AS totalPrsOpened, + ifNull(m.orgPrsOpened, 0) AS orgPrsOpened, + ( + -- Maintainers: 3 pts if org has at least 1 active maintainer (24-month window) + -- Contributors: 0 if no share; 1.1 if share in (0, 0.1%]; share + 1.0 otherwise + CASE WHEN ifNull(mt.scoreMaintainersCount, 0) >= 1 THEN 3.0 ELSE 0.0 END + CASE + WHEN + ifNull(pa.scoreContributorCount, 0) = 0 + OR ifNull(oa.scoreOrgContributorCount, 0) = 0 + THEN 0.0 + WHEN oa.scoreOrgContributorCount * 100.0 / pa.scoreContributorCount <= 0.1 + THEN 1.1 + ELSE round(oa.scoreOrgContributorCount * 100.0 / pa.scoreContributorCount + 1.0, 1) + END + -- Commits: same formula + + CASE + WHEN ifNull(pa.scoreCommits, 0) = 0 OR ifNull(oa.scoreOrgCommits, 0) = 0 + THEN 0.0 + WHEN oa.scoreOrgCommits * 100.0 / pa.scoreCommits <= 0.1 + THEN 1.1 + ELSE round(oa.scoreOrgCommits * 100.0 / pa.scoreCommits + 1.0, 1) + END + -- PRs opened: same formula + + CASE + WHEN ifNull(pa.scorePrsOpened, 0) = 0 OR ifNull(oa.scoreOrgPrsOpened, 0) = 0 + THEN 0.0 + WHEN oa.scoreOrgPrsOpened * 100.0 / pa.scorePrsOpened <= 0.1 + THEN 1.1 + ELSE round(oa.scoreOrgPrsOpened * 100.0 / pa.scorePrsOpened + 1.0, 1) + END + ) AS technicalScore, + w.computedAt AS computedAt + FROM org_page_projects_with_meta w + LEFT JOIN + org_dash_metric_copy_ds m ON w.organizationId = m.organizationId AND w.projectSlug = m.slug + LEFT JOIN org_page_projects_score_project_code_activity pa ON w.segmentId = pa.segmentId + LEFT JOIN + org_page_projects_score_org_code_activity oa + ON w.segmentId = oa.segmentId + AND w.organizationId = oa.organizationId + LEFT JOIN + org_page_projects_score_active_maintainers mt + ON w.projectId = mt.insightsProjectId + AND w.organizationId = mt.organizationId + +TYPE COPY +TARGET_DATASOURCE org_page_projects_copy_ds +COPY_MODE replace +COPY_SCHEDULE 30 1 * * * diff --git a/services/libs/tinybird/pipes/organizations_leaderboard.pipe b/services/libs/tinybird/pipes/organizations_leaderboard.pipe index 23272d0977..c4ea670d92 100644 --- a/services/libs/tinybird/pipes/organizations_leaderboard.pipe +++ b/services/libs/tinybird/pipes/organizations_leaderboard.pipe @@ -18,7 +18,7 @@ DESCRIPTION > - `offset`: Optional integer for result pagination, defaults to 0 - Response: - Count mode (`count=true`): `count` (total number of organizations) - - Data mode (default): `id`, `logo`, `displayName`, `contributionCount`, `contributionPercentage` + - Data mode (default): `id`, `slug`, `logo`, `displayName`, `contributionCount`, `contributionPercentage` NODE organizations_leaderboard_paginated SQL > @@ -28,13 +28,14 @@ SQL > {% else %} SELECT org.id AS id, + org.slug AS slug, org.logo AS logo, org.displayName AS displayName, COUNT(af.id) AS contributionCount, ROUND(COUNT(af.id) * 100.0 / SUM(COUNT(af.id)) OVER (), 2) AS contributionPercentage FROM activities_filtered af - JOIN organizations org FINAL ON org.id = af.organizationId - GROUP BY org.id, org.logo, org.displayName + JOIN organizations_populated_slug org ON org.id = af.organizationId + GROUP BY org.id, org.slug, org.logo, org.displayName ORDER BY contributionCount DESC, id desc LIMIT {{ Int32(limit, 10) }} OFFSET {{ Int32(offset, 0) }}