Skip to content

Add AI-powered carbon emission anomaly detection and dashboard integration#10

Open
BRUH-on wants to merge 1 commit into
mainfrom
anomaly
Open

Add AI-powered carbon emission anomaly detection and dashboard integration#10
BRUH-on wants to merge 1 commit into
mainfrom
anomaly

Conversation

@BRUH-on

@BRUH-on BRUH-on commented May 29, 2026

Copy link
Copy Markdown
Collaborator

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.ts
  • Implemented anomaly detection logic using:

    • Rolling mean
    • Rolling standard deviation
    • Z-score analysis
    • Sudden percentage increase detection
  • Detects anomalies when:

    • Z-score > 2.5
    • CO₂ increase exceeds 40% compared to previous reading
  • Returns:

    • Anomaly status
    • Severity level
    • Confidence score
    • Detection reason
    • Summary information

API

Added endpoint:

POST /api/v1/anomaly/detect

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:

    • Carbon spike alerts
    • Severity classification
    • Confidence percentage
    • Detection reason
  • 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

  • Verified backend route registration.
  • Verified anomaly detection API responses.
  • Tested emission spike scenarios.
  • Confirmed dashboard integration and alert rendering.
  • Confirmed no regressions to existing dashboard modules.

Future Improvements

  • Replace mock data with live sensor streams.
  • Add anomaly history tracking.
  • Add predictive forecasting for emissions.
  • Add automated compliance escalation workflows.

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.
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.

1 participant