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:
2026-10-22 18:15:38 +03:00
co-authored by Claude Opus 5.5
parent c24770af1c
commit 0b74842560
16 changed files with 1302 additions and 201 deletions
+46 -12
View File
@@ -1,5 +1,21 @@
const nf = (digits) =>
new Intl.NumberFormat(undefined, { minimumFractionDigits: digits, maximumFractionDigits: digits })
// Set by the language provider so numbers and dates follow the chosen language
let lang = 'en'
const LOCALES = { en: 'en-GB', el: 'el-GR' }
export function setFormatLanguage(l) {
lang = LOCALES[l] ? l : 'en'
}
const locale = () => LOCALES[lang]
const nfCache = new Map()
const nf = (digits) => {
const key = `${lang}:${digits}`
if (!nfCache.has(key)) {
nfCache.set(key, new Intl.NumberFormat(locale(), { minimumFractionDigits: digits, maximumFractionDigits: digits }))
}
return nfCache.get(key)
}
export function num(v, digits = 0) {
return v === null || v === undefined || Number.isNaN(v) ? '—' : nf(digits).format(v)
@@ -33,13 +49,31 @@ export function energy(wh) {
return `${v} ${u}`
}
const UNITS = {
en: { s: 's', min: 'min', h: 'h', d: 'd', days: 'days', ago: (x) => `${x} ago`, never: 'never' },
el: { s: 'δευτ.', min: 'λεπ.', h: 'ώρ.', d: 'ημ.', days: 'ημ.', ago: (x) => `πριν ${x}`, never: 'ποτέ' },
}
export function ago(iso) {
if (!iso) return 'never'
const u = UNITS[lang]
if (!iso) return u.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`
if (s < 60) return u.ago(`${s} ${u.s}`)
if (s < 3600) return u.ago(`${Math.floor(s / 60)} ${u.min}`)
if (s < 86400) return u.ago(`${Math.floor(s / 3600)} ${u.h}`)
return u.ago(`${Math.floor(s / 86400)} ${u.d}`)
}
/** Length of a silence: 12 min, 3.5 h, 2.0 days. */
export function duration(seconds) {
const u = UNITS[lang]
if (seconds < 3600) return `${Math.floor(seconds / 60)} ${u.min}`
if (seconds < 86400) return `${num(seconds / 3600, 1)} ${u.h}`
return `${num(seconds / 86400, 1)} ${u.days}`
}
export function dateTime(iso) {
return new Date(iso).toLocaleString(locale())
}
export function pct(ratio) {
@@ -48,12 +82,12 @@ export function pct(ratio) {
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' })
if (spanSeconds <= 2 * 86400) return d.toLocaleTimeString(locale(), { hour: '2-digit', minute: '2-digit' })
return d.toLocaleDateString(locale(), { weekday: 'short', day: 'numeric' })
}
export function dateTimeLabel(unix) {
return new Date(unix * 1000).toLocaleString([], {
return new Date(unix * 1000).toLocaleString(locale(), {
weekday: 'short',
day: 'numeric',
month: 'short',
@@ -65,6 +99,6 @@ export function dateTimeLabel(unix) {
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' })
? d.toLocaleDateString(locale(), { weekday: 'short', day: 'numeric', month: 'short', year: 'numeric' })
: d.toLocaleDateString(locale(), { day: 'numeric', month: 'short' })
}