Bug Description
The analytics CSV export endpoint (GET /api/analytics/export) has an incorrect filter string for excluding AI replies from the top contributors calculation. It uses "DoubtDesk AI" (a display name) instead of "ai@doubtdesk.com" (the actual email address used for AI replies). Since no reply has userEmail equal to "DoubtDesk AI", the filter never matches any rows, and AI replies are included in the top contributor counts — artificially inflating them.
Steps to Reproduce
- Ensure the classroom has at least one AI reply (created with
userEmail: "ai@doubtdesk.com")
- As a teacher, call
GET /api/analytics/export?classroomId=<id>
- Download the generated CSV file
- Observe that the "Top Contributors" section includes entries with name
"DoubtDesk AI" or "ai@doubtdesk.com" (the AI)
- Compare with the JSON analytics endpoint (
GET /api/analytics) which correctly filters out AI replies
Expected Behavior
The export CSV should exclude AI-generated replies from the top contributors list, matching the behavior of the regular analytics JSON endpoint.
Actual Behavior
In src/app/api/analytics/export/route.ts (approximately line 174):
ne(repliesTable.userEmail, "DoubtDesk AI")
This uses the display name "DoubtDesk AI" which never matches any stored userEmail. The correct filter should be "ai@doubtdesk.com".
Compare with the regular analytics endpoint in src/app/api/analytics/route.ts (approximately line 98):
ne(repliesTable.userEmail, 'ai@doubtdesk.com')
The regular endpoint correctly uses the email address, so it properly excludes AI replies from top contributors. The export endpoint does not.
Environment
Additional Context
The AI reply user email is stored as "ai@doubtdesk.com" (confirmed in the recentAIReplies query at line ~100 of the regular analytics route which filters eq(repliesTable.userEmail, 'ai@doubtdesk.com')). The export route's "DoubtDesk AI" string is likely a display name, not a database value, which is why it doesn't match any rows.
Files affected:
src/app/api/analytics/export/route.ts — incorrect filter value
src/app/api/analytics/route.ts — correct filter value (reference)
Suggested Fix
Change the filter in src/app/api/analytics/export/route.ts from:
ne(repliesTable.userEmail, "DoubtDesk AI")
to:
ne(repliesTable.userEmail, "ai@doubtdesk.com")
This will align the export endpoint's behavior with the regular JSON analytics endpoint.
GSSoC 2026
I would like to work on this issue under GSSoC 2026. Please assign it to me.
Bug Description
The analytics CSV export endpoint (
GET /api/analytics/export) has an incorrect filter string for excluding AI replies from the top contributors calculation. It uses"DoubtDesk AI"(a display name) instead of"ai@doubtdesk.com"(the actual email address used for AI replies). Since no reply hasuserEmailequal to"DoubtDesk AI", the filter never matches any rows, and AI replies are included in the top contributor counts — artificially inflating them.Steps to Reproduce
userEmail: "ai@doubtdesk.com")GET /api/analytics/export?classroomId=<id>"DoubtDesk AI"or"ai@doubtdesk.com"(the AI)GET /api/analytics) which correctly filters out AI repliesExpected Behavior
The export CSV should exclude AI-generated replies from the top contributors list, matching the behavior of the regular analytics JSON endpoint.
Actual Behavior
In
src/app/api/analytics/export/route.ts(approximately line 174):This uses the display name
"DoubtDesk AI"which never matches any storeduserEmail. The correct filter should be"ai@doubtdesk.com".Compare with the regular analytics endpoint in
src/app/api/analytics/route.ts(approximately line 98):The regular endpoint correctly uses the email address, so it properly excludes AI replies from top contributors. The export endpoint does not.
Environment
Additional Context
The AI reply user email is stored as
"ai@doubtdesk.com"(confirmed in therecentAIRepliesquery at line ~100 of the regular analytics route which filterseq(repliesTable.userEmail, 'ai@doubtdesk.com')). The export route's"DoubtDesk AI"string is likely a display name, not a database value, which is why it doesn't match any rows.Files affected:
src/app/api/analytics/export/route.ts— incorrect filter valuesrc/app/api/analytics/route.ts— correct filter value (reference)Suggested Fix
Change the filter in
src/app/api/analytics/export/route.tsfrom:to:
This will align the export endpoint's behavior with the regular JSON analytics endpoint.
GSSoC 2026
I would like to work on this issue under GSSoC 2026. Please assign it to me.