A full-stack web application that detects and tracks traffic accidents in real-time using sequential estimation techniques (ARMA/ARIMA, CUSUM, SPRT, Page-Hinkley). Built with Python Flask backend and interactive JavaScript frontend.
- Overview
- Features
- Technology Stack
- Installation
- Usage
- System Architecture
- Algorithms
- Screenshots
- API Documentation
- Future Enhancements
- Resume Bullet Points
| Dashboard View | Accident Detected |
|---|---|
![]() |
![]() |
| Real-time Monitoring | Instant Alert System |
| Simulation Running | Accident Cleared |
|---|---|
![]() |
![]() |
| Live Data Streaming | Automatic Clearance |
This project transforms traditional traffic accident detection from a batch processing problem into a real-time monitoring system. It demonstrates:
- Full-stack development with Python backend and JavaScript frontend
- Real-time data streaming using WebSocket technology
- Statistical algorithm implementation (ARMA/ARIMA, CUSUM, SPRT, Page-Hinkley)
- Interactive data visualization with Chart.js and Leaflet.js
- Production-ready architecture with proper separation of concerns
Traditional traffic monitoring systems rely on manual reports or delayed camera analysis. This system provides:
- Automated detection of accidents from GPS speed data
- Sub-second latency from incident to alert
- Robust performance under noisy observations
- Real-time tracking of accident persistence and clearance
- β Real-time accident detection using multiple statistical tests
- β Live traffic speed monitoring with ARIMA prediction
- β Interactive map visualization showing accident locations
- β Accident persistence tracking with evolving speed profiles
- β Automatic clearance detection when traffic normalizes
- β WebSocket-based streaming for real-time updates (2-second intervals)
- β Voting mechanism requiring 2/3 statistical tests to agree
- β Noise filtering to handle GPS inaccuracy
- β Configurable parameters for detection sensitivity
- β Demo mode with realistic traffic simulation
- β Modern dark theme with glassmorphism effects
- β Responsive design for desktop and mobile
- β Real-time charts with smooth animations
- β Toast notifications for accident alerts
- β Manual controls for demonstration (inject/clear accidents)
- Python 3.8+ - Core language
- Flask 3.0 - Web framework
- Flask-SocketIO - WebSocket support
- NumPy & SciPy - Numerical computing
- statsmodels - ARIMA time-series modeling
- Pandas - Data manipulation
- HTML5 & CSS3 - Structure and styling
- Vanilla JavaScript - No framework dependencies
- Chart.js - Real-time speed charts
- Leaflet.js - Interactive maps
- Socket.IO Client - WebSocket communication
- Git - Version control
- Eventlet - Async server
- Python 3.8 or higher
- pip (Python package manager)
- Git
git clone https://github.com/paramparekh/AccidentDetectionSystem.git
cd AccidentDetectionSystem# Windows
python -m venv venv
venv\Scripts\activate
# macOS/Linux
python3 -m venv venv
source venv/bin/activatepip install -r requirements.txtpython app.pyNavigate to: http://localhost:5000
-
Launch the application
python app.py
-
Open dashboard in your browser at
http://localhost:5000 -
Click "Start Monitoring" to begin real-time traffic simulation
- System automatically injects accidents at random intervals
- Watch the detection algorithms identify speed drops
- Observe clearance detection when traffic normalizes
- Inject Accident: Manually trigger an accident scenario (120-second duration)
- Clear Accident: Immediately clear the current accident
- Stop Monitoring: Pause the simulation
-
Speed Chart:
- Blue line = Actual speed
- Purple dashed = ARIMA prediction
- Orange = CUSUM statistic
-
Map:
- Green marker = Normal traffic
- Red marker = Accident detected
-
Alerts Panel:
- Shows detection methods (CUSUM, SPRT, Page-Hinkley)
- Displays confidence level
- Updates status when cleared
-
Statistics:
- Real-time speed values
- Detection algorithm outputs
- Active accident count
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Frontend (Browser) β
β ββββββββββββ ββββββββββββ ββββββββββββ β
β β Map β β Chart β β Alerts β β
β ββββββββββββ ββββββββββββ ββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β WebSocket
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Flask Backend (Python) β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Data Stream Worker (Thread) β β
β β ββββββββββββββ ββββββββββββββ ββββββββββββββ β β
β β β Simulator ββ β Detector ββ β Emitter β β β
β β ββββββββββββββ ββββββββββββββ ββββββββββββββ β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Sequential Estimation Models β β
β β β’ ARIMA Predictor β β
β β β’ CUSUM Detector β β
β β β’ SPRT Detector β β
β β β’ Page-Hinkley Detector β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- Simulator generates GPS speed data every 2 seconds
- Detector processes data through all statistical tests
- Voting mechanism combines results (requires 2/3 agreement)
- WebSocket emits updates to all connected clients
- Frontend updates charts, map, and statistics in real-time
Purpose: Predict next speed value based on historical data
Implementation:
- Order: (1, 0, 1) - AR(1) with MA(1)
- Uses last 60 speed readings
- Provides baseline for anomaly detection
Code: models/sequential_estimators.py:ARIMAPredictor
Purpose: Detect sustained decrease in speed
How it works:
- Accumulates deviations from predicted speed
- Triggers alert when cumulative sum exceeds threshold
- Resets to zero when no negative deviations
Parameters:
- Threshold: 10.0
- Drift: 2.0
Code: models/sequential_estimators.py:CUSUMDetector
Purpose: Test hypothesis H0 (normal) vs H1 (accident)
How it works:
- Calculates likelihood ratio for each observation
- Compares speed to normal distribution (ΞΌ=60, Ο=10)
- Compares speed to accident distribution (ΞΌ=15, Ο=5)
- Makes decision when ratio crosses threshold
Parameters:
- Upper threshold: 5.0 (accident)
- Lower threshold: 0.2 (normal)
Code: models/sequential_estimators.py:SPRTDetector
Purpose: Detect changes in mean speed
How it works:
- Monitors cumulative difference from baseline
- Detects both decreases (accidents) and increases (clearance)
- Adaptive to changing traffic conditions
Parameters:
- Threshold: 8.0
- Delta: 2.0
Code: models/sequential_estimators.py:PageHinkleyDetector
Robust Detection:
- Requires 2 out of 3 tests to agree
- Reduces false positives
- Confidence score = (votes / 3)
Get current system status
Response:
{
"simulation_running": true,
"active_accidents": [...],
"detector_status": {...},
"config": {...}
}Get accident history (last 20)
Response:
{
"history": [...]
}Manually inject accident
Request:
{
"duration": 120
}Manually clear accident
start_simulation- Start monitoringstop_simulation- Stop monitoringupdate_config- Update parameters
traffic_update- Real-time data (every 2s)accident_alert- New accident detectedaccident_cleared- Accident resolvedsimulation_status- Status change



