improve rain charts

This commit is contained in:
2026-02-06 16:24:38 +11:00
parent c68c063ff1
commit 51f351d6ae
2 changed files with 14 additions and 6 deletions

View File

@@ -23,6 +23,8 @@ const colors = {
rainStart: "#f77f00", rainStart: "#f77f00",
}; };
const RAIN_HOURLY_THRESHOLD_MM = 0.1;
function formatNumber(value, digits) { function formatNumber(value, digits) {
if (value === null || value === undefined) { if (value === null || value === undefined) {
return "--"; return "--";
@@ -101,7 +103,6 @@ function computeRainIncrements(points) {
if (prev !== null) { if (prev !== null) {
delta = p.rain_mm - prev; delta = p.rain_mm - prev;
if (delta < 0) delta = 0; if (delta < 0) delta = 0;
if (delta < 0.1) delta = 0;
} }
prev = p.rain_mm; prev = p.rain_mm;
out.push({ x: t, y: delta }); out.push({ x: t, y: delta });
@@ -119,7 +120,7 @@ function computeHourlySums(points, tz) {
} }
return Array.from(buckets.entries()) return Array.from(buckets.entries())
.sort((a, b) => a[0] - b[0]) .sort((a, b) => a[0] - b[0])
.map(([x, y]) => ({ x, y: y < 0.1 ? 0 : y })); .map(([x, y]) => ({ x, y: y < RAIN_HOURLY_THRESHOLD_MM ? 0 : y }));
} }
function clampRainSeries(points, key) { function clampRainSeries(points, key) {
@@ -372,6 +373,13 @@ function updateText(id, text) {
if (el) el.textContent = text; if (el) el.textContent = text;
} }
function observationBucketSummary() {
if (state.range === "6h") {
return "obs bucket 1m (6h view)";
}
return "obs bucket 5m (TimescaleDB-aligned)";
}
function describeBarometer(pressure, trend) { function describeBarometer(pressure, trend) {
if (pressure === null || pressure === undefined) { if (pressure === null || pressure === undefined) {
return "No barometer data yet."; return "No barometer data yet.";
@@ -649,7 +657,7 @@ function renderDashboard(data) {
const forecastMeta = data.forecast && data.forecast.points && data.forecast.points.length const forecastMeta = data.forecast && data.forecast.points && data.forecast.points.length
? `forecast retrieved ${formatDateTime(data.forecast.retrieved_at)}` ? `forecast retrieved ${formatDateTime(data.forecast.retrieved_at)}`
: "forecast not available"; : "forecast not available";
updateText("forecast-meta", forecastMeta); updateText("forecast-meta", `${forecastMeta} | ${observationBucketSummary()}`);
if (latest) { if (latest) {
updateText("live-temp", `${formatNumber(latest.temp_c, 2)} C`); updateText("live-temp", `${formatNumber(latest.temp_c, 2)} C`);
@@ -852,7 +860,7 @@ function renderDashboard(data) {
updateText("live-rain-hour", latestRainHour == null ? "--" : `${formatNumber(latestRainHour, 2)} mm`); updateText("live-rain-hour", latestRainHour == null ? "--" : `${formatNumber(latestRainHour, 2)} mm`);
const rainTitle = document.getElementById("chart-rain-title"); const rainTitle = document.getElementById("chart-rain-title");
if (rainTitle) { if (rainTitle) {
rainTitle.textContent = "Rain (obs hourly sum vs forecast)"; rainTitle.textContent = `Rain (obs hourly sum from ${state.bucket} buckets vs forecast)`;
} }
const forecastRain = clampRainSeries(forecastLine, "precip_mm"); const forecastRain = clampRainSeries(forecastLine, "precip_mm");
@@ -861,7 +869,7 @@ function renderDashboard(data) {
datasets: [ datasets: [
{ {
type: "line", type: "line",
label: "obs hourly sum (mm)", label: `obs hourly sum (mm, ${state.bucket} buckets)`,
data: rainHourly, data: rainHourly,
borderColor: colors.rain, borderColor: colors.rain,
yAxisID: "y", yAxisID: "y",

View File

@@ -74,7 +74,7 @@ func (d *DB) ObservationSeries(ctx context.Context, site, bucket string, start,
max(light_lux) AS light_lux_max, max(light_lux) AS light_lux_max,
avg(battery_mv) AS battery_mv_avg, avg(battery_mv) AS battery_mv_avg,
avg(supercap_v) AS supercap_v_avg, avg(supercap_v) AS supercap_v_avg,
avg(rain_mm) AS rain_mm_avg, max(rain_mm) AS rain_mm_avg,
max(rain_start) AS rain_start_max max(rain_start) AS rain_start_max
FROM observations_ws90 FROM observations_ws90
WHERE site = $1 WHERE site = $1