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:
@@ -0,0 +1,191 @@
|
||||
import { useMemo } from 'react'
|
||||
import {
|
||||
Bar,
|
||||
BarChart,
|
||||
CartesianGrid,
|
||||
Line,
|
||||
LineChart,
|
||||
ResponsiveContainer,
|
||||
Tooltip,
|
||||
XAxis,
|
||||
YAxis,
|
||||
} from 'recharts'
|
||||
import { useThemeColors } from '../lib/colors'
|
||||
import { dateTimeLabel, dayLabel, timeLabel } from '../lib/format'
|
||||
|
||||
export function Legend({ series }) {
|
||||
if (series.length < 2) return null
|
||||
return (
|
||||
<ul className="flex flex-wrap gap-x-4 gap-y-1 text-xs text-ink-2">
|
||||
{series.map((s) => (
|
||||
<li key={s.key} className="inline-flex items-center gap-1.5">
|
||||
<span className="h-0.5 w-3 rounded-full" style={{ background: s.color, height: 3 }} />
|
||||
{s.name}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)
|
||||
}
|
||||
|
||||
function TooltipBox({ title, rows, total }) {
|
||||
return (
|
||||
<div className="card min-w-40 px-3 py-2 text-xs shadow-lg">
|
||||
<div className="mb-1 font-medium text-ink-2">{title}</div>
|
||||
<table className="w-full">
|
||||
<tbody>
|
||||
{rows.map((r) => (
|
||||
<tr key={r.key}>
|
||||
<td className="py-0.5 pr-3">
|
||||
<span className="inline-flex items-center gap-1.5 text-ink-2">
|
||||
<span className="inline-block h-2 w-2 rounded-full" style={{ background: r.color }} />
|
||||
{r.name}
|
||||
</span>
|
||||
</td>
|
||||
<td className="tnum py-0.5 text-right font-medium text-ink">{r.value}</td>
|
||||
</tr>
|
||||
))}
|
||||
{total && (
|
||||
<tr className="border-t border-line">
|
||||
<td className="pt-1 pr-3 text-ink-2">Total</td>
|
||||
<td className="tnum pt-1 text-right font-semibold text-ink">{total}</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const axisTick = (c) => ({ fill: c.muted, fontSize: 11 })
|
||||
|
||||
/** Insert an empty point wherever readings stop for more than a couple of
|
||||
* buckets (night, outage), so the line breaks instead of bridging the gap. */
|
||||
function withGaps(points, bucket) {
|
||||
if (!bucket || points.length < 2) return points
|
||||
const out = [points[0]]
|
||||
for (let i = 1; i < points.length; i++) {
|
||||
if (points[i].t - points[i - 1].t > bucket * 2.5) out.push({ t: points[i - 1].t + bucket })
|
||||
out.push(points[i])
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/**
|
||||
* Lines over time. points: [{t: unix seconds, [series.key]: number}]
|
||||
* series: [{key, name, color}]. Gaps (night, outages) stay gaps.
|
||||
*/
|
||||
export function TimeLines({ points, series, from, to, bucket, format, axisFormat, height = 240, showTotal = false }) {
|
||||
const c = useThemeColors()
|
||||
const span = to - from
|
||||
const data = useMemo(() => withGaps(points, bucket), [points, bucket])
|
||||
return (
|
||||
<div style={{ height }}>
|
||||
<ResponsiveContainer width="100%" height="100%">
|
||||
<LineChart data={data} margin={{ top: 8, right: 8, bottom: 0, left: 0 }}>
|
||||
<CartesianGrid stroke={c.grid} vertical={false} />
|
||||
<XAxis
|
||||
dataKey="t"
|
||||
type="number"
|
||||
domain={[from, to]}
|
||||
scale="time"
|
||||
tickFormatter={(t) => timeLabel(t, span)}
|
||||
tick={axisTick(c)}
|
||||
stroke={c.axis}
|
||||
tickLine={false}
|
||||
minTickGap={28}
|
||||
/>
|
||||
<YAxis
|
||||
tickFormatter={axisFormat ?? format}
|
||||
tick={axisTick(c)}
|
||||
axisLine={false}
|
||||
tickLine={false}
|
||||
width={48}
|
||||
/>
|
||||
<Tooltip
|
||||
cursor={{ stroke: c.axis, strokeWidth: 1 }}
|
||||
content={({ active, payload, label }) => {
|
||||
if (!active || !payload?.length) return null
|
||||
const rows = series
|
||||
.filter((s) => payload[0].payload[s.key] != null)
|
||||
.map((s) => ({ ...s, value: format(payload[0].payload[s.key]) }))
|
||||
const total = showTotal
|
||||
? format(series.reduce((sum, s) => sum + (payload[0].payload[s.key] ?? 0), 0))
|
||||
: null
|
||||
return <TooltipBox title={dateTimeLabel(label)} rows={rows} total={total} />
|
||||
}}
|
||||
/>
|
||||
{series.map((s) => (
|
||||
<Line
|
||||
key={s.key}
|
||||
dataKey={s.key}
|
||||
name={s.name}
|
||||
stroke={s.color}
|
||||
strokeWidth={2}
|
||||
dot={false}
|
||||
activeDot={{ r: 4, stroke: c.surface, strokeWidth: 2 }}
|
||||
connectNulls={false}
|
||||
isAnimationActive={false}
|
||||
/>
|
||||
))}
|
||||
</LineChart>
|
||||
</ResponsiveContainer>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Bars per day. days: [{day: 'YYYY-MM-DD', [series.key]: number}].
|
||||
* Several series are stacked (the stack height is the day's total).
|
||||
*/
|
||||
export function DayBars({ days, series, format, axisFormat, height = 220 }) {
|
||||
const c = useThemeColors()
|
||||
const last = series.length - 1
|
||||
return (
|
||||
<div style={{ height }}>
|
||||
<ResponsiveContainer width="100%" height="100%">
|
||||
<BarChart data={days} margin={{ top: 8, right: 8, bottom: 0, left: 0 }} barCategoryGap="18%">
|
||||
<CartesianGrid stroke={c.grid} vertical={false} />
|
||||
<XAxis
|
||||
dataKey="day"
|
||||
tickFormatter={(d) => dayLabel(d)}
|
||||
tick={axisTick(c)}
|
||||
stroke={c.axis}
|
||||
tickLine={false}
|
||||
minTickGap={24}
|
||||
/>
|
||||
<YAxis
|
||||
tickFormatter={axisFormat ?? format}
|
||||
tick={axisTick(c)}
|
||||
axisLine={false}
|
||||
tickLine={false}
|
||||
width={48}
|
||||
/>
|
||||
<Tooltip
|
||||
cursor={{ fill: c.grid, opacity: 0.5 }}
|
||||
content={({ active, payload, label }) => {
|
||||
if (!active || !payload?.length) return null
|
||||
const row = payload[0].payload
|
||||
const rows = series.map((s) => ({ ...s, value: format(row[s.key]) }))
|
||||
const total =
|
||||
series.length > 1 ? format(series.reduce((sum, s) => sum + (row[s.key] ?? 0), 0)) : null
|
||||
return <TooltipBox title={dayLabel(label, true)} rows={rows} total={total} />
|
||||
}}
|
||||
/>
|
||||
{series.map((s, i) => (
|
||||
<Bar
|
||||
key={s.key}
|
||||
dataKey={s.key}
|
||||
name={s.name}
|
||||
stackId="day"
|
||||
fill={s.color}
|
||||
stroke={series.length > 1 ? c.surface : undefined}
|
||||
strokeWidth={series.length > 1 ? 1 : 0}
|
||||
radius={i === last ? [3, 3, 0, 0] : 0}
|
||||
isAnimationActive={false}
|
||||
/>
|
||||
))}
|
||||
</BarChart>
|
||||
</ResponsiveContainer>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user