3.2.3.1
Fix average to top temps
This commit is contained in:
+24
-16
@@ -491,31 +491,39 @@ export function computeGlanceSummary(todayRows, profile, variant, skinType, cols
|
||||
alert: maxRainProb >= 60,
|
||||
};
|
||||
|
||||
// ── Vs seasonal average (climate anomaly) ──────────────────────────────
|
||||
// Shown across every profile: how far this day's mean air temp sits above or
|
||||
// below the 1991-2020 normal for the date. A small, honest climate-change cue.
|
||||
// ── Vs seasonal norms (climate anomalies) ──────────────────────────────
|
||||
// Shown across every profile: two rows comparing this day against the
|
||||
// 1991-2020 norm for the date — the day's HIGH vs the normal high, and the
|
||||
// day's 24h AVERAGE vs the normal mean. High tracks the daytime peak people
|
||||
// notice; the average is the standard climate anomaly. An honest climate cue.
|
||||
const climateItem = (() => {
|
||||
if (!normals) return [];
|
||||
const key = dayKey || todayRows[0]?.iso?.slice(0, 10);
|
||||
if (!key) return [];
|
||||
const LEAP_CUM = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335];
|
||||
const doy = LEAP_CUM[parseInt(key.slice(5, 7), 10) - 1] + (parseInt(key.slice(8, 10), 10) - 1);
|
||||
const normal = normals[doy];
|
||||
if (normal == null) return [];
|
||||
const taVals = todayRows.map(r => r.Ta).filter(v => v != null);
|
||||
if (taVals.length === 0) return [];
|
||||
const dayHigh = Math.max(...taVals);
|
||||
const dayMean = taVals.reduce((a, b) => a + b, 0) / taVals.length;
|
||||
const anomaly = dayMean - normal;
|
||||
const mag = Math.abs(anomaly);
|
||||
const value = mag < 0.5
|
||||
? 'About average'
|
||||
: `${anomaly >= 0 ? '+' : '−'}${mag.toFixed(1)}° ${anomaly >= 0 ? 'warmer' : 'cooler'}`;
|
||||
return [{
|
||||
icon: '🌡',
|
||||
label: '1991-2020 Average',
|
||||
value,
|
||||
alert: anomaly >= 5,
|
||||
}];
|
||||
const fmt = (anom) => {
|
||||
const mag = Math.abs(anom);
|
||||
return mag < 0.5
|
||||
? 'About average'
|
||||
: `${anom >= 0 ? '+' : '−'}${mag.toFixed(1)}° ${anom >= 0 ? 'warmer' : 'cooler'}`;
|
||||
};
|
||||
const out = [];
|
||||
const nHigh = normals.high?.[doy];
|
||||
if (nHigh != null) {
|
||||
const a = dayHigh - nHigh;
|
||||
out.push({ icon: '🌡', label: '1991-2020 High', value: fmt(a), alert: a >= 5 });
|
||||
}
|
||||
const nMean = normals.mean?.[doy];
|
||||
if (nMean != null) {
|
||||
const a = dayMean - nMean;
|
||||
out.push({ icon: '🌡', label: '1991-2020 Average', value: fmt(a), alert: a >= 5 });
|
||||
}
|
||||
return out;
|
||||
})();
|
||||
|
||||
// ── Good Driving Time ──────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user