mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-09-20 22:37:44 +00:00
Autogenerated type safety parameterisation of all methods
This commit is contained in:
+16
-11
@@ -1,5 +1,10 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, TypeVar
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
# Lookup tables for derived text descriptions.
|
||||
# Each threshold-based table is a list of (min_value, description) pairs in descending order;
|
||||
@@ -71,7 +76,7 @@ ELECTRON_FLUX_DESCRIPTIONS = [
|
||||
]
|
||||
|
||||
|
||||
def _xray_blackout_scale(xray):
|
||||
def _xray_blackout_scale(xray: str | None) -> int:
|
||||
"""Return the NOAA Radio Blackout scale number (R0-R5) for the given X-ray flux class string
|
||||
(e.g. "M4.5", "X12")."""
|
||||
|
||||
@@ -93,7 +98,7 @@ def _xray_blackout_scale(xray):
|
||||
return 0
|
||||
|
||||
|
||||
def _lookup_by_threshold(value, table, default=None):
|
||||
def _lookup_by_threshold(value: int | None, table: list[tuple[int, T]], default: T | None = None) -> T | None:
|
||||
"""Return the description from a threshold table for the given numeric value.
|
||||
The table is a list of (min_value, description) pairs in descending order."""
|
||||
|
||||
@@ -150,20 +155,20 @@ class SolarConditions:
|
||||
# Geomagnetic background noise level, e.g. "S0", "S1", "S2"
|
||||
geomag_noise: str | None = None
|
||||
# HF band propagation conditions, keyed by "{band}-{time}" e.g. "80m-40m-day"
|
||||
hf_conditions: dict | None = None
|
||||
hf_conditions: dict[str, str] | None = None
|
||||
# VHF propagation conditions, keyed by condition name
|
||||
vhf_conditions: dict | None = None
|
||||
vhf_conditions: dict[str, str | None] | None = None
|
||||
# NOAA Kp index 3-day forecast, keyed by UNIX timestamp of the start of each 3-hour UTC period
|
||||
k_index_forecast: dict | None = None
|
||||
k_index_forecast: dict[float, float] | None = None
|
||||
# NOAA Solar Radiation Storm (S1 or greater) probability forecast, keyed by UNIX timestamp of start of day UTC
|
||||
solar_storm_forecast: dict | None = None
|
||||
solar_storm_forecast: dict[float, int] | None = None
|
||||
# NOAA Radio Blackout (R1-R2) probability forecast, keyed by UNIX timestamp of start of day UTC
|
||||
blackout_forecast_r1r2: dict | None = None
|
||||
blackout_forecast_r1r2: dict[float, int] | None = None
|
||||
# NOAA Radio Blackout (R3 or greater) probability forecast, keyed by UNIX timestamp of start of day UTC
|
||||
blackout_forecast_r3_or_greater: dict | None = None
|
||||
blackout_forecast_r3_or_greater: dict[float, int] | None = None
|
||||
# Ionosonde measurements, dict keyed by URSI code, values are dicts with keys: ursi, name, fof2, muf, luf,
|
||||
# band_states. Populated by GIROIonosonde or KC2GProp providers.
|
||||
ionosonde_data: dict | None = None
|
||||
ionosonde_data: dict[str, Any] | None = None
|
||||
|
||||
# Derived values (populated by infer_descriptions())
|
||||
# HF radio blackout risk description, derived from xray
|
||||
@@ -183,7 +188,7 @@ class SolarConditions:
|
||||
# Electron flux description, derived from electron_flux
|
||||
electron_flux_desc: str | None = None
|
||||
|
||||
def infer_descriptions(self):
|
||||
def infer_descriptions(self) -> None:
|
||||
"""Populate derived text description fields from the current numeric/raw field values."""
|
||||
|
||||
if self.xray and len(self.xray) > 0:
|
||||
@@ -196,7 +201,7 @@ class SolarConditions:
|
||||
self.band_conditions_desc = _lookup_by_threshold(self.sfi, BAND_CONDITIONS_DESCRIPTIONS)
|
||||
self.electron_flux_desc = _lookup_by_threshold(self.electron_flux, ELECTRON_FLUX_DESCRIPTIONS)
|
||||
|
||||
def to_json(self):
|
||||
def to_json(self) -> str:
|
||||
"""JSON serialise. Dict key order is insertion order (Python 3.7+ guarantee), so callers receive
|
||||
fields in a predictable, logical sequence without relying on sort_keys."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user