Conversation
D-source1602
added a commit
that referenced
this pull request
May 29, 2026
feat(anomaly): AI-powered carbon emission anomaly detection (rebased on main, port fix) — supersedes #10
NischalaV-4
pushed a commit
to NischalaV-4/CLIMATRIX
that referenced
this pull request
May 29, 2026
Original work by Anshika Sharma (PR D-source1602#10) — rebased on top of current main. Original PR was based on an old main (only PR D-source1602#5 merged) and the diff showed a 2300-line 'deletion' of PRs D-source1602#6, D-source1602#7, D-source1602#9 as a side-effect. This commit reconstructs only the additive changes: BACKEND - backend/src/routes/anomaly.routes.ts (new) Pure stats anomaly detector: rolling z-score (window=5) and sudden percentage spike. Stateless POST /api/v1/anomaly/detect endpoint. Severity grading (low/medium/high) by zScore and pct increase. Mounted via the established routes/index.ts pattern (consistent with /auth, /aqi, /reports), not via a parallel app.use in app.ts. FRONTEND - src/lib/anomaly.ts (new) Typed wrapper around the shared api() helper; uses VITE_API_URL. - src/App.tsx Adds RUN SPIKE SCAN button on the AI Anomaly Detection capability card with severity-colored result panel. BUG FIX vs original PR D-source1602#10: - Original frontend hard-coded http://localhost:5000/api/v1/anomaly/detect. Backend runs on :4000 — the feature would have 100% failed in the demo. Switched to api() helper which reads VITE_API_URL. Architecture preserved: the route shape mirrors what a future FastAPI + Isolation Forest microservice would expose, so swapping in real ML later is contained to the detect() function body.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces an AI-powered anomaly detection system for identifying sudden carbon emission spikes within ClimaCore.
The feature adds a backend anomaly detection API and integrates anomaly monitoring directly into the dashboard, enabling proactive detection of unusual emission events and improving environmental intelligence capabilities.
Changes Made
Backend
Added new anomaly detection route:
backend/src/routes/anomaly.tsImplemented anomaly detection logic using:
Detects anomalies when:
Returns:
API
Added endpoint:
Example request:
{ "readings": [ { "timestamp": "2026-05-29T10:00:00Z", "co2": 120 }, { "timestamp": "2026-05-29T11:00:00Z", "co2": 125 }, { "timestamp": "2026-05-29T12:00:00Z", "co2": 260 } ] }Frontend
Integrated anomaly detection into the dashboard.
Added AI anomaly scan capability.
Displays:
Maintains existing industrial/sketch-style UI.
Preserves existing dashboard, compliance, reporting, and heatmap functionality.
Impact
This enhancement improves environmental monitoring by automatically identifying abnormal emission patterns and providing actionable alerts before compliance issues escalate.
Testing
Future Improvements