mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-09-21 06:47:42 +00:00
Autogenerated type safety parameterisation of all methods
This commit is contained in:
+27
-18
@@ -1,14 +1,23 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import re
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
import diskcache
|
||||
import geopandas
|
||||
|
||||
from core.config import MAX_ALERT_AGE, MAX_SPOT_AGE
|
||||
from core.live_data_cache import LiveDataCache
|
||||
from core.single_object_data_cache import SingleObjectDataCache
|
||||
from data.solar_conditions import SolarConditions
|
||||
|
||||
if TYPE_CHECKING:
|
||||
# Deferred to avoid a circular import: data.alert and data.spot both import core.data_store at module level.
|
||||
from data.alert import Alert
|
||||
from data.spot import Spot
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
CACHE_DIR = "./cache/"
|
||||
@@ -18,31 +27,31 @@ class DataStore:
|
||||
"""Data caching/storage object. Handles storage of spots, alerts, solar conditions, activity reference data, and
|
||||
callsign lookup data using different caching strategies for each."""
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
# Constants
|
||||
self._MAX_SPOT_COUNT = 100000
|
||||
self._MAX_ALERT_COUNT = 100000
|
||||
self._SPOT_ALERT_SNAPSHOT_INTERVAL_SEC = 300
|
||||
self.CALLSIGN_DATA_TTL_SEC = 30 * 24 * 60 * 60
|
||||
# Caches
|
||||
self.alerts = None
|
||||
self.spots = None
|
||||
self.callsign_data_countryfiles = None
|
||||
self.callsign_data_clublogxml = None
|
||||
self.callsign_data_clublogapi = None
|
||||
self.callsign_data_qrz = None
|
||||
self.callsign_data_hamqth = None
|
||||
self.dxcc_data = None
|
||||
self.dxcc_lookup_by_call_regex = []
|
||||
self.activity_refs = None
|
||||
self.status = None
|
||||
self.solar_conditions = None
|
||||
self.alerts: LiveDataCache[Alert] | None = None
|
||||
self.spots: LiveDataCache[Spot] | None = None
|
||||
self.callsign_data_countryfiles: diskcache.Cache | None = None
|
||||
self.callsign_data_clublogxml: diskcache.Cache | None = None
|
||||
self.callsign_data_clublogapi: diskcache.Cache | None = None
|
||||
self.callsign_data_qrz: diskcache.Cache | None = None
|
||||
self.callsign_data_hamqth: diskcache.Cache | None = None
|
||||
self.dxcc_data: diskcache.Cache | None = None
|
||||
self.dxcc_lookup_by_call_regex: list[tuple[re.Pattern[str], Any]] = []
|
||||
self.activity_refs: diskcache.Cache | None = None
|
||||
self.status: SingleObjectDataCache[dict[str, Any]] | None = None
|
||||
self.solar_conditions: SingleObjectDataCache[SolarConditions] | None = None
|
||||
# ITU/CQ zone GeoJSON data is only ever loaded statically from a local file so these don't even need to be
|
||||
# caches, they can just be straight objects
|
||||
self.cq_zone_data = None
|
||||
self.itu_zone_data = None
|
||||
self.cq_zone_data: geopandas.GeoDataFrame | None = None
|
||||
self.itu_zone_data: geopandas.GeoDataFrame | None = None
|
||||
|
||||
def setup(self):
|
||||
def setup(self) -> None:
|
||||
Path(CACHE_DIR).mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# For solar data and status data, we use a wrapper around disk cache where each cache contains only a single
|
||||
@@ -100,7 +109,7 @@ class DataStore:
|
||||
)
|
||||
logger.info(f"Loaded {len(self.alerts.keys())} alerts from a previous run.")
|
||||
|
||||
def regenerate_call_regex_to_dxcc_entity_map(self):
|
||||
def regenerate_call_regex_to_dxcc_entity_map(self) -> None:
|
||||
"""DXCC entity data from K0SWE includes a regex which we can use to match a callsign, and determine which DXCC
|
||||
entity it belongs to. But getting every DXCC entity data object out of DiskCache, iterating, compiling its regex
|
||||
and testing the callsign every time is expensive. So instead we build a separate in-memory lookup of compiled
|
||||
@@ -110,7 +119,7 @@ class DataStore:
|
||||
for entry in [DATA_STORE.dxcc_data[key] for key in DATA_STORE.dxcc_data]:
|
||||
self.dxcc_lookup_by_call_regex.append((re.compile(entry["prefixRegex"]), entry["entityCode"]))
|
||||
|
||||
def close(self):
|
||||
def close(self) -> None:
|
||||
self.spots.close()
|
||||
self.alerts.close()
|
||||
self.solar_conditions.close()
|
||||
|
||||
Reference in New Issue
Block a user