Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Node
node_modules/
dist/
.vite/

# Python
__pycache__/
*.py[cod]
*.pyo
*.egg-info/
*.egg
.eggs/
*.whl
.venv/
venv/
env/

# Byte-compiled / optimized
*.so

# Jupyter
.ipynb_checkpoints/

# IDE
.vscode/
.idea/
*.swp
*.swo
*~
.DS_Store
Thumbs.db

# Environment
.env
.env.local
.env.*.local

# Logs
*.log
npm-debug.log*

# macOS
__MACOSX/

# Model artifacts (large binaries)
*.pkl

# Misc
*.bak
*.tmp
32 changes: 32 additions & 0 deletions Dockerfile.backend
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM python:3.11-slim

WORKDIR /app

# Copy dependency manifests
COPY requirements.txt .
COPY backend/requirements.txt backend/requirements.txt
COPY earnings/earnings/requirements.txt earnings/earnings/requirements.txt
COPY drivepulse_stress_model/requirements.txt drivepulse_stress_model/requirements.txt

# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt \
&& pip install --no-cache-dir -r backend/requirements.txt \
&& pip install --no-cache-dir -r earnings/earnings/requirements.txt \
&& pip install --no-cache-dir -r drivepulse_stress_model/requirements.txt

# Copy source code
COPY backend/ backend/
COPY earnings/ earnings/
COPY drivepulse_stress_model/ drivepulse_stress_model/

ENV PYTHONUNBUFFERED=1

EXPOSE 8000

# Match local dev layout: run from /app/backend so imports like `from utils...`
# and `from data...` resolve the same as `cd backend && python main.py`
WORKDIR /app/backend

CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]


22 changes: 22 additions & 0 deletions Dockerfile.frontend
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM node:20-alpine AS build

WORKDIR /app

COPY frontend/package*.json ./
RUN npm ci

COPY frontend/ .
RUN npm run build

FROM nginx:1.27-alpine

WORKDIR /usr/share/nginx/html

COPY --from=build /app/dist ./

COPY nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]

1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: uvicorn backend.main:app --host 0.0.0.0 --port ${PORT:-8000}
159 changes: 159 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# 🚗 DrivePulse

Real-time driver wellness & earnings intelligence platform for ride-hailing drivers. Uses on-device sensor data (accelerometer, gyroscope, microphone) with ML models to detect stressful driving situations and forecast earnings velocity.

---

## Features

- **Dashboard** — Daily trips, earnings, stress score, timeline
- **Trip Detail** — Map playback, sensor charts, event detection with explainability
- **Trends** — Weekly/monthly earnings, stress, and velocity charts
- **Goals** — Set and track daily earnings targets
- **Predict** — Enter sensor/earnings values → instant ML prediction *(judge-facing)*
- **Batch Upload** — Upload CSV → run inference on multiple trips at once *(judge-facing)*
- **Explainability** — Per-event feature contributions, confidence badges
- **Feedback** — Thumbs up/down on detected events
- **Auth** — Login / register with demo accounts or new profile

To log **multiple trips at once**, go to the `Trips` tab and use **Import CSV**.

---

## Architecture

```
Driver-Pulse/
├── backend/ # FastAPI REST API (25 endpoints)
│ ├── main.py # Routes, middleware, Pydantic models
│ ├── data/
│ │ ├── sample_data.py # Synthetic trip/route/event generator
│ │ ├── batch_processor.py # Loads ML models, runs batch inference
│ │ ├── trips_import.py # CSV trip import parser
│ │ ├── users.py # In-memory auth store
│ │ └── config.py # Batch limits & constants
│ └── utils/
│ └── logging.py # Timestamped structured logging
├── frontend/ # React 18 + Vite + Tailwind SPA
│ └── src/
│ ├── pages/ # 8 pages: Home, Dashboard, Trips, TripDetail,
│ │ # Trends, Goals, Predict, BatchUpload
│ ├── components/ # 16 reusable components
│ ├── api/client.js # Centralised API client
│ └── utils/sanityChecks.js # Input validation helpers
├── drivepulse_stress_model/ # Stress Detection ML pipeline
│ ├── run.py # CLI entry (--generate --calibrate --train --demo)
│ ├── src/
│ │ ├── generate_data.py # Synthetic sensor window generator (3,150 samples)
│ │ ├── train.py # RF classifier training + evaluation
│ │ ├── inference.py # InferenceEngine with rule-based fallback
│ │ └── hal.py # Hardware Abstraction Layer (device calibration)
│ ├── model/ # Trained artifacts (rf_model.pkl, baselines, contract)
│ └── calibration/ # Device calibration profile
├── earnings/earnings/ # Earnings Forecasting ML pipeline
│ ├── run.py # Sequential pipeline entry
│ ├── src/
│ │ ├── build_dataset.py # Merges drivers + goals + velocity + trips
│ │ ├── features.py # 14-feature engineering (lags, rolling avg, rush flags)
│ │ ├── augment.py # 5× Gaussian noise augmentation
│ │ ├── train.py # RF regressor training + evaluation
│ │ └── inference.py # Batch velocity prediction
│ ├── model/ # Trained artifacts (rf_model.pkl, contract)
│ └── data/ # Source CSVs (drivers, goals, velocity, trips)
├── streamlit_app.py # Standalone Streamlit demo (3 tabs)
├── tests/data/ # Example CSVs for batch & import testing
└── requirements.txt # Root Python dependencies
```

```mermaid
flowchart LR
browser[Browser_ReactApp] --> api[FastAPI_Backend]
api --> tripsStore[InMemory_Trips_+_Goals]
api --> stressBatch[Stress_Batch_Processor]
api --> earningsBatch[Earnings_Batch_Processor]
stressBatch --> stressModel[Stress_Model_Files]
earningsBatch --> earningsModel[Earnings_Model_Files]
```

---

## Setup

### Prerequisites
- Python 3.9+
- Node.js 18+
- Docker Desktop (for judge-friendly containerisation)

### Install & Run (local dev)

```bash
# Install Python dependencies
pip install -r requirements.txt

# Start backend (http://localhost:8000)
cd backend && python main.py

# In a new terminal — start frontend (http://localhost:5173)
cd frontend && npm install && npm run dev
```

Open **http://localhost:5173** in your browser.

---

### Run with Docker

With [Docker Desktop](https://www.docker.com/products/docker-desktop/) running:

```bash
# From the repo root (Driver-Pulse/)
docker compose up --build
```

Then open:

- Frontend: `http://localhost:5173`
- Backend (direct): `http://localhost:8000/api/health`

The frontend talks to the backend via `/api/*`, which is proxied by Nginx inside the `frontend` container to the `backend` container.

**Judge login (demo account):**

- Username: `judge@uber.com`
- Password: `hackathon2026`

---

## Tech Stack

| Layer | Tech |
|-------|------|
| Frontend | React 18, Vite, Tailwind CSS, Recharts, Leaflet |
| Backend | FastAPI, Uvicorn |
| ML | scikit-learn, NumPy, Pandas |

---

## Data Flow

- **Trips & goals**: Manual entry or CSV import hit `/api/trips` or `/api/trips/import-csv`, which update an in-memory trips list. Goals (`/api/goals`) and dashboard (`/api/dashboard`) recompute current earnings, hours, and forecast from those trips.
- **Batch stress & earnings**: Batch CSV uploads are processed by backend helpers that engineer features, call local models, and return per-row predictions plus summaries as JSON.

---

## Scalability & Modularity

- **Backend**: FastAPI routes in `backend/main.py` delegate to small modules in `backend/data/` for trips, goals, imports, and batch processing, so swapping the in-memory store for a database or separate ML service is a local change.
- **Frontend**: The React app uses a single API client layer (`frontend/src/api/client.js`) plus page/component separation, making it easy to plug in global state, auth, or feature flags without rewriting screens.
- **Batch endpoints**: Batch CSV processing is stateless per request, so multiple backend instances can handle uploads in parallel behind a load balancer.

---

## Testing & Validation Notes

- **Frontend sanity checks** — lightweight helpers in `frontend/src/utils/sanityChecks.js` validate money inputs, time ranges, and clamp goal targets.
- **Example test files** — illustrative, non-wired tests live in `frontend/src/__tests__/` (e.g. `EarningsProgress.test.jsx`, `TripsAddTrip.test.jsx`) to show how key components and behaviours could be validated in a full test setup.
Empty file added backend/data/__init__.py
Empty file.
Loading