Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

EV Battery Forensics

An AI agent prototype for in-depth forensic diagnosis of electric vehicle traction batteries. Built for the hackathon track Challenge #2 — "Dr. House is live!".

The system aims to identify hidden root causes behind obvious but misleading symptoms by correlating heterogeneous, noisy data, testing competing hypotheses, and explaining its findings through physical evidence and operating history.

Quick start

Install Docker with Docker Compose and start the Docker daemon. Run the following command in a terminal from the project root:

docker compose -f compose.yaml -f compose.dev.yaml up --build -d --wait

On the first run, the one-shot data-setup service downloads the pinned data-v1 release (approximately 128 MB), verifies its SHA-256 checksum, and installs the prepared datasets into data/. The backend starts only after setup succeeds. Later runs reuse the installed version. Caddy and Python run inside Docker; no local installation or manual directory creation is required.

Once the services are running, open the frontend or the API documentation.

Diagnostic scenario

The subject is a liquid-cooled NMC lithium-ion battery consisting of multiple modules and cells.

Symptoms: reduced driving range, emergency power limitation (Turtle Mode), voltage sag, and a BMS error pointing to a specific cell, such as cell #14 in module #3.

Obvious but incorrect hypothesis: cell #14 has degraded or failed, requiring an expensive battery repair.

Hidden root cause defined for the demo scenario: the cell is physically healthy. A sticking solenoid valve impairs cooling in module #3, while the driver regularly uses DC fast charging immediately after a prolonged uphill drive. Local overheating triggers BMS protection measures that mimic cell failure in the scenario, including current and balancing restrictions.

This is the intended synthetic scenario, not an established finding from the real datasets. The agent must infer the root cause from evidence; the known scenario ground truth must not appear in its inputs. The specific valve failure and BMS behavior must be supported by available measurements or explicitly identified synthetic channels. When evidence is insufficient, the conclusion must remain a hypothesis.

Data

We use four public datasets, prepared as Parquet for analysis with pandas and DuckDB. Columns, caveats and rebuild commands are in docs/DATA.md; sources, licenses and citations are in docs/SOURCES.md.

Dataset Role in the project
Battery and Heating Data in Real Driving Cycles — BMW i3, 70 trips (TU Munich) Healthy baseline: voltage, current, battery temperature, speed, GPS altitude, ambient temperature, and thermal management signals. Used to calibrate battery heating. Synthetic anomalies and sensor noise will be injected into the final trips.
LG 18650HG2 Li-ion Battery Data — McMaster University Laboratory cycles of an NMC cell at −20 to +40 °C, used to calibrate how resistance and voltage depend on temperature and current.
NASA PCoE Battery Data Set Measured capacity fade and resistance growth during cell aging, used only as relative degradation for the "genuinely degraded cell" scenario.
Vehicle Energy Dataset (VED) — 27 EV/PHEV, 4,107 trips Additional real driving load profiles.

Channel availability and measurement units must be verified during data preparation. LG laboratory characteristics require validation of their applicability and scaling before being used for the BMW battery.

Large datasets are stored locally in the root-level data/ directory; processing outputs go into artifacts/. Both directories are excluded from Git. The backend/data/ package contains data handling code, not the datasets themselves.

Architecture

Raw CSV files, Parquet files, and time series are not passed directly to the LLM. LLM weights are not fine-tuned on numerical measurements.

BMW i3 + LG → Parquet / DuckDB → Analytics core
                                      ↕ Compact JSON evidence / tool calls
                                  LLM agent
                                      ↓
                                API → Frontend

1. Analytics and ML core

Planned stack: Python, Pandas/DuckDB, Scikit-learn/LightGBM.

  • Builds a healthy baseline model using BMW and LG data.
  • Computes physical features: internal resistance R_int, heating rate dT/dt, and associations between anomalies, elevation gain, and charging power.
  • Compares anomalous episodes against operating history and the healthy baseline.
  • Returns compact JSON digests with sources, time intervals, measurement units, and confidence limitations.

2. "Dr. House" AI agent

Planned approach: an LLM with tool calling, orchestrated through LangGraph.

  • Calls get_trip_anomalies, check_cell_health, correlate_external_factors, compare_with_history.
  • Tests at least three hypotheses: the obvious cell failure, a systemic cooling failure, and external operating conditions.
  • Searches for both supporting and contradicting evidence.
  • Refutes incorrect hypotheses using physics and trip history.
  • Produces a step-by-step verdict linked to evidence and identifies missing data.

3. User interface

The planned interface displays symptoms, hypotheses, the investigation timeline, timestamps, and charts supporting the final conclusion.

Currently, Caddy serves a static HTML/JavaScript page that checks API connectivity through /api/health. A frontend framework has not been selected yet; Node.js is not required for the current page. The backend uses FastAPI + Uvicorn.

Current status

  • Analytics, data, and agent directories are ready for further implementation.
  • Only the infrastructure endpoint GET /health → {"status": "ok"} is implemented.
  • A landing page checks API availability.
  • Two long-running services, backend and frontend, are configured with health checks and a separate development mode that mounts local source files.
  • A one-shot data-setup service installs the pinned dataset release before the backend starts. It exits successfully after installing or checking the data.
  • Dataset download and preparation are implemented in backend/data/ (see docs/DATA.md).
  • Diagnostic logic, models, and the LLM agent are not implemented yet. The /health response confirms API availability, not diagnostic readiness.

Project structure

backend/                   # Backend Python packages
├── __init__.py
├── Dockerfile             # Python 3.14, dependencies from uv.lock
├── api/main.py            # FastAPI: /health, /docs, /openapi.json
├── data/                  # Release downloader, manifest, and dataset preparation
├── analytics/             # Physical metrics, baseline models, JSON digests
└── agent/                 # LLM agent, tools, hypotheses, verdict
docs/
├── DATA.md                # Datasets, columns, caveats, rebuild commands
└── SOURCES.md             # Data sources, licenses, citations
frontend/
├── Dockerfile             # Caddy with static files
├── Caddyfile              # Static file serving and /api/ proxy to backend
├── src/main.js            # API availability check
└── public/index.html      # Landing page
compose.yaml               # Standard run with source code baked into images
compose.dev.yaml           # Development override with local source mounts
.dockerignore              # Build context exclusions
.env.example               # Example local configuration
.python-version            # Python 3.14
pyproject.toml             # Python project configuration and dependencies
uv.lock                    # Locked dependency versions

Running the project with Docker

Requires Docker Engine / Docker Desktop and Docker Compose v2.24.0+ (or a newer major version). The Docker daemon must be running. Local installations of Python, uv, and Node.js are not required for this mode.

Compose creates the local data/ and artifacts/ directories automatically. The data-setup service has write access to data/; the backend has read-only access. The setup image uses only Python's standard library and does not install the analytics dependencies.

If needed, copy .env.example to .env and change the host ports. The .env file is optional; the default ports are 8000 and 3000.

Standard run with source code baked into the images:

docker compose up --build -d --wait

Once the services are running:

URL Purpose
http://localhost:3000 Landing page with an API availability check
http://localhost:3000/api/health Frontend → Caddy → backend connectivity check
http://localhost:8000/health Direct API health check
http://localhost:8000/docs Backend Swagger UI

Use docker compose logs -f data-setup to follow the first download. An Exited (0) status for data-setup is expected: it is a completed preparation step, not a continuously running server. If download or validation fails, setup exits with an error and Compose does not start the backend.

These URLs use the default ports. Services are exposed only on the host's loopback interface. Containers communicate through backend:8000, independently of the host-side BACKEND_PORT. The browser requests the relative URL /api/health; Caddy uses handle_path to strip the /api prefix and forward the request to the backend. CORS is not required for this setup.

For local development, Caddy listens for HTTP on port 80 inside the container. HTTPS and a domain name are not required. The /healthz endpoint checks Caddy availability; /api/health also checks backend availability through the proxy.

DuckDB will run as a library inside the backend. There are currently no separate database, queue, or LLM containers. An LLM API key is not required to start the project.

Development mode

docker compose -f compose.yaml -f compose.dev.yaml up --build -d --wait
  • Changes in backend/ automatically restart Uvicorn.
  • HTML and JavaScript changes appear after refreshing the browser page.
  • After changing frontend/Caddyfile, restart the frontend: docker compose -f compose.yaml -f compose.dev.yaml restart frontend.
  • After changing dependencies, update uv.lock using uv add ... and rerun the startup command with --build.

compose.dev.yaml extends the main file and is not intended to run on its own. The local .venv is not mounted into the container: the container has its own environment built from uv.lock, without dependencies from the dev group.

Data and configuration

Local path Path inside the backend container Access
data/ /app/data Read-only
artifacts/ /app/artifacts Read/write

backend/data/release.json pins the release version, asset URL, archive SHA-256, and expected file sizes. The downloader strips the archive's top-level data/ directory, so files are installed into data/processed/, not data/data/processed/. The archive and extraction staging files are removed after setup.

data/.release.json records the completed installation. On later runs, setup checks this marker and the expected file sizes without network requests. Missing or truncated files trigger a new download. Files are not fully rehashed on every startup; use --force to restore a release after local modifications:

docker compose run --rm data-setup python download_release.py --force

Stop the backend before replacing data it is actively using. To publish a new dataset version, update the URL, version, checksum, and file sizes in the tracked manifest, then rebuild and run Compose. The release is pinned, not selected via latest. Existing unrelated files under data/ are preserved.

Outputs remain on the host after containers are removed. Future data processing code will use the DATA_DIR and ARTIFACTS_DIR environment variables, already defined in Compose. Place prepared Parquet files in data/ and generated files, including writable DuckDB databases, in artifacts/.

The local .env file supplies environment variables to the backend. Secrets, datasets, artifacts, and the local Python environment are excluded from the Docker build context.

Managing containers

For standard mode:

docker compose ps
docker compose logs -f data-setup
docker compose logs -f backend frontend
docker compose down

For development mode, use the same commands with both files, for example:

docker compose -f compose.yaml -f compose.dev.yaml logs -f backend frontend
docker compose -f compose.yaml -f compose.dev.yaml down

Local Python development and PyCharm

Requires Python 3.14 and uv. From the project root:

uv sync

This command creates .venv and installs dependencies from uv.lock, including development tools. Current dependencies include FastAPI, Uvicorn with standard extras for development, the data processing libraries, Ruff, and pytest. Agent libraries will be added during implementation.

To install the same pinned dataset without Docker, run from the project root:

uv run python -m backend.data.download_release

The downloader respects DATA_DIR and also accepts --data-dir, --manifest, and --force. A public GitHub release is used, so no GitHub CLI or token is needed.

In PyCharm, select the existing interpreter at .venv/bin/python: Settings → Python Interpreter → Add Interpreter → Add Local Interpreter.

To start the API from a terminal:

uv run uvicorn backend.api.main:app --reload --host 127.0.0.1 --port 8000

To debug in PyCharm, create a Python run configuration using the uvicorn module, the arguments backend.api.main:app --host 127.0.0.1 --port 8000, and the repository root as the working directory. The --reload flag is not needed for debugging. Before starting the local API, stop the containerized backend if it occupies the same port. For future local data processing, set DATA_DIR=./data and ARTIFACTS_DIR=./artifacts.

The containerized frontend is configured to reach the containerized backend. When running the backend separately in PyCharm, access it directly through /health and /docs.

Check the environment and code style:

uv run python --version
uv run ruff check .
uv run ruff format --check .

Run the dataset downloader tests with uv run pytest. They use small ZIP fixtures and a local HTTP server; they do not download the real dataset.

Use English for all project documentation, comments, docstrings, and user-facing text.

Hackathon evaluation criteria

Criterion Weight How the project should address it
Root cause accuracy 35% Reconstruct the causal chain from measurements and operating history
Overcoming cognitive bias 25% Test alternatives and refute the obvious hypothesis with evidence
Explainability 20% Provide a step-by-step evidence chain, timestamps, and charts
Technical implementation 20% Deliver a working prototype with separate analytics and LLM investigation layers

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages