Skip to content

fix: count distinct districts/IPs instead of total rows in reportValidation.service.ts (#1967)#2139

Merged
dipexplorer merged 1 commit into
RatLoopz:mainfrom
nimkarprachi17:fix/distinct-count-report-validation-1967
Jun 20, 2026
Merged

fix: count distinct districts/IPs instead of total rows in reportValidation.service.ts (#1967)#2139
dipexplorer merged 1 commit into
RatLoopz:mainfrom
nimkarprachi17:fix/distinct-count-report-validation-1967

Conversation

@nimkarprachi17

Copy link
Copy Markdown
Contributor

🛑 STOP: Assignment & File Scope Check

  • I am assigned to this issue.
  • I verified that this PR ONLY touches the required files.

📋 PR Summary & Link

  • Closes [BUG] reportValidation.service.ts counts total rows instead of distinct values in geographic spread and Sybil checks #1967
  • Summary: Fixes apps/api/src/services/reportValidation.service.ts where the geographic spread check and both Sybil detection checks used select(column, { count: "exact", head: true }), which returns the total row count matching the filter, not a distinct count. This meant 5 duplicate reports from the same IP/district were incorrectly counted as 5 distinct districts/reporters. Fixed by fetching the actual rows and computing distinct counts in JavaScript with a Set, since the lookback window (burstDeadline, last hour) keeps the result set small. Added unit tests in apps/api/tests/reportValidation.service.test.ts verifying duplicate reports from the same IP/district do not trigger the distinct-value thresholds, while genuinely distinct districts/IPs still correctly trigger them.

📸 Proof of Work (Screenshots / Logs)

image image

🏷️ PR Type

  • 🐛 type: bug
  • 🧪 type: testing

✅ Checklist

  • My PR has a linked issue (Closes #1967)
  • I have pulled the latest main and resolved any conflicts

Files changed:

  • apps/api/src/services/reportValidation.service.ts — fixed 3 distinct-count queries (geographic spread, Sybil-by-district, Sybil-by-medicine) to use Set-based distinct counting instead of count: "exact" row counts
  • apps/api/tests/reportValidation.service.test.ts — new file, 4 unit tests covering both the bug scenario (duplicate reports not over-counted) and the correct-detection scenario (genuinely distinct districts/IPs still flagged)

@github-project-automation github-project-automation Bot moved this to 📥 Backlog in SahiDawa Workflow Jun 20, 2026
@github-actions github-actions Bot added gssoc:approved Approved for gssoc level:advanced 55 pts status: open-for-all type:bug Something isn't working labels Jun 20, 2026
@dipexplorer dipexplorer merged commit 315c03a into RatLoopz:main Jun 20, 2026
17 of 18 checks passed
@github-project-automation github-project-automation Bot moved this from 📥 Backlog to 🎉 Merged in SahiDawa Workflow Jun 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🎉 Congratulations @nimkarprachi17! Your Pull Request "fix: count distinct districts/IPs instead of total rows in reportValidation.service.ts (#1967)" has been successfully merged by @dipexplorer.

Thank you for your valuable contribution to SahiDawa! 🇮🇳
If this was for GSSoC 2026, your work is officially merged and valid. Keep up the great work and feel free to claim other open issues. 🚀

Follow us on LinkedIn: https://www.linkedin.com/company/ratloopz/ to get shoutout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: 🎉 Merged

Development

Successfully merging this pull request may close these issues.

[BUG] reportValidation.service.ts counts total rows instead of distinct values in geographic spread and Sybil checks

2 participants