Make ionosonde_data a map keyed by URSI, and on polling the website, replace data for the specific URSI rather than overwriting everything. This allows us to preserve data from an older lookup if the website is down or returns nothing

This commit is contained in:
Ian Renton
2026-05-16 11:04:40 +01:00
parent 6058eb5053
commit a7a45190cb
13 changed files with 48 additions and 49 deletions

View File

@@ -115,7 +115,7 @@ function loadSolarConditions() {
// Ionosonde
if (jsonData.ionosonde_data && jsonData.ionosonde_data.length > 0) {
if (jsonData.ionosonde_data && Object.keys(jsonData.ionosonde_data).length > 0) {
ionosondeData = jsonData.ionosonde_data;
populateIonosondeDropdown(ionosondeData);
renderIonosondeData();
@@ -366,9 +366,12 @@ function populateIonosondeDropdown(data) {
const savedUrsi = localStorage.getItem('#ionosonde-station:value');
const savedValue = savedUrsi ? JSON.parse(savedUrsi) : null;
select.empty();
data.forEach(function (station) {
// Sort by station name rather than URSI because station name is what's displayed, and any out-of-order names might
// confuse the user
Object.values(data).sort((a, b) => a.name.localeCompare(b.name)).forEach(function (station) {
select.append($('<option>', {value: station.ursi, text: station.name}));
});
// Select one by default if the user's localStorage has an existing selection for this
if (savedValue && select.find('option[value="' + savedValue + '"]').length) {
select.val(savedValue);
}
@@ -381,9 +384,7 @@ function renderIonosondeData() {
if (!ionosondeData) return;
const ursi = $('#ionosonde-station').val();
if (!ursi) return;
const station = ionosondeData.find(function (s) {
return s.ursi === ursi;
});
const station = ionosondeData[ursi];
if (!station) return;
// Set up some styles, matching the k-index chart. We use Bootstrap's "primary" and "danger" colours not for any