fix: Refactor displayMetar to correctly load METAR by URL ID

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
2026-02-14 18:13:06 -07:00
parent dc7345fb1d
commit c7a6fa4a11
+4 -4
View File
@@ -825,15 +825,15 @@
return; return;
} }
let metarIndex = -1; let metarIndex;
// If an ID is provided, try to find it.
if (id !== undefined) { if (id !== undefined) {
metarIndex = metars.findIndex(m => m.line === id); metarIndex = metars.findIndex(m => m.line === id);
} }
if (metarIndex === -1) { // If no ID was provided, or the ID was not found, pick a random METAR.
// Bias random selection towards the more interesting (higher-scored) METARs. if (id === undefined || metarIndex === -1) {
// Math.random() * Math.random() skews distribution towards 0.
const randomSortedIndex = Math.floor(Math.random() * Math.random() * sortedMetars.length); const randomSortedIndex = Math.floor(Math.random() * Math.random() * sortedMetars.length);
const selectedMetar = sortedMetars[randomSortedIndex]; const selectedMetar = sortedMetars[randomSortedIndex];
metarIndex = metars.findIndex(m => m.metar === selectedMetar.metar); metarIndex = metars.findIndex(m => m.metar === selectedMetar.metar);