refactor: Ensure METARs retain load order; use sorted list for random selection
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
+10
-6
@@ -73,6 +73,7 @@
|
|||||||
const nextBtn = document.getElementById('next-btn');
|
const nextBtn = document.getElementById('next-btn');
|
||||||
const decodeAllCheckbox = document.getElementById('decode-all-checkbox');
|
const decodeAllCheckbox = document.getElementById('decode-all-checkbox');
|
||||||
const metars = [];
|
const metars = [];
|
||||||
|
let sortedMetars = [];
|
||||||
|
|
||||||
let currentMetarSections = [];
|
let currentMetarSections = [];
|
||||||
let currentSectionIndex = 0;
|
let currentSectionIndex = 0;
|
||||||
@@ -828,9 +829,11 @@
|
|||||||
if (index !== undefined && index >= 0 && index < metars.length) {
|
if (index !== undefined && index >= 0 && index < metars.length) {
|
||||||
metarIndex = index;
|
metarIndex = index;
|
||||||
} else {
|
} else {
|
||||||
// Bias random selection towards the more interesting (higher-scored) METARs at the start of the array.
|
// Bias random selection towards the more interesting (higher-scored) METARs.
|
||||||
// Math.random() * Math.random() skews distribution towards 0.
|
// Math.random() * Math.random() skews distribution towards 0.
|
||||||
metarIndex = Math.floor(Math.random() * Math.random() * metars.length);
|
const randomSortedIndex = Math.floor(Math.random() * Math.random() * sortedMetars.length);
|
||||||
|
const selectedMetar = sortedMetars[randomSortedIndex];
|
||||||
|
metarIndex = metars.findIndex(m => m.metar === selectedMetar.metar);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (metarIndex === currentMetarIndex) {
|
if (metarIndex === currentMetarIndex) {
|
||||||
@@ -877,13 +880,14 @@
|
|||||||
metars.push({ metar: metarString, score: score });
|
metars.push({ metar: metarString, score: score });
|
||||||
});
|
});
|
||||||
|
|
||||||
// 3. Sort by score descending
|
// 3. Create a sorted copy for biased random selection, but don't sort the main array
|
||||||
metars.sort((a, b) => b.score - a.score);
|
sortedMetars = [...metars];
|
||||||
|
sortedMetars.sort((a, b) => b.score - a.score);
|
||||||
|
|
||||||
console.log(`Loaded and ranked ${metars.length} METARs.`);
|
console.log(`Loaded and ranked ${metars.length} METARs.`);
|
||||||
console.log(`Top 5 most interesting METARs:`);
|
console.log(`Top 5 most interesting METARs:`);
|
||||||
for (let i = 0; i < Math.min(5, metars.length); i++) {
|
for (let i = 0; i < Math.min(5, sortedMetars.length); i++) {
|
||||||
console.log(` - Score: ${metars[i].score.toFixed(2)}, METAR: ${metars[i].metar}`);
|
console.log(` - Score: ${sortedMetars[i].score.toFixed(2)}, METAR: ${sortedMetars[i].metar}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const hash = window.location.hash.substring(1);
|
const hash = window.location.hash.substring(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user