Source code for iCalibrationDB.constant_version

from datetime import datetime
from dateutil import parser

from .detectors import DetectorModule
from .util import DictConvertable


[docs]class ConstantVersion(DictConvertable): """ Calibration constant versions reflect evolution over time """ mandatory = ["karabo_id", "file_name", "flg_good_quality", "begin_validity_at", "end_validity_at", "begin_at"] retrieve_optionals = ["file_name"] def __init__(self): super(ConstantVersion, self).__init__() self._datadict = dict() self._datadict["flg_good_quality"] = True @property def ccv_id(self): """ Id number of the calibration constant version """ return self._datadict.get("ccv_id") @ccv_id.setter def ccv_id(self, value): self._datadict["ccv_id"] = value @ccv_id.deleter def ccv_id(self): del self._datadict["ccv_id"] @property def device_name(self): """ Name of the device producing the constant """ return self._datadict.get("pdu_physical_name") @device_name.setter def device_name(self, value): if not value and not self.karabo_da: raise ValueError("Need to define a non-empty device_name " "or karabo-da!") if isinstance(value, DetectorModule): value = value.device_name self._datadict["pdu_physical_name"] = str(value) @device_name.deleter def device_name(self): del self._datadict["pdu_physical_name"] @property def karabo_id(self): """ Name of the Karabo ID to identify the detector producing the constant """ return self._datadict.get("karabo_id") @karabo_id.setter def karabo_id(self, value): if not value: raise ValueError("Need to define a non-empty karabo_id") if isinstance(value, DetectorModule): value = value.karabo_id self._datadict["karabo_id"] = str(value) @karabo_id.deleter def karabo_id(self): del self._datadict["karabo_id"] @property def karabo_da(self): """ Name of the Karabo DA to identify the detector producing the constant """ return self._datadict.get("karabo_da") @karabo_da.setter def karabo_da(self, value): if not value and not self.device_name: raise ValueError("Need to define a non-empty karabo_da " "or device_name!") if isinstance(value, DetectorModule): value = value.karabo_da self._datadict["karabo_da"] = str(value) @karabo_da.deleter def karabo_da(self): del self._datadict["karabo_da"] @property def karabo_id(self): """ Name of the Karabo ID to identify the detector producing the constant """ return self._datadict.get("karabo_id") @karabo_id.setter def karabo_id(self, value): if not value: raise ValueError("Need to define a non-empty karabo_id") if isinstance(value, DetectorModule): value = value.karabo_id self._datadict["karabo_id"] = str(value) @karabo_id.deleter def karabo_id(self): del self._datadict["karabo_id"] @property def karabo_da(self): """ Name of the Karabo DA to identify the detector producing the constant """ return self._datadict.get("karabo_da") @karabo_da.setter def karabo_da(self, value): if not value and not self.device_name: raise ValueError("Need to define a non-empty karabo_da " "or device_name!") if isinstance(value, DetectorModule): value = value.karabo_da self._datadict["karabo_da"] = str(value) @karabo_da.deleter def karabo_da(self): del self._datadict["karabo_da"] @property def file_name(self): """ File name the constant is stored at - will be auto-filled """ return self._datadict.get("file_name") @file_name.setter def file_name(self, value): self._datadict["file_name"] = str(value) @file_name.deleter def file_name(self): del self._datadict["file_name"] @property def good_quality(self): """ Flag indicating if the constant is of good quality (True) """ return self._datadict.get("flg_good_quality") @good_quality.setter def good_quality(self, value): self._datadict["flg_good_quality"] = bool(value) @good_quality.deleter def good_quality(self): del self._datadict["flg_good_quality"] @property def begin_validity_at(self): """ When the validity of the constant begins at. Expects a datetime object, e.g. `datatime.now()` """ value = self._datadict.get("begin_validity_at") if value is None: return value return parser.parse(value) @begin_validity_at.setter def begin_validity_at(self, value): if value is None: self._datadict["begin_validity_at"] = None return if not isinstance(value, datetime): raise ValueError("Expecting datetime object") self._datadict["begin_validity_at"] = value.isoformat() @begin_validity_at.deleter def begin_validity_at(self): del self._datadict["begin_validity_at"] @property def end_validity_at(self): """ When the validity of the constant ends at. Expects a datetime object, e.g. `datatime.now()` """ value = self._datadict.get("end_validity_at") if value is None: return value return parser.parse(value) @end_validity_at.setter def end_validity_at(self, value): if value is None: self._datadict["end_validity_at"] = None return if not isinstance(value, datetime): raise ValueError("Expecting datetime object") self._datadict["end_validity_at"] = value.isoformat() @end_validity_at.deleter def end_validity_at(self): del self._datadict["end_validity_at"] @property def begin_at(self): """ When the constant was produced/injected Expects a datetime object, e.g. `datatime.now()` """ value = self._datadict.get("begin_at") if value is None: return value return parser.parse(value) @begin_at.setter def begin_at(self, value): if value is None: self._datadict["begin_at"] = None return if not isinstance(value, datetime): raise ValueError("Expecting datetime object") self._datadict["begin_at"] = value.isoformat() @begin_at.deleter def begin_at(self): del self._datadict["begin_at"] @property def description(self): """ A description of this constant version """ return self._datadict.get("description") @description.setter def description(self, value): self._datadict["description"] = str(value) @description.deleter def description(self): del self._datadict["description"] @property def raw_data_location(self): """ Location of the raw_data. Will be auto-set. """ return self._datadict.get("raw_data_location") @raw_data_location.setter def raw_data_location(self, value): self._datadict["raw_data_location"] = str(value) @raw_data_location.deleter def raw_data_location(self): del self._datadict["raw_data_location"] @property def report_path(self): """ Path of the report. Will be auto-set. """ return self._datadict.get("report") @report_path.setter def report_path(self, value): self._datadict["report"] = dict(value) @report_path.deleter def report_path(self): del self._datadict["report"]