From 41f9430d37ea65906d0d770fee648eba867e2078 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sat, 14 Feb 2026 16:45:57 -0700 Subject: [PATCH] fix: Correct CYVR typo, improve visibility parsing, and handle unknown components Co-authored-by: aider (gemini/gemini-2.5-pro) --- metar.html | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/metar.html b/metar.html index 2839ef0..0db4e3e 100644 --- a/metar.html +++ b/metar.html @@ -64,7 +64,7 @@ if (code === 'CYYC') return "CYYC: Calgary International Airport"; if (code === 'CYEG') return "CYEG: Edmonton International Airport"; if (code === 'CYXS') return "CYXS: Prince George Airport"; - if (code === 'CYVR') return "CVYR: Vancouver International Airport"; + if (code === 'CYVR') return "CYVR: Vancouver International Airport"; if (code === 'CYBW') return "CYBW: Calgary/Springbank Airport"; console.log(`Unknown Airport code: ${code} in METAR: ${metarString}`); return `${code}: Unknown Airport`; @@ -559,10 +559,18 @@ const mainParts = rmkIndex !== -1 ? parts.slice(index, rmkIndex) : parts.slice(index); // Intermediate sections - mainParts.forEach(part => { + for (let i = 0; i < mainParts.length; i++) { + let part = mainParts[i]; + + // Check for mixed fraction visibility, e.g., "1 1/2SM" which is split into "1" and "1/2SM" + if (part.match(/^\d+$/) && (i + 1) < mainParts.length && mainParts[i+1].match(/^\d\/\dSM$/)) { + part = `${part} ${mainParts[i+1]}`; + i++; // Consume next part + } + if (part.endsWith('KT')) { sections.push({ raw: part, decoded: decodeWind(part) }); - } else if (part.endsWith('SM') || part.match(/^\d+$/) || part.match(/^\d\/\dSM$/)) { + } else if (part.endsWith('SM') || part.match(/^\d+$/)) { sections.push({ raw: part, decoded: decodeVisibility(part) }); } else if (part.match(/^([+-]|VC)?(MI|PR|BC|DR|BL|SH|TS|FZ|DZ|RA|SN|SG|IC|PL|GR|GS|UP|BR|FG|FU|VA|DU|SA|HZ|PY|PO|SQ|FC|SS|DS|TR)+$/)) { sections.push({ raw: part, decoded: decodeWeather(part, metarString) }); @@ -572,8 +580,11 @@ sections.push({ raw: part, decoded: decodeTempDew(part) }); } else if (part.startsWith('A') && part.length === 5 && !isNaN(part.substring(1))) { sections.push({ raw: part, decoded: decodeAltimeter(part) }); + } else { + console.log(`Unknown main METAR part: ${part} in METAR: ${metarString}`); + sections.push({ raw: part, decoded: `${part}: Unknown METAR component` }); } - }); + } // Remarks section if (rmkIndex !== -1) {