fix wind calculation/display

This commit is contained in:
Matt Fiddaman
2025-04-14 16:31:09 -04:00
parent d9f29e9d62
commit 53b7d9d888
2 changed files with 6 additions and 10 deletions

View File

@@ -53,7 +53,7 @@ const LimitsMatrix = ({ metar }) => {
}, },
{ {
label: 'Crosswind', label: 'Crosswind',
value: `${metar.crosswind}kts (R${metar.runway})`, value: `${metar.crosswind ?? 0}kts ${metar.runway ? `(R${metar.runway})` : ''}`,
pattern: withinLimits('pattern', 'crosswind', metar.crosswind), pattern: withinLimits('pattern', 'crosswind', metar.crosswind),
dual: withinLimits('dual', 'crosswind', metar.crosswind), dual: withinLimits('dual', 'crosswind', metar.crosswind),
solo: withinLimits('solo', 'crosswind', metar.crosswind), solo: withinLimits('solo', 'crosswind', metar.crosswind),

View File

@@ -24,20 +24,15 @@ export function decodeMetar(metar) {
const baseWind = parseInt(windMatch[2], 10); const baseWind = parseInt(windMatch[2], 10);
const gust = windMatch[4] ? parseInt(windMatch[4], 10) : null; const gust = windMatch[4] ? parseInt(windMatch[4], 10) : null;
result.direction = result.direction = dir === 'VRB' ? 'variable' : parseInt(dir, 10);
dir === 'VRB'
? 'variable'
: dir === '000' && baseWind === 0
? 'calm'
: parseInt(dir, 10);
result.gusts = gust; result.gusts = gust;
const effectiveWind = gust ? Math.max(baseWind, gust) : baseWind; const effectiveWind = gust ? Math.max(baseWind, gust) : baseWind;
result.wind = effectiveWind; result.wind = effectiveWind;
// Runway calculations // Runway calculations
if (typeof result.direction === 'number') { if (true) {
const windDir = result.direction; const windDir = result.direction || 0;
result.runwayBreakdown = runways.map(({ id, heading }) => { result.runwayBreakdown = runways.map(({ id, heading }) => {
const angleDiff = Math.abs(windDir - heading); const angleDiff = Math.abs(windDir - heading);
@@ -60,8 +55,9 @@ export function decodeMetar(metar) {
a.headwind > b.headwind ? a : b, a.headwind > b.headwind ? a : b,
); );
result.runway = best.runway; result.runway = dir === '000' && baseWind === 0 ? null : best.runway;
result.crosswind = Math.abs(best.crosswind); result.crosswind = Math.abs(best.crosswind);
} else {
} }
} }