Skip to content

[Bug]: Analytics export filter uses display name "DoubtDesk AI" instead of email "ai@doubtdesk.com", inflating top contributor statistics #949

Description

@vipul674

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

  1. Ensure the classroom has at least one AI reply (created with userEmail: "ai@doubtdesk.com")
  2. As a teacher, call GET /api/analytics/export?classroomId=<id>
  3. Download the generated CSV file
  4. Observe that the "Top Contributors" section includes entries with name "DoubtDesk AI" or "ai@doubtdesk.com" (the AI)
  5. 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

  • OS: All
  • Browser: All

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendAPI routes, database, server logicgssoc'26GSSoC program issuelevel:advancedAdvanced level tasktype:bugBug fix

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions