3.0.3.0
Added lightning, change values to amp/pm
This commit is contained in:
+45
-6
@@ -54,6 +54,8 @@ export function buildHourlyRows({ forecast, airQuality, location, vehicleType, v
|
||||
const uv = h.uv_index ? (h.uv_index[i] || 0) : 0;
|
||||
const precip = h.precipitation[i] || 0;
|
||||
const precipProb = h.precipitation_probability ? (h.precipitation_probability[i] ?? 0) : 0;
|
||||
const lightning = h.lightning_potential ? (h.lightning_potential[i] ?? 0) : 0;
|
||||
const cape = h.cape ? (h.cape[i] ?? 0) : 0;
|
||||
const snow = h.snowfall[i] || 0;
|
||||
const soilT0 = h.soil_temperature_0cm ? h.soil_temperature_0cm[i] : null;
|
||||
const soilT6 = h.soil_temperature_6cm ? h.soil_temperature_6cm[i] : null;
|
||||
@@ -144,7 +146,7 @@ export function buildHourlyRows({ forecast, airQuality, location, vehicleType, v
|
||||
iso, dt, Ta, RH, dew, va, wd, gust, dir, dif, glob,
|
||||
cc, ccLow, ccMid, ccHigh, cloudCat,
|
||||
uv, uvA, uvB,
|
||||
precip, precipProb, snow,
|
||||
precip, precipProb, lightning, cape, snow,
|
||||
soilT0, soilT6, soilM, vehicleT,
|
||||
effectiveRad,
|
||||
elev, Tmrt, utci, utciAdj, eh, compass,
|
||||
@@ -379,7 +381,22 @@ export function computeGlanceSummary(todayRows, profile, variant, skinType, cols
|
||||
if (!todayRows || todayRows.length === 0) return [];
|
||||
const show = (key) => !cols || !!cols[key];
|
||||
|
||||
const hhmm = (iso) => iso ? iso.slice(11, 16) : null;
|
||||
const hhmm = (iso) => {
|
||||
if (!iso) return null;
|
||||
const h = parseInt(iso.slice(11, 13), 10);
|
||||
const m = iso.slice(14, 16);
|
||||
const period = h < 12 ? 'am' : 'pm';
|
||||
const h12 = h % 12 || 12;
|
||||
return m === '00' ? `${h12}${period}` : `${h12}:${m}${period}`;
|
||||
};
|
||||
const hhmmEnd = (iso) => {
|
||||
if (!iso) return null;
|
||||
const h = parseInt(iso.slice(11, 13), 10) + 1;
|
||||
const m = iso.slice(14, 16);
|
||||
const period = (h % 24) < 12 ? 'am' : 'pm';
|
||||
const h12 = h % 12 || 12;
|
||||
return m === '00' ? `${h12}${period}` : `${h12}:${m}${period}`;
|
||||
};
|
||||
const dayRows = todayRows.filter(r => r.elev > 0);
|
||||
|
||||
const peakRow = (field) => todayRows.reduce((best, r) =>
|
||||
@@ -419,6 +436,23 @@ export function computeGlanceSummary(todayRows, profile, variant, skinType, cols
|
||||
return 'Poor';
|
||||
};
|
||||
|
||||
const lightningLabel = (v) => {
|
||||
if (v <= 0) return null;
|
||||
if (v < 5) return 'Low';
|
||||
if (v < 25) return 'Moderate';
|
||||
return 'High';
|
||||
};
|
||||
const peakLightningRow = todayRows.reduce((best, r) =>
|
||||
(r.lightning ?? 0) > (best?.lightning ?? 0) ? r : best, null);
|
||||
const peakLightning = peakLightningRow?.lightning ?? 0;
|
||||
const lightningRisk = lightningLabel(peakLightning);
|
||||
const lightningItem = lightningRisk ? [{
|
||||
icon: '⚡',
|
||||
label: 'Lightning risk',
|
||||
value: `${lightningRisk} at ${hhmm(peakLightningRow.iso)}`,
|
||||
alert: peakLightning >= 5,
|
||||
}] : [];
|
||||
|
||||
const moistureLabel = (v) => {
|
||||
if (v == null) return null;
|
||||
if (v < 0.15) return 'Dry';
|
||||
@@ -450,7 +484,7 @@ export function computeGlanceSummary(todayRows, profile, variant, skinType, cols
|
||||
icon: '⏱',
|
||||
label: 'Best field work',
|
||||
value: fieldWindow
|
||||
? `${hhmm(fieldWindow.start.iso)} – ${hhmm(fieldWindow.end.iso)}`
|
||||
? `${hhmm(fieldWindow.start.iso)} – ${hhmmEnd(fieldWindow.end.iso)}`
|
||||
: 'No suitable window',
|
||||
alert: !fieldWindow,
|
||||
},
|
||||
@@ -461,6 +495,7 @@ export function computeGlanceSummary(todayRows, profile, variant, skinType, cols
|
||||
alert: !soilWarmRow,
|
||||
}] : []),
|
||||
...(show('precipProb') ? [rainItem] : []),
|
||||
...lightningItem,
|
||||
...(show('soilM') ? [{
|
||||
icon: '💧',
|
||||
label: 'Soil moisture',
|
||||
@@ -494,6 +529,7 @@ export function computeGlanceSummary(todayRows, profile, variant, skinType, cols
|
||||
alert: !!dangerFrom,
|
||||
}] : []),
|
||||
...(show('precipProb') ? [rainItem] : []),
|
||||
...lightningItem,
|
||||
{
|
||||
icon: '🌤',
|
||||
label: 'Best travel comfort',
|
||||
@@ -534,10 +570,11 @@ export function computeGlanceSummary(todayRows, profile, variant, skinType, cols
|
||||
icon: '🪟',
|
||||
label: 'Open windows',
|
||||
value: ventWindow
|
||||
? `${hhmm(ventWindow.start.iso)} – ${hhmm(ventWindow.end.iso)}`
|
||||
? `${hhmm(ventWindow.start.iso)} – ${hhmmEnd(ventWindow.end.iso)}`
|
||||
: 'Keep closed',
|
||||
alert: false,
|
||||
}] : []),
|
||||
...lightningItem,
|
||||
...(show('aqi') ? [{
|
||||
icon: '💨',
|
||||
label: 'Air quality',
|
||||
@@ -570,11 +607,12 @@ export function computeGlanceSummary(todayRows, profile, variant, skinType, cols
|
||||
icon: '⏱',
|
||||
label: `Best ${variant} window`,
|
||||
value: coolWindow
|
||||
? `${hhmm(coolWindow.start.iso)} – ${hhmm(coolWindow.end.iso)}`
|
||||
? `${hhmm(coolWindow.start.iso)} – ${hhmmEnd(coolWindow.end.iso)}`
|
||||
: 'No cool window today',
|
||||
alert: !coolWindow,
|
||||
},
|
||||
...(show('precipProb') ? [rainItem] : []),
|
||||
...lightningItem,
|
||||
...(show('burn') && burnMins ? [{
|
||||
icon: '☀',
|
||||
label: 'UV burn time (peak)',
|
||||
@@ -613,7 +651,7 @@ export function computeGlanceSummary(todayRows, profile, variant, skinType, cols
|
||||
icon: '🌤',
|
||||
label: 'Comfortable window',
|
||||
value: comfortWindow
|
||||
? `${hhmm(comfortWindow.start.iso)} – ${hhmm(comfortWindow.end.iso)}`
|
||||
? `${hhmm(comfortWindow.start.iso)} – ${hhmmEnd(comfortWindow.end.iso)}`
|
||||
: 'No comfortable window',
|
||||
alert: !comfortWindow,
|
||||
},
|
||||
@@ -630,6 +668,7 @@ export function computeGlanceSummary(todayRows, profile, variant, skinType, cols
|
||||
alert: !!(peakUvRow && peakUvRow.uv >= 6),
|
||||
}] : []),
|
||||
...(show('precipProb') ? [rainItem] : []),
|
||||
...lightningItem,
|
||||
...(show('aqi') ? [{
|
||||
icon: '💨',
|
||||
label: 'Air quality',
|
||||
|
||||
Reference in New Issue
Block a user