Skip to content

Commit

Permalink
Allow for requests for historical data with no events
Browse files Browse the repository at this point in the history
  • Loading branch information
ugyballoons committed Oct 11, 2024
1 parent 1dd5261 commit 822a854
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions python/lsst/ts/rubintv/background/historicaldata.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, locations: list[Location], test_mode: bool = False) -> None:
self._clients: dict[str, S3Client] = {}
self._metadata: dict[str, bytes] = {}
self._temp_events: dict[str, list[Event]] = {}
self._events: dict[str, bytes] = {}
self._compressed_events: dict[str, bytes] = {}
self._nr_metadata: dict[str, list[NightReportData]] = {}
self._calendar: dict[str, dict[int, dict[int, dict[int, int]]]] = {}
self._locations = locations
Expand All @@ -61,7 +61,7 @@ def __init__(self, locations: list[Location], test_mode: bool = False) -> None:
async def clear_all_data(self) -> None:
self._have_downloaded = False
self._metadata = {}
self._events = {}
self._compressed_events = {}
self._nr_metadata = {}
self._calendar = {}

Expand Down Expand Up @@ -156,10 +156,12 @@ async def filter_convert_store_objects(
async def compress_events(self) -> None:
for storage_key, events in self._temp_events.items():
compressed = zlib.compress(pickle.dumps(events))
if storage_key in self._events:
self._events[storage_key] += compressed
if storage_key in self._compressed_events:
self._compressed_events[storage_key] += compressed
else:
self._events[storage_key] = compressed
self._compressed_events[storage_key] = compressed

# async def add_metadata_to_calendar(self) -> None:

async def store_events(self, events: list[Event], locname: str) -> None:
for event in events:
Expand Down Expand Up @@ -264,8 +266,10 @@ async def get_events_for_date(
) -> list[Event]:
loc_cam = f"{location.name}/{camera.name}"
date_str = a_date.isoformat()
compressed = self._events[loc_cam]
events: list[Event] = pickle.loads(zlib.decompress(compressed))
to_decompress = self._compressed_events.get(loc_cam, None)
if to_decompress is None:
return []
events: list[Event] = pickle.loads(zlib.decompress(to_decompress))
events = [e for e in events if e.day_obs == date_str]
return events

Expand Down Expand Up @@ -324,7 +328,7 @@ async def get_most_recent_events(
day_obs = await self.get_most_recent_day(location, camera)
if not day_obs:
return []
compressed = self._events.get(loc_cam, None)
compressed = self._compressed_events.get(loc_cam, None)
if compressed is None:
return []
events = pickle.loads(zlib.decompress(compressed))
Expand All @@ -335,7 +339,7 @@ async def get_most_recent_event(
self, location: Location, camera: Camera, channel: Channel
) -> Event | None:
loc_cam = f"{location.name}/{camera.name}"
compressed = self._events.get(loc_cam, None)
compressed = self._compressed_events.get(loc_cam, None)
if compressed is None:
return None
events = pickle.loads(zlib.decompress(compressed))
Expand Down

0 comments on commit 822a854

Please sign in to comment.