Skip to content

coolss21/envision_grid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌍 EnvisionGrid β€” City-Scale Environmental Risk Intelligence Platform

Predict, Alert, and Simulate environmental risks across urban zones using data-driven intelligence

CI Python 3.9+ FastAPI Streamlit License: MIT


πŸ“Œ Overview

EnvisionGrid is a full-stack environmental monitoring platform that ingests violation reports, complaints, and optional IoT sensor data to generate real-time risk predictions for city grid zones. It features explainable risk scoring, automated alert generation, case management, hotspot detection, and policy simulation β€” all accessible through a REST API and an interactive Streamlit dashboard.

Design Philosophy: Sensor-Agnostic, Sensor-Enhanced. Core intelligence derives from violations + complaints data; IoT sensors boost prediction confidence but are never required.


πŸ—οΈ System Architecture

graph TD
    subgraph Data Ingestion
        A1[CSV/JSON Upload] --> ING[Ingestion Engine]
        A2[Arduino Edge Node] -.->|Optional| ING
    end

    subgraph Processing Pipeline
        ING --> DB[(SQLite Storage)]
        ING --> FE[Feature Engineering<br/>Rolling Windows]
        FE --> MODEL[Risk Model<br/>Deterministic Rules + Sigmoid]
    end

    subgraph Output Layer
        MODEL --> ALERTS[Alert Generation]
        MODEL --> EXPLAIN[Explainability Engine]
        ALERTS --> CASES[Case Management]
        MODEL --> HOT[Hotspot Detection]
        MODEL --> COV[Coverage Analysis]
    end

    subgraph Simulation
        SIM[Policy What-If Engine]
    end

    subgraph Interfaces
        API[FastAPI REST API]
        DASH[Streamlit Dashboard<br/>6 Interactive Tabs]
    end

    ALERTS --> API
    EXPLAIN --> API
    CASES --> API
    HOT --> API
    COV --> API
    SIM --> API
    API --> DASH
Loading

✨ Key Features

Feature Description
πŸ“Š Risk Prediction Multi-type environmental risk scoring per grid zone
🚨 Smart Alerts Auto-generated alerts when risk thresholds are breached
πŸ“‹ Case Management Create and track investigation cases from alerts
πŸ—ΊοΈ Hotspot Detection Identify the highest-risk zones across the city
πŸ”¬ Explainability Human-readable explanations of risk drivers
πŸ§ͺ Policy Simulation What-if analysis for intervention planning
πŸ“‘ IoT Integration Optional Arduino edge nodes for sensor data
πŸ“ˆ Coverage Analysis Identify data gaps across the monitoring grid

πŸš€ Quick Start

# 1. Clone the repository
git clone https://github.com/coolss21/envision_grid.git
cd envision_grid

# 2. Install dependencies
pip install -r requirements.txt

# 3. Generate demo data
python sample_data/generate_demo_data.py

# 4. Start backend (Terminal 1)
uvicorn src.api:app --reload

# 5. Start dashboard (Terminal 2)
streamlit run frontend/app.py

# 6. (Optional) Run full automated demo
python scripts/demo_end_to_end.py

πŸ“‚ Project Structure

envision_grid/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ api.py              # FastAPI endpoints (16 routes)
β”‚   β”œβ”€β”€ config.py           # Tunable parameters & thresholds
β”‚   β”œβ”€β”€ db.py               # SQLite schema + helpers
β”‚   β”œβ”€β”€ schemas.py          # Pydantic request/response models
β”‚   β”œβ”€β”€ geo_grid.py         # Lat/lon β†’ grid cell mapping
β”‚   β”œβ”€β”€ ingest.py           # CSV/JSON data ingestion
β”‚   β”œβ”€β”€ features.py         # Rolling-window feature engineering
β”‚   β”œβ”€β”€ model_adapter.py    # Risk model with clean ML interface
β”‚   β”œβ”€β”€ explain.py          # Human-readable risk explanations
β”‚   β”œβ”€β”€ actions.py          # Recommended intervention actions
β”‚   β”œβ”€β”€ alerts.py           # Alert generation & management
β”‚   β”œβ”€β”€ cases.py            # Investigation case tracking
β”‚   β”œβ”€β”€ hotspots.py         # Top risk zone detection
β”‚   β”œβ”€β”€ coverage.py         # Data coverage gap analysis
β”‚   └── simulate.py         # Policy what-if simulation
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ app.py              # Streamlit dashboard (6 tabs)
β”‚   └── ui_components.py    # Reusable UI widgets
β”œβ”€β”€ edge_node/
β”‚   β”œβ”€β”€ serial_to_api_bridge.py   # Arduino β†’ API bridge
β”‚   β”œβ”€β”€ arduino_stub.ino          # Reference firmware
β”‚   β”œβ”€β”€ sensor_payload_example.json
β”‚   β”œβ”€β”€ wiring_diagram.md
β”‚   └── README_EDGE_NODE.md
β”œβ”€β”€ sample_data/
β”‚   β”œβ”€β”€ generate_demo_data.py     # Synthetic data generator
β”‚   └── scenario_timeline.json    # Early-signal demo scenario
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ demo_end_to_end.py        # Full automated demo
β”‚   β”œβ”€β”€ reset_db.py               # Database reset utility
β”‚   β”œβ”€β”€ run_backend.bat
β”‚   └── run_frontend.bat
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ ML_BLUEPRINT.md           # ML logic specification
β”‚   └── API_SCHEMA.md             # Full API reference
β”œβ”€β”€ .github/workflows/ci.yml     # Automated CI pipeline
β”œβ”€β”€ requirements.txt
└── README.md

πŸ”Œ API Reference

Method Endpoint Description
GET /health Health check
GET /grid/preview Preview grid mapping for coordinates
POST /ingest/violation-event Ingest single violation event
POST /ingest/violations Batch upload violations CSV
POST /ingest/complaints Batch upload complaints CSV
POST /ingest/sensor Ingest single sensor reading
POST /ingest/sensors Batch upload sensor CSV
POST /predict Run risk prediction pipeline
GET /predictions Retrieve stored predictions
GET /alerts List generated alerts
POST /cases Create case from alert
GET /cases List investigation cases
PATCH /cases/{id} Update case status
GET /hotspots Get top risk zones
GET /coverage Data coverage report
POST /simulate Run policy what-if simulation
πŸ“‹ Example curl Commands
# Health check
curl http://localhost:8000/health

# Ingest a violation event
curl -X POST http://localhost:8000/ingest/violation-event \
  -H "Content-Type: application/json" \
  -d '{"violation_id":"V001","timestamp":"2024-03-15T10:00:00","lat":40.72,"lon":-74.01,"violation_type":"industrial_emission","severity":4,"source":"Facility_13"}'

# Upload violations CSV
curl -X POST http://localhost:8000/ingest/violations -F "file=@sample_data/demo_violations.csv"

# Run prediction
curl -X POST http://localhost:8000/predict \
  -H "Content-Type: application/json" \
  -d '{"risk_type":"all","horizon_hours":72,"threshold":0.5,"use_sensors":true}'

# What-if simulation
curl -X POST http://localhost:8000/simulate \
  -H "Content-Type: application/json" \
  -d '{"risk_type":"all","horizon_hours":72,"adjustments":[{"grid_id":"40.71_-74.01","violation_type":"industrial_emission","factor":0.3}]}'

# Get hotspots & coverage
curl http://localhost:8000/hotspots
curl http://localhost:8000/coverage

🧩 Design Decisions

Decision Choice Rationale
Primary Signal Violations + Complaints Available immediately; no hardware required
Sensor Role Confidence Booster Validates predictions; doesn't replace core data
Model Deterministic Placeholder Stable & reproducible; clean interface for future ML
Storage SQLite Zero setup; single-file database
Geo-Binning 2-decimal lat/lon ~1.1km grid cells; city-scale granularity

πŸ“‘ IoT Edge Node (Optional)

The edge_node/ directory contains everything needed to connect an Arduino-based sensor station:

  • arduino_stub.ino β€” Reference firmware for temperature, humidity, and air quality sensors
  • serial_to_api_bridge.py β€” Python bridge that reads serial data and POSTs to the API
  • wiring_diagram.md β€” Hardware wiring reference

See edge_node/README_EDGE_NODE.md for full setup instructions.


πŸ“„ License

MIT β€” Built for the InnovateYou Hackathon.


Making cities smarter, one grid cell at a time.

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors