mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-06-23 21:25:12 +00:00
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:
@@ -51,34 +51,33 @@ class GIROIonosonde(SolarConditionsProvider):
|
||||
|
||||
def _poll(self):
|
||||
try:
|
||||
logging.debug(f"Polling {self.name} ionosonde data...")
|
||||
logging.debug(f"Polling GIRO ionosonde data...")
|
||||
now = datetime.now(timezone.utc)
|
||||
from_time = now - timedelta(hours=HISTORY_HOURS)
|
||||
results = []
|
||||
ionosonde_data = dict(self._solar_conditions.ionosonde_data or {})
|
||||
updated_count = 0
|
||||
|
||||
for station in self._stations:
|
||||
if self._stop_event.is_set():
|
||||
break
|
||||
ursi = station["ursi"]
|
||||
name = station["name"]
|
||||
entry = {"ursi": ursi, "name": name, "fof2": None, "muf": None}
|
||||
try:
|
||||
fof2, muf = self._fetch_station_data(ursi, from_time, now)
|
||||
entry["fof2"] = fof2
|
||||
entry["muf"] = muf
|
||||
if fof2 and muf:
|
||||
results.append(entry)
|
||||
ionosonde_data[ursi] = {"ursi": ursi, "name": name, "fof2": fof2, "muf": muf}
|
||||
updated_count += 1
|
||||
except Exception:
|
||||
logging.debug(f"Could not fetch ionosonde data for {ursi} ({name})")
|
||||
logging.warning(f"Could not fetch ionosonde data for {ursi} ({name})")
|
||||
|
||||
self.update_data({"ionosonde_data": results})
|
||||
self.update_data({"ionosonde_data": ionosonde_data})
|
||||
self.status = "OK"
|
||||
self.last_update_time = datetime.now(pytz.UTC)
|
||||
logging.debug(f"Received ionosonde data for {len(results)} stations from {self.name}.")
|
||||
logging.debug(f"Updated ionosonde data for {updated_count} stations.")
|
||||
|
||||
except Exception:
|
||||
self.status = "Error"
|
||||
logging.exception(f"Exception in GIRO Ionosonde data provider ({self.name})")
|
||||
logging.exception(f"Exception in GIRO Ionosonde data provider")
|
||||
self._stop_event.wait(timeout=1)
|
||||
|
||||
def _fetch_station_data(self, ursi, from_time, to_time):
|
||||
@@ -86,9 +85,7 @@ class GIROIonosonde(SolarConditionsProvider):
|
||||
|
||||
from_str = from_time.strftime("%Y.%m.%d+%H:%M:%S")
|
||||
to_str = to_time.strftime("%Y.%m.%d+%H:%M:%S")
|
||||
url = (
|
||||
f"{LGDC_URL}?ursiCode={ursi}&charName=foF2,MUFD&DMUF=3000&fromDate={from_str}&toDate={to_str}"
|
||||
)
|
||||
url = f"{LGDC_URL}?ursiCode={ursi}&charName=foF2,MUFD&DMUF=3000&fromDate={from_str}&toDate={to_str}"
|
||||
response = requests.get(url, headers=HTTP_HEADERS, timeout=(5, 15))
|
||||
if response.status_code != 200:
|
||||
return None, None
|
||||
@@ -104,10 +101,11 @@ class GIROIonosonde(SolarConditionsProvider):
|
||||
line = line.strip()
|
||||
if not line or line.startswith('#'):
|
||||
continue
|
||||
# Data rows: timestamp CS foF2 QD MUFD QD
|
||||
# Data rows have the following format: timestamp CS foF2 QD MUFD QD
|
||||
parts = line.split()
|
||||
if len(parts) >= 5:
|
||||
try:
|
||||
# Python 3.8 TZ parsing fudge
|
||||
ts = datetime.fromisoformat(parts[0].replace('Z', '+00:00')).timestamp()
|
||||
except ValueError:
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user