Skip to content

B2.2: Add /insights/trends aggregation pipeline and index support for… - #1056

Open
mansipatel765-sk wants to merge 3 commits into
mainfrom
EB/MUP/B2.2-insights-aggregation-pipelines
Open

mansipatel765-sk wants to merge 3 commits into
mainfrom
EB/MUP/B2.2-insights-aggregation-pipelines

Conversation

@mansipatel765-sk

@mansipatel765-sk mansipatel765-sk commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Task

B2.2 (Shared, under B2 – Detection Insights and Analytics Extension)

Summary

Added a new /insights/trends aggregation pipeline (detections grouped by day, reusing existing filter/normalization helpers) and a new compound index on the events collection (species, sensorId, timestamp). Species/sensorId filtered queries now use the index (IXSCAN) instead of a full collection scan. Date-range-only and unfiltered queries still do a COLLSCAN because the date filter runs on the computed _normalizedTs field. Also verified daily totals across the supported timestamp formats (Date and ISO strings, grouped by UTC day).

Evidence

See src/production/backend/docs/sprint2/B2.2-insights-aggregation-index-support.md for the timestamp format check, explain() results from the actual endpoint pipelines, and full test steps.

Reviewer

As per Sprint 2 allocation (B2, Shared) — no reviewer added per team instruction.

@Maneesh-Kumar-Maddini Maneesh-Kumar-Maddini left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

o timestamp defect was identified during review. Please provide a focused check showing correct daily totals for the supported timestamp formats, along with execution-plan evidence for the actual aggregation queries. Approval is pending that verificatio

@mansipatel765-sk

Copy link
Copy Markdown
Contributor Author

Hi @Maneesh-Kumar-Maddini, thanks for the review. Your comment looks cut off on my side (it starts with "o timestamp defect..." and ends at "verificatio"), so I've read it as asking me to prove the daily totals and plans. Let me know if I got it wrong. I've updated the writeup with two things:

  1. Timestamp check: 7 test events (Date, ISO with Z, ISO with ms, ISO with +10:00 offset, ISO with no timezone, an invalid string, a numeric epoch). Daily totals came out correct, grouped by UTC day: 2026-09-21 = 4 and 2026-09-22 = 1. The invalid string and the number are skipped by design.

  2. Execution plans: taken from the app's actual /insights/trends pipelines. Species + sensorId filters use the new index (IXSCAN). Date-range-only and unfiltered queries still do a COLLSCAN, because the date filter runs on the computed field. I also removed my earlier PROJECTION_COVERED claim, since the real pipeline shows a FETCH.

@Maneesh-Kumar-Maddini

Copy link
Copy Markdown
Collaborator

Thanks, Mansi. You interpreted my truncated comment correctly: it should have started with “No timestamp defect was identified during review.” I was requesting evidence of correct daily totals across supported timestamp formats and execution plans for the actual pipelines. The updated evidence addresses that request and correctly explains the remaining collection scans. Please resolve the conflict in insights.py, preserve the shared timestamp/filter behaviour, and rerun the checks on the reconciled version before approval.

Signed-off-by: nandu1231239 <83577828+nandu1231239@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants