Skip to content

Commit 569d53b

Browse files
committed
fix: resolve collection_insights_aggregate via collectionsSlugs, not project ids
- Takes collectionSlug directly instead of a caller-supplied project-id array, resolving collection membership via insights_projects_populated_ds.collectionsSlugs (has() filter, same pattern as insightsProjects_filtered.pipe). - Fixes segmentId resolution: project_insights_copy_ds has no segmentId column at all (confirmed by the Tinybird deploy error); insights_projects_populated_ds has both segmentId and healthScore. Verified live against Tinybird - returns correct projectCount, uniqueContributorCount, and avgHealthScore for a real collection. Signed-off-by: Gašper Grom <gasper.grom@gmail.com>
1 parent 7782241 commit 569d53b

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

services/libs/tinybird/pipes/collection_insights_aggregate.pipe

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
11
DESCRIPTION >
2-
- `collection_insights_aggregate.pipe` serves aggregate insights metrics for a collection (an arbitrary list of projects).
3-
- Returns a single row with metrics aggregated across all projects in the list, not one row per project.
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.
44
- Parameters:
5-
- `ids`: Required array of project ids (as returned by `project_insights.pipe`'s `id`/`ids`) to aggregate over.
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.
69
- Response:
7-
- `projectCount`: count of distinct project ids from the input list that matched an existing project.
8-
- `uniqueContributorCount`: total unique contributors across all matched projects, deduplicated (a contributor active on multiple projects in the list is counted once).
9-
- `avgHealthScore`: average of each matched project's health score, rounded.
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.
1013

1114
TAGS "Insights, Widget", "Collection"
1215

1316
NODE collection_insights_aggregate_projects
1417
DESCRIPTION >
15-
Resolves the input project ids to their segment ids, since activity data is keyed by segmentId, not project id
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.
1621

1722
SQL >
1823
%
1924
SELECT id, segmentId, healthScore
20-
FROM project_insights_copy_ds
25+
FROM insights_projects_populated_ds
2126
WHERE
22-
type = 'project'
23-
AND id IN {{ Array(ids, 'String', description="Filter by project id list", required=True) }}
27+
enabled = 1
28+
AND has(
29+
collectionsSlugs,
30+
{{ String(collectionSlug, description="Filter by collection slug", required=True) }}
31+
)
2432

2533
NODE collection_insights_aggregate_results
2634
DESCRIPTION >

0 commit comments

Comments
 (0)