Skip to content

Commit a64af87

Browse files
committed
feat: optimize data processing for ai code tracker
Signed-off-by: Gašper Grom <gasper.grom@gmail.com>
1 parent bdeb596 commit a64af87

3 files changed

Lines changed: 53 additions & 19 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
DESCRIPTION >
2+
- `ai_code_tracker_commits_ds` contains only authored-commit activities, pre-filtered from the full activities table.
3+
- Populated daily by `ai_code_tracker_commits_copy.pipe`.
4+
- Stores only the fields needed for AI tool detection: timestamp, title, body, attributes.
5+
- Reduces the dataset from ~1B rows to only commits, with sorting keys optimized for the AI pattern matching step.
6+
7+
TAGS "Report"
8+
9+
SCHEMA >
10+
`timestamp` DateTime,
11+
`title` String DEFAULT '',
12+
`body` String DEFAULT '',
13+
`attributes` String DEFAULT ''
14+
15+
ENGINE MergeTree
16+
ENGINE_PARTITION_KEY toYear(timestamp)
17+
ENGINE_SORTING_KEY timestamp
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
DESCRIPTION >
2+
- `ai_code_tracker_commits_copy.pipe` extracts only authored-commit rows from `activities_deduplicated_ds`.
3+
- Runs daily to populate `ai_code_tracker_commits_ds` with a small subset (~commits only) of the full 1B+ activities table.
4+
- This intermediate datasource is then used by `ai_code_tracker_copy.pipe` for fast AI pattern matching.
5+
6+
TAGS "Report"
7+
8+
NODE ai_code_tracker_commits_copy_result
9+
SQL >
10+
SELECT
11+
a.timestamp,
12+
a.title,
13+
a.body,
14+
a.attributes
15+
FROM activities_deduplicated_ds a
16+
WHERE a.type = 'authored-commit'
17+
18+
TYPE COPY
19+
TARGET_DATASOURCE ai_code_tracker_commits_ds
20+
COPY_MODE replace
21+
COPY_SCHEDULE 0 2 * * *

services/libs/tinybird/pipes/ai_code_tracker_copy.pipe

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
DESCRIPTION >
22
- `ai_code_tracker_copy.pipe` materializes AI-assisted commit counts into `ai_code_tracker_ds`.
3-
- Runs daily to scan `activities_deduplicated_ds` for commits matching AI tool patterns.
3+
- Runs daily (after commits copy) reading from `ai_code_tracker_commits_ds` (only commits, not all 1B+ activities).
44
- Classifies commits by AI tool based on title, body, and attributes content.
55
- Stores monthly aggregates per tool plus total commits per month (toolKey = '__total__').
66
- Uses multiSearchAnyCaseInsensitive for fast single-pass pre-filtering before classification.
@@ -9,34 +9,30 @@ TAGS "Report"
99

1010
NODE ai_code_tracker_copy_totals
1111
DESCRIPTION >
12-
Total commits per month - no LIKE scanning needed, just a simple count
12+
Total commits per month - simple count, no string scanning
1313
SQL >
1414
SELECT
15-
toStartOfMonth(a.timestamp) AS monthStart,
15+
toStartOfMonth(timestamp) AS monthStart,
1616
'__total__' AS toolKey,
1717
count() AS commitCount
18-
FROM activities_deduplicated_ds a
19-
WHERE a.type = 'authored-commit'
18+
FROM ai_code_tracker_commits_ds
2019
GROUP BY monthStart
2120

2221
NODE ai_code_tracker_copy_prefilter
2322
DESCRIPTION >
24-
Fast pre-filter: only keep commits that contain ANY AI keyword in title, body, or attributes.
25-
multiSearchAnyCaseInsensitive does a single pass instead of dozens of separate LIKE checks.
23+
Fast pre-filter: only keep commits containing ANY AI keyword.
24+
multiSearchAnyCaseInsensitive does a single pass instead of dozens of separate checks.
2625
SQL >
2726
SELECT
28-
toStartOfMonth(a.timestamp) AS monthStart,
29-
a.title,
30-
a.body,
31-
a.attributes
32-
FROM activities_deduplicated_ds a
27+
toStartOfMonth(timestamp) AS monthStart,
28+
title,
29+
body,
30+
attributes
31+
FROM ai_code_tracker_commits_ds
3332
WHERE
34-
a.type = 'authored-commit'
35-
AND (
36-
multiSearchAnyCaseInsensitive(a.title, ['copilot', 'chatgpt', 'claude', 'cursor', 'codewhisperer', 'gemini', 'codeium', 'aider', 'devin', 'tabnine', 'ai-generated', 'ai generated']) != 0
37-
OR multiSearchAnyCaseInsensitive(a.body, ['copilot', 'chatgpt', 'claude', 'cursor', 'codewhisperer', 'gemini', 'codeium', 'aider', 'devin', 'tabnine', 'ai-generated', 'ai generated', 'co-authored-by']) != 0
38-
OR multiSearchAnyCaseInsensitive(a.attributes, ['copilot', 'ai-generated']) != 0
39-
)
33+
multiSearchAnyCaseInsensitive(title, ['copilot', 'chatgpt', 'claude', 'cursor', 'codewhisperer', 'gemini', 'codeium', 'aider', 'devin', 'tabnine', 'ai-generated', 'ai generated']) != 0
34+
OR multiSearchAnyCaseInsensitive(body, ['copilot', 'chatgpt', 'claude', 'cursor', 'codewhisperer', 'gemini', 'codeium', 'aider', 'devin', 'tabnine', 'ai-generated', 'ai generated', 'co-authored-by']) != 0
35+
OR multiSearchAnyCaseInsensitive(attributes, ['copilot', 'ai-generated']) != 0
4036

4137
NODE ai_code_tracker_copy_classify
4238
DESCRIPTION >
@@ -45,7 +41,7 @@ SQL >
4541
SELECT
4642
monthStart,
4743
multiIf(
48-
positionCaseInsensitive(title, 'github copilot') > 0 OR positionCaseInsensitive(body, 'co-authored-by') > 0 AND positionCaseInsensitive(body, 'copilot') > 0 OR positionCaseInsensitive(attributes, 'copilot') > 0, 'github-copilot',
44+
positionCaseInsensitive(title, 'github copilot') > 0 OR (positionCaseInsensitive(body, 'co-authored-by') > 0 AND positionCaseInsensitive(body, 'copilot') > 0) OR positionCaseInsensitive(attributes, 'copilot') > 0, 'github-copilot',
4945
positionCaseInsensitive(title, 'cursor') > 0 OR positionCaseInsensitive(body, 'cursor') > 0, 'cursor',
5046
positionCaseInsensitive(title, 'claude') > 0 OR positionCaseInsensitive(body, 'claude') > 0, 'claude',
5147
positionCaseInsensitive(title, 'chatgpt') > 0 OR positionCaseInsensitive(body, 'chatgpt') > 0, 'chatgpt',

0 commit comments

Comments
 (0)