@@ -93,11 +93,10 @@ def clear_caches():
93
93
OBSERVATIONS .clear ()
94
94
95
95
96
- def _merge_cmds_archive_recent (start , scenario ):
96
+ def _merge_cmds_archive_recent (start , cache_key , cmds_recent ):
97
97
"""Merge cmds archive from ``start`` onward with recent cmds for ``scenario``
98
98
99
99
This assumes:
100
- - CMDS_RECENT cache has been set with that scenario.
101
100
- Recent commands overlap the cmds archive
102
101
103
102
Parameters
@@ -112,11 +111,10 @@ def _merge_cmds_archive_recent(start, scenario):
112
111
CommandTable
113
112
Commands from cmds archive and all recent commands
114
113
"""
115
- cmds_recent = CMDS_RECENT [scenario ]
116
114
117
115
logger .info (f"Merging cmds_recent with archive commands from { start } " )
118
116
119
- if scenario not in MATCHING_BLOCKS :
117
+ if cache_key not in MATCHING_BLOCKS :
120
118
# Get index for start of cmds_recent within the cmds archive
121
119
i0_arch_recent = IDX_CMDS .find_date (cmds_recent ["date" ][0 ])
122
120
@@ -130,9 +128,9 @@ def _merge_cmds_archive_recent(start, scenario):
130
128
IDX_CMDS [i0_arch_recent :], cmds_recent
131
129
)
132
130
arch_block_end = i0_arch_recent + arch_recent_offset
133
- MATCHING_BLOCKS [scenario ] = arch_block_end , recent_block_end , i0_arch_recent
131
+ MATCHING_BLOCKS [cache_key ] = arch_block_end , recent_block_end , i0_arch_recent
134
132
else :
135
- arch_block_end , recent_block_end , i0_arch_recent = MATCHING_BLOCKS [scenario ]
133
+ arch_block_end , recent_block_end , i0_arch_recent = MATCHING_BLOCKS [cache_key ]
136
134
137
135
# Get archive commands from the requested start time (or start of the overlap
138
136
# with recent commands) to the end of the matching block in recent commands.
@@ -258,6 +256,10 @@ def get_cmds(
258
256
# Default stop is either now (typically) or set by env var
259
257
default_stop = CxoTime (get_default_stop ())
260
258
259
+ # Cache key used for CMDS_RECENT and MATCHING_BLOCKS.
260
+ # TODO: make more complete.
261
+ cache_key = scenario
262
+
261
263
# For flight scenario or no internet or if the query stop time is guaranteed
262
264
# to not require recent commands then just use the archive.
263
265
before_recent_cmds = stop < default_stop - conf .default_lookback * u .day
@@ -268,7 +270,7 @@ def get_cmds(
268
270
f" { scenario = } { before_recent_cmds = } { HAS_INTERNET = } "
269
271
)
270
272
else :
271
- if scenario not in CMDS_RECENT :
273
+ if cache_key not in CMDS_RECENT :
272
274
cmds_recent = update_archive_and_get_cmds_recent (
273
275
scenario ,
274
276
cache = True ,
@@ -277,7 +279,7 @@ def get_cmds(
277
279
event_filter = event_filter ,
278
280
)
279
281
else :
280
- cmds_recent = CMDS_RECENT [scenario ]
282
+ cmds_recent = CMDS_RECENT [cache_key ]
281
283
282
284
# Get `cmds` as correct mix of recent and archive commands that contains
283
285
# the requested date range.
@@ -293,7 +295,7 @@ def get_cmds(
293
295
# archive commands. The margin is set at 3 days to ensure that OBS
294
296
# command continuity is maintained (there is at least one maneuver).
295
297
# See also the DESIGN commentary after the function.
296
- cmds = _merge_cmds_archive_recent (start , scenario )
298
+ cmds = _merge_cmds_archive_recent (start , cache_key , cmds_recent )
297
299
logger .info (
298
300
"Getting commands from archive + recent: start < recent loads start +"
299
301
f" 3 days for { scenario = } "
@@ -372,9 +374,11 @@ def update_archive_and_get_cmds_recent(
372
374
----------
373
375
scenario : str, None
374
376
Scenario name
375
- lookback : int, Quantity, None
376
- Lookback time from ``stop`` for recent loads. If None, use
377
+ lookback : int, None
378
+ Lookback time from ``stop`` for recent loads in days . If None, use
377
379
conf.default_lookback.
380
+ stop : CxoTime-like, None
381
+ Stop time for recent loads. If None, use default_stop.
378
382
cache : bool
379
383
Cache the result in CMDS_RECENT dict.
380
384
pars_dict : dict, None
@@ -385,6 +389,7 @@ def update_archive_and_get_cmds_recent(
385
389
Callable function or list of callable functions that takes an Event Table as
386
390
input and returns a boolean mask with same length as Table. This is used to
387
391
select rows from the Table. If None, no filtering is done.
392
+
388
393
Returns
389
394
-------
390
395
CommandTable
0 commit comments