# energodata

Local tooling to fetch, store, and visualize data from the LookDet energy
aggregator (`agregator.e-management.cz`), without depending on the web UI.

## Components

| File | Purpose |
|------|---------|
| `fetch_emanagement.bat` → `process.ps1` | Poll `getData`, write `emdata.js` / history, ingest to DB |
| `db_schema.sql`, `db_build.py`, `db_ingest.py` | SQLite history store (`points` / `readings` / `snapshots`) |
| `db_backfill_gvals.py` | Pull deep per-channel history from the server into the DB |
| `serve.py` + `realtime.bat` | Local proxy that serves the pages and forwards API calls with your session |
| `realtime.html` | Live self-polling synoptic clone — KPIs, click-to-chart, Grafy panel, total-power footer |
| `prehled.html` | Static offline clone of the "Přehled EZ" screen |
| `dashboard.html` | Tile view with sparklines/trends |
| `labels.js`, `baseline.js`, `menu.json` | Channel names/units/multipliers, frozen fallback values, tab list |

## Setup (not in git — you provide these)

Authentication is **not committed**. Create one of:

- **`login.txt`** (auto-login, recommended) — two lines:
  ```
  <username>
  <password>
  ```
  `serve.py` logs in on start (fresh session) and re-logs-in automatically on expiry.

- **`session.txt`** — a single line with a valid `PHPSESSID` cookie (manual fallback).

## Run

- **Live view:** double-click `realtime.bat` → opens `http://localhost:8765/realtime.html`.
- **One-off fetch + DB store:** run `fetch_emanagement.bat`.
- **Backfill history:** `python db_backfill_gvals.py 24` (hours).

The SQLite DB and generated snapshots are gitignored; they rebuild from the scripts.
