Source code for koa_middleware.datamodel_protocol
from abc import abstractmethod
from typing import Protocol, runtime_checkable
[docs]
@runtime_checkable
class SupportsCalibrationModelIO(Protocol):
"""
Structural interface for DataModel-like objects that can be written to disk
and converted into a calibration database record.
Any class instance that wishes to be treated as a CalibrationModel
must implement the methods defined here.
"""
[docs]
@abstractmethod
def save(
self, *args,
output_path : str | None = None,
output_dir: str | None = None,
**kwargs
) -> str:
"""
Save the data model to disk.
Parameters
----------
output_path : str, optional
Full file path to save the file to. If None, saves to the current directory.
output_dir : str, optional
Directory to save the file to. Ignored if ``output_path`` is provided.
Returns
-------
str
The full file path where the model was saved.
"""
...
[docs]
@abstractmethod
def to_record(self, *args, **kwargs) -> dict:
"""
Convert this model into a calibration database record.
Returns
-------
dict
A dictionary representing the calibration database record.
"""
...