feat: solar inverter monitor — FastAPI + SQLite backend, React PWA dashboard

Monitoring for the Refusol 020K inverters. The on-site poller POSTs each
60 s cycle to /api/readings; the dashboard answers first whether every
inverter is operating and whether one is producing far less than its peers
(string fuse / breaker problems).

- Backend: FastAPI + SQLite. Parameters defined once in fields.py (columns
  auto-added on start); unknown poller keys are kept in `extra` since the
  parameter map is still being researched. Idempotent ingest, daily energy
  rollup in site-local days, history downsampling, 2-year retention.
- Health: Offline vs Sleeping (sun elevation) vs No data (datalogger
  silent, detected via empty-batch heartbeats), Fault from error_code,
  underperformance vs fleet median (per kWp when sizes set), MPPT imbalance.
- Frontend: mobile-first React + Tailwind, installable PWA, comparison bars,
  24 h power / 30 day energy charts, detail page with all parameters.
- Docker: backend + frontend + nginx on one port for NPM, as in
  bellsystems-cp; deploy-host.sh pulls main and rebuilds.
- poller/backend_client.py: stdlib client with offline spool for
  refusol_poller.py; fake_poller.py simulates the site.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-21 07:42:48 +03:00
co-authored by Claude Opus 5.5
commit d4b584e364
59 changed files with 10849 additions and 0 deletions
+70
View File
@@ -0,0 +1,70 @@
const nf = (digits) =>
new Intl.NumberFormat(undefined, { minimumFractionDigits: digits, maximumFractionDigits: digits })
export function num(v, digits = 0) {
return v === null || v === undefined || Number.isNaN(v) ? '—' : nf(digits).format(v)
}
/** Power with an auto unit: 950 W, 12.4 kW, 1.20 MW. Returns [value, unit]. */
export function powerParts(w) {
if (w === null || w === undefined) return ['—', 'W']
const a = Math.abs(w)
if (a >= 1e6) return [num(w / 1e6, 2), 'MW']
if (a >= 1000) return [num(w / 1000, a >= 1e5 ? 0 : 1), 'kW']
return [num(w, 0), 'W']
}
export function power(w) {
const [v, u] = powerParts(w)
return `${v} ${u}`
}
/** Energy with an auto unit: 850 Wh, 42.3 kWh, 123.4 MWh. Returns [value, unit]. */
export function energyParts(wh) {
if (wh === null || wh === undefined) return ['—', 'kWh']
const a = Math.abs(wh)
if (a >= 1e6) return [num(wh / 1e6, a >= 1e8 ? 0 : 1), 'MWh']
if (a >= 1000) return [num(wh / 1000, a >= 1e5 ? 0 : 1), 'kWh']
return [num(wh, 0), 'Wh']
}
export function energy(wh) {
const [v, u] = energyParts(wh)
return `${v} ${u}`
}
export function ago(iso) {
if (!iso) return 'never'
const s = Math.max(0, Math.round((Date.now() - new Date(iso).getTime()) / 1000))
if (s < 60) return `${s} s ago`
if (s < 3600) return `${Math.floor(s / 60)} min ago`
if (s < 86400) return `${Math.floor(s / 3600)} h ago`
return `${Math.floor(s / 86400)} d ago`
}
export function pct(ratio) {
return ratio === null || ratio === undefined ? '—' : `${Math.round(ratio * 100)}%`
}
export function timeLabel(unix, spanSeconds) {
const d = new Date(unix * 1000)
if (spanSeconds <= 2 * 86400) return d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
return d.toLocaleDateString([], { weekday: 'short', day: 'numeric' })
}
export function dateTimeLabel(unix) {
return new Date(unix * 1000).toLocaleString([], {
weekday: 'short',
day: 'numeric',
month: 'short',
hour: '2-digit',
minute: '2-digit',
})
}
export function dayLabel(isoDay, long = false) {
const d = new Date(`${isoDay}T12:00:00`)
return long
? d.toLocaleDateString([], { weekday: 'short', day: 'numeric', month: 'short', year: 'numeric' })
: d.toLocaleDateString([], { day: 'numeric', month: 'short' })
}