diff --git a/src/calng/base_calcat.py b/src/calng/base_calcat.py index 9e2963113b487cd312ae407d7cfece0cabe3408f..5d126cec15facfe49a1660922d5e0703e023b53a 100644 --- a/src/calng/base_calcat.py +++ b/src/calng/base_calcat.py @@ -56,41 +56,96 @@ def add_status_schema_from_enum(schema, prefix, enum_class): BOOL_ELEMENT(schema) .key(f"{constant_node}.found") + .displayedName("Found and loaded") .readOnly() .initialValue(False) .commit(), STRING_ELEMENT(schema) - .key(f"{constant_node}.validFrom") + .key(f"{constant_node}.beginValidityAt") + .displayedName("Constant timestamp") + .description( + "This field displays the field 'begin_validity_at' from CalCat of the " + "most recently found + loaded constant. This field is tied to when the " + "constant was created and is useful to notice if some constants are " + "out of date." + ) .readOnly() .initialValue("") .commit(), STRING_ELEMENT(schema) .key(f"{constant_node}.calibrationId") + .displayedName("[CalCat] Calibration ID") + .description( + "In CalCat, each constant type is associated with a calibration ID " + "(for example, 'Offset' has ID 1). If calibration ID is not found, " + "something is quite wrong: missing in CalCat or issue with correction " + "device." + ) .readOnly() .initialValue("") .commit(), VECTOR_UINT32_ELEMENT(schema) .key(f"{constant_node}.conditionIds") + .displayedName("[CalCat] Condition IDs found") + .description( + "In CalCat, constants are found based on Physical Detector Unit and " + "the operating condition of the detector. A condition ID represents a " + "match on these. As operating conditions can overlap, a query may " + "involve multiple valid condition IDs; the retrieval strategy later " + "('closest in time') will determine which candidate constant is loaded." + ) .readOnly() .initialValue([]) .commit(), + STRING_ELEMENT(schema) + .key(f"{constant_node}.usedConditionId") + .displayedName("[CalCat] Condition ID used") + .description( + "Of the condition IDs found, this one applies to the constant that was " + "retrieved in the end." + ) + .readOnly() + .initialValue("") + .commit(), + VECTOR_UINT32_ELEMENT(schema) .key(f"{constant_node}.constantIds") + .displayedName("[CalCat] Constant IDs found") + .description( + "In CalCat, a 'constant' represents matching 'calibration ID', " + "'detector type ID', and 'condition ID'. Similar to condition IDs, a " + "query may yield multiple candidate constant IDs." + ) .readOnly() .initialValue([]) .commit(), + STRING_ELEMENT(schema) + .key(f"{constant_node}.usedConstantId") + .displayedName("[CalCat] Constant ID used") + .description( + "Of the candidate constant IDs, this one applies to the constant which " + "was retrieved in the end." + ) + .readOnly() + .initialValue("") + .commit(), + STRING_ELEMENT(schema) .key(f"{constant_node}.constantVersionId") + .displayedName("[CalCat] Constant version ID") .description( + "Finally, a constant version represents a concrete constant that can " + "be loaded (see descriptions of preceding fields for details on other " + "steps). " "This field is editable - if for any reason a specific constant " "version is desired, the constant version ID (as used in CalCat) can " "be set here and the slot below can be called to load this particular " - "version, overriding the automatic loading of latest constants." + "version. Only relevant in very unusual situations." ) .assignmentOptional() .defaultValue("") @@ -100,6 +155,27 @@ def add_status_schema_from_enum(schema, prefix, enum_class): SLOT_ELEMENT(schema) .key(f"{constant_node}.overrideConstantVersion") .displayedName("Override constant version") + .description("See description of constant version id.") + .commit(), + + STRING_ELEMENT(schema) + .key(f"{constant_node}.dataFilePath") + .displayedName("[Debug] Data file path") + .description( + "Where is the actual file for the currently loaded constant located?" + ) + .readOnly() + .initialValue("") + .commit(), + + STRING_ELEMENT(schema) + .key(f"{constant_node}.dataSetName") + .displayedName("[Debug] Data set name") + .description( + "Within the actual data file, where is the constant data located?" + ) + .readOnly() + .initialValue("") .commit(), ) @@ -457,12 +533,22 @@ class BaseCalcatFriend: self._check_resp(resp, warning="Failed to find calibration constant version") # TODO: replace with start date and end date timestamp = resp["data"]["begin_validity_at"] - self._set_status(constant, "validFrom", timestamp) + self._set_status(constant, "beginValidityAt", timestamp) self._set_status(constant, "constantVersionId", resp["data"]["id"]) + self._set_status( + constant, + "usedConditionId", + resp["data"]["calibration_constant"]["condition_id"], + ) + self._set_status( + constant, "usedConstantId", resp["data"]["calibration_constant"]["id"] + ) file_path = ( self.caldb_store / resp["data"]["path_to_file"] / resp["data"]["file_name"] ) + self._set_status(constant, "dataFilePath", str(file_path)) + self._set_status(constant, "dataSetName", resp["data"]["data_set_name"]) # TODO: handle FileNotFoundError if we are led astray with h5py.File(file_path, "r") as fd: constant_data = np.array(fd[resp["data"]["data_set_name"]]["data"]) @@ -489,7 +575,7 @@ class BaseCalcatFriend: constant_data = np.array(fd[resp["data"]["data_set_name"]]["data"]) with self.cached_constants_lock: self.cached_constants[constant] = constant_data - self._set_status(constant, "validFrom", resp["data"]["begin_at"]) + self._set_status(constant, "beginValidityAt", resp["data"]["begin_at"]) self._set_status(constant, "calibrationId", "manual override") self._set_status(constant, "conditionId", "manual override") self._set_status(constant, "constantId", "manual override") @@ -526,7 +612,7 @@ class BaseCalcatFriend: def flush_constants(self): for constant in self._constant_enum_class: - self._set_status(constant, "validFrom", "") + self._set_status(constant, "beginValidityAt", "") self._set_status(constant, "found", False) def _check_resp(self, resp, exception=Exception, warning=None): diff --git a/src/calng/scenes.py b/src/calng/scenes.py index e830bb7e0e43ce65e2fbd56555de9dbdea06eb53..fb00b680ef0d39f9547c89e375b71bf5019e7cc8 100644 --- a/src/calng/scenes.py +++ b/src/calng/scenes.py @@ -297,31 +297,38 @@ class MaybeEditableRow(HorizontalLayout): @titled("Found constants", width=6 * NARROW_INC) @boxed class FoundConstantsColumn(VerticalLayout): - def __init__(self, device_id, schema_hash, prefix="foundConstants"): + def __init__( + self, + device_id, + schema_hash, + prefix="foundConstants", + ): super().__init__(padding=0) - self.children.extend( - [ - HorizontalLayout( - LabelModel( - text=constant_name, - width=6 * NARROW_INC, - height=NARROW_INC, - ), - ColorBoolModel( - width=NARROW_INC, - height=NARROW_INC, - keys=[f"{device_id}.{prefix}.{constant_name}.found"], - ), - DisplayLabelModel( - keys=[f"{device_id}.{prefix}.{constant_name}.validFrom"], - width=8 * BASE_INC, - height=BASE_INC, - ), - padding=0, - ) - for constant_name in schema_hash.get(prefix).getKeys() - ] - ) + for constant_name in schema_hash.get(prefix).getKeys(): + constant_row = HorizontalLayout( + LabelModel( + text=constant_name, + width=6 * NARROW_INC, + height=NARROW_INC, + ), + ColorBoolModel( + width=NARROW_INC, + height=NARROW_INC, + keys=[f"{device_id}.{prefix}.{constant_name}.found"], + ), + DisplayLabelModel( + keys=[f"{device_id}.{prefix}.{constant_name}.beginValidityAt"], + width=8 * BASE_INC, + height=BASE_INC, + ), + DisplayLabelModel( + keys=[f"{device_id}.{prefix}.{constant_name}.constantVersionId"], + width=3 * BASE_INC, + height=BASE_INC, + ), + padding=0, + ) + self.children.append(constant_row) class ConstantLoadedAmpeln(HorizontalLayout): @@ -780,7 +787,7 @@ def correction_constant_dashboard( ), *( DisplayLabelModel( - keys=[f"{device_id}.{prefix}.{constant}.validFrom"], + keys=[f"{device_id}.{prefix}.{constant}.beginValidityAt"], width=7 * BASE_INC, height=BASE_INC, font_size=9,