Allow fetching soundings by station ID

This commit is contained in:
XANTRONIX 2025-03-29 18:49:08 -04:00
parent 1ddc343487
commit cda1413f2c

View file

@ -572,16 +572,13 @@ class RAOBReader():
self.soundings = dict() self.soundings = dict()
def sounding(self, station: str, timestamp: str) -> RAOBSounding: def sounding(self, station: str, timestamp: str) -> RAOBSounding:
key = station + '.' + timestamp if station not in self.soundings:
self.soundings[station] = dict()
if key in self.soundings: if timestamp not in self.soundings[station]:
return self.soundings[key] self.soundings[station][timestamp] = RAOBSounding(station, timestamp)
sounding = RAOBSounding(station, timestamp) return self.soundings[station][timestamp]
self.soundings[key] = sounding
return sounding
def parse_chunk(self, text: str) -> RAOBChunk: def parse_chunk(self, text: str) -> RAOBChunk:
meta = { meta = {
@ -667,12 +664,17 @@ class RAOBReader():
data.get('wind_speed'), data.get('wind_speed'),
data.get('wind_dir')) data.get('wind_dir'))
for key in self.soundings: def each_sounding_by_station(self, station: str):
sounding = self.soundings[key].finish() for timestamp in self.soundings[station]:
sounding = self.soundings[station][timestamp].finish()
if sounding is not None: if sounding is not None:
yield sounding yield sounding
def each_sounding(self):
for station in self.soundings:
yield from self.each_sounding_by_station(station)
@staticmethod @staticmethod
def each_sounding_from_fh(fh: io.TextIOBase): def each_sounding_from_fh(fh: io.TextIOBase):
reader = RAOBReader(fh) reader = RAOBReader(fh)