|
| 1 | +DESCRIPTION > |
| 2 | + - `collection_insights_aggregate.pipe` serves aggregate insights metrics for a collection. |
| 3 | + - Returns a single row with metrics aggregated across every project in the collection, not one row per project. |
| 4 | + - Parameters: |
| 5 | + - `collectionSlug`: Required collection slug. insights_projects_populated_ds.collectionsSlugs already lists |
| 6 | + every collection each project belongs to (see insightsProjects_filtered.pipe for the same filter pattern), |
| 7 | + so this pipe resolves collection membership directly rather than requiring the caller to first look up a |
| 8 | + project id list. |
| 9 | + - Response: |
| 10 | + - `projectCount`: count of distinct projects in the collection. |
| 11 | + - `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. |
| 13 | + |
| 14 | +TAGS "Insights, Widget", "Collection" |
| 15 | + |
| 16 | +NODE collection_insights_aggregate_projects |
| 17 | +DESCRIPTION > |
| 18 | + Resolves the collection's member projects to their segment ids and health scores directly via |
| 19 | + collectionsSlugs, matching the same has(collectionsSlugs, ...) filter already used by |
| 20 | + insightsProjects_filtered.pipe. |
| 21 | + |
| 22 | +SQL > |
| 23 | + % |
| 24 | + SELECT id, segmentId, healthScore |
| 25 | + FROM insights_projects_populated_ds |
| 26 | + WHERE |
| 27 | + enabled = 1 |
| 28 | + AND has( |
| 29 | + collectionsSlugs, |
| 30 | + {{ String(collectionSlug, description="Filter by collection slug", required=True) }} |
| 31 | + ) |
| 32 | + |
| 33 | +NODE collection_insights_aggregate_results |
| 34 | +DESCRIPTION > |
| 35 | + Aggregates health score across matched projects and counts unique contributors across their segments in one pass |
| 36 | + |
| 37 | +SQL > |
| 38 | + SELECT |
| 39 | + (SELECT count(distinct id) FROM collection_insights_aggregate_projects) AS projectCount, |
| 40 | + uniq(ar.memberId) AS uniqueContributorCount, |
| 41 | + (SELECT round(avg(healthScore)) FROM collection_insights_aggregate_projects) AS avgHealthScore |
| 42 | + FROM activityRelations_deduplicated_cleaned_bucket_union AS ar |
| 43 | + WHERE |
| 44 | + ar.memberId != '' |
| 45 | + AND ar.segmentId IN (SELECT segmentId FROM collection_insights_aggregate_projects) |
| 46 | + AND (ar.type, ar.platform) IN ( |
| 47 | + SELECT activityType, platform |
| 48 | + FROM activityTypes |
| 49 | + WHERE isCodeContribution = 1 OR isCollaboration = 1 |
| 50 | + ) |
0 commit comments