neclib.core.data_type.status_manager#
Aliases#
None |
- class StatusManager(ctx_type, /, start='start', stop='stop', idx_getter=<built-in function time>, keep=60)[source]#
Bases:
Generic
[T
]Manage multiple contexts.
- Parameters:
ctx_type (Type[T]) – A dataclass type which keeps single status/context. The arguments of its constructor should have default values, otherwise
get(out_of_range)
will fail.start (str) – Name of the attribute which stores the start index of the context. The index would typically be the time.
stop (str) – Name of the attribute which stores the stop index of the context.
idx_getter (Callable[[], float]) – A function which returns the current index. This function is called with no arguments.
keep (float) – Maximum index difference from current one to keep the context. Contexts with index difference larger than this value will be removed.
Examples
>>> @dataclass ... class Context: ... start: Optional[float] = None ... stop: Optional[float] = None ... value: int = 0 >>> manager = StatusManager(Context) >>> manager.get(time.time()) Context(start=None, stop=None, value=0) # default value >>> manager.set(start=time.time(), stop=time.time() + 10, value=100) >>> manager.get(time.time()) Context(start=..., stop=..., value=100)