feat(frontend): settings page, Greek translation, comparison and chart options
The end user is Greek and the owner wants to confirm at a glance that every inverter is working without one cloud-shaded reading raising doubt. - Settings page (gear in the header), stored on the server and shared by every viewer; saving asks for the API key once per device. - Output comparison: latest reading or average of the last 3/5 (evens out a passing cloud); bar scale auto (round ceiling above the best) / highest = 100% / custom kW; percentage vs fleet median, best inverter or the custom kW. - Power chart: 30 min to last month plus "last production run", a per-visit range picker on the card, optional light/strong smoothing. Series reporting slower than the chart bucket (INV5, every 5 min) are now interpolated across short gaps — on 1-min buckets their line used to vanish entirely; night gaps still break the line. - Greek/English: per-device switch in the header, shared default in settings, Greek number/date formats; issue texts translated from code + params. - AC voltage shown as phase (L-N) or line (L-L, x√3, matching the inverter screens); lifetime total says how many inverters it covers; the inverter's own status text appears on its card. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
||||
} from 'recharts'
|
||||
import { useThemeColors } from '../lib/colors'
|
||||
import { dateTimeLabel, dayLabel, timeLabel } from '../lib/format'
|
||||
import { useT } from '../lib/i18n'
|
||||
|
||||
export function Legend({ series }) {
|
||||
if (series.length < 2) return null
|
||||
@@ -28,6 +29,7 @@ export function Legend({ series }) {
|
||||
}
|
||||
|
||||
function TooltipBox({ title, rows, total }) {
|
||||
const { t } = useT()
|
||||
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>
|
||||
@@ -46,7 +48,7 @@ function TooltipBox({ title, rows, total }) {
|
||||
))}
|
||||
{total && (
|
||||
<tr className="border-t border-line">
|
||||
<td className="pt-1 pr-3 text-ink-2">Total</td>
|
||||
<td className="pt-1 pr-3 text-ink-2">{t('chart.total')}</td>
|
||||
<td className="tnum pt-1 text-right font-semibold text-ink">{total}</td>
|
||||
</tr>
|
||||
)}
|
||||
@@ -58,26 +60,83 @@ function TooltipBox({ title, rows, total }) {
|
||||
|
||||
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])
|
||||
// Silences up to this long are drawn through; longer ones (night, outage)
|
||||
// break the line. Covers a unit reporting every ~5 min plus a missed cycle.
|
||||
const BRIDGE_SECONDS = 900
|
||||
const SMOOTHING_RADIUS = { off: 0, light: 1, strong: 3 }
|
||||
|
||||
/**
|
||||
* Chart rows from API points: a gap row where the whole fleet went silent,
|
||||
* values interpolated where one series reports less often than the bucket
|
||||
* (INV5 every ~5 min on a 1-min chart would otherwise have no line at all),
|
||||
* then an optional centred moving average. Interpolated values are flagged
|
||||
* `<key>__est` so the tooltip can mark them.
|
||||
*/
|
||||
function prepare(points, keys, bucket, smoothing) {
|
||||
const maxGap = Math.max(BRIDGE_SECONDS, (bucket || 0) * 2.5)
|
||||
const rows = []
|
||||
points.forEach((p, i) => {
|
||||
if (i && p.t - points[i - 1].t > maxGap) rows.push({ t: points[i - 1].t + (bucket || 1) })
|
||||
rows.push({ ...p })
|
||||
})
|
||||
for (const key of keys) {
|
||||
let prev = -1
|
||||
rows.forEach((r, i) => {
|
||||
if (r[key] == null) return
|
||||
if (prev >= 0 && i - prev > 1 && r.t - rows[prev].t <= maxGap) {
|
||||
const a = rows[prev]
|
||||
for (let j = prev + 1; j < i; j++) {
|
||||
rows[j][key] = a[key] + ((r[key] - a[key]) * (rows[j].t - a.t)) / (r.t - a.t)
|
||||
rows[j][`${key}__est`] = true
|
||||
}
|
||||
}
|
||||
prev = i
|
||||
})
|
||||
}
|
||||
return out
|
||||
const radius = SMOOTHING_RADIUS[smoothing] ?? 0
|
||||
if (radius) {
|
||||
for (const key of keys) {
|
||||
const raw = rows.map((r) => r[key])
|
||||
rows.forEach((r, i) => {
|
||||
if (raw[i] == null) return
|
||||
// Only neighbours on the same unbroken stretch of line
|
||||
let sum = raw[i]
|
||||
let n = 1
|
||||
for (let j = i - 1; j >= i - radius && j >= 0 && raw[j] != null; j--) {
|
||||
sum += raw[j]
|
||||
n++
|
||||
}
|
||||
for (let j = i + 1; j <= i + radius && j < raw.length && raw[j] != null; j++) {
|
||||
sum += raw[j]
|
||||
n++
|
||||
}
|
||||
r[key] = sum / n
|
||||
})
|
||||
}
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 }) {
|
||||
export function TimeLines({
|
||||
points,
|
||||
series,
|
||||
from,
|
||||
to,
|
||||
bucket,
|
||||
format,
|
||||
axisFormat,
|
||||
height = 240,
|
||||
showTotal = false,
|
||||
smoothing = 'off',
|
||||
}) {
|
||||
const c = useThemeColors()
|
||||
const span = to - from
|
||||
const data = useMemo(() => withGaps(points, bucket), [points, bucket])
|
||||
const keys = series.map((s) => s.key).join(',')
|
||||
const data = useMemo(() => prepare(points, keys.split(','), bucket, smoothing), [points, keys, bucket, smoothing])
|
||||
return (
|
||||
<div style={{ height }}>
|
||||
<ResponsiveContainer width="100%" height="100%">
|
||||
@@ -105,9 +164,10 @@ export function TimeLines({ points, series, from, to, bucket, format, axisFormat
|
||||
cursor={{ stroke: c.axis, strokeWidth: 1 }}
|
||||
content={({ active, payload, label }) => {
|
||||
if (!active || !payload?.length) return null
|
||||
const row = payload[0].payload
|
||||
const rows = series
|
||||
.filter((s) => payload[0].payload[s.key] != null)
|
||||
.map((s) => ({ ...s, value: format(payload[0].payload[s.key]) }))
|
||||
.filter((s) => row[s.key] != null)
|
||||
.map((s) => ({ ...s, value: (row[`${s.key}__est`] ? '≈ ' : '') + format(row[s.key]) }))
|
||||
const total = showTotal
|
||||
? format(series.reduce((sum, s) => sum + (payload[0].payload[s.key] ?? 0), 0))
|
||||
: null
|
||||
@@ -121,6 +181,7 @@ export function TimeLines({ points, series, from, to, bucket, format, axisFormat
|
||||
name={s.name}
|
||||
stroke={s.color}
|
||||
strokeWidth={2}
|
||||
type={smoothing === 'off' ? 'linear' : 'monotone'}
|
||||
dot={false}
|
||||
activeDot={{ r: 4, stroke: c.surface, strokeWidth: 2 }}
|
||||
connectNulls={false}
|
||||
@@ -191,10 +252,11 @@ export function DayBars({ days, series, format, axisFormat, height = 220 }) {
|
||||
}
|
||||
|
||||
export function EnergyFootnote({ estimated }) {
|
||||
const { t } = useT()
|
||||
return (
|
||||
<div className="mt-1 flex justify-between gap-3 text-[11px] text-muted">
|
||||
<span>{estimated && '≈ Estimated from AC power readings until the energy counters are decoded'}</span>
|
||||
<span className="shrink-0">axis in kWh</span>
|
||||
<span>{estimated && t('energy.footEstimated')}</span>
|
||||
<span className="shrink-0">{t('energy.axis')}</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user