Skip to content

Commit e5a299d

Browse files
committed
fix: exclude non-onboarded projects from collection avgHealthScore
Signed-off-by: Gašper Grom <gasper.grom@gmail.com> (cherry picked from commit e151768ef9644cd25602fed132fa789be2be7e69)
1 parent 4c5d3ee commit e5a299d

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

services/libs/tinybird/pipes/collection_insights_aggregate.pipe

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ DESCRIPTION >
99
- Response:
1010
- `projectCount`: count of distinct projects in the collection.
1111
- `uniqueContributorCount`: total unique contributors across all projects in the collection, deduplicated (a contributor active on multiple projects in the collection is counted once).
12-
- `avgHealthScore`: average of each project's health score in the collection, rounded.
12+
- `avgHealthScore`: average health score across the collection's onboarded projects, rounded. A project
13+
is "onboarded" when it has at least one contributor or organization attributed to it (same definition
14+
used by insightsProjects_filtered.pipe's `onboarded` filter and the frontend's project-row `isOnboarded`
15+
check) — projects with no attributed contributors/organizations have no meaningful health signal yet
16+
and would otherwise pull the average down artificially.
1317

1418
TAGS "Insights, Widget", "Collection"
1519

@@ -21,7 +25,7 @@ DESCRIPTION >
2125

2226
SQL >
2327
%
24-
SELECT id, segmentId, healthScore
28+
SELECT id, segmentId, healthScore, organizationCount, contributorCount
2529
FROM insights_projects_populated_ds
2630
WHERE
2731
enabled = 1
@@ -38,7 +42,11 @@ SQL >
3842
SELECT
3943
(SELECT count(distinct id) FROM collection_insights_aggregate_projects) AS projectCount,
4044
uniq(ar.memberId) AS uniqueContributorCount,
41-
(SELECT round(avg(healthScore)) FROM collection_insights_aggregate_projects) AS avgHealthScore
45+
(
46+
SELECT round(avg(healthScore))
47+
FROM collection_insights_aggregate_projects
48+
WHERE NOT (organizationCount = 0 AND contributorCount = 0)
49+
) AS avgHealthScore
4250
FROM activityRelations_deduplicated_cleaned_bucket_union AS ar
4351
WHERE
4452
ar.memberId != ''

0 commit comments

Comments
 (0)