diff --git a/src/cal_tools/constants.py b/src/cal_tools/constants.py index edd00892cbcd8d44f0f03c05bf9c2f9b9d4d7be9..25cb9355f09ec6cb79dff49ad6d1dafdd2d0c47a 100644 --- a/src/cal_tools/constants.py +++ b/src/cal_tools/constants.py @@ -32,10 +32,9 @@ class CCVAlreadyInjectedError(InjectionError): @dataclass class ParameterConditionAttribute: value: str - parameter_id: str = "" # Default value, allowing assignment later lower_deviation_value: float = 0 upper_deviation_value: float = 0 - flg_available: str = 'true' + flg_available: bool = True description: str = '' @@ -51,13 +50,7 @@ def generate_unique_condition_name( detector_type (str): detector type. pdu_name (str): Physical detector unit db name. pdu_uuid (float): Physical detector unit db id. - cond_params (dict): A list of dictionary with each condition - e.g. [{ - "parameter_name": "Memory Cells", - "value": 352.0, - "lower-deviation": 0.0, - "upper-deviation": 0.0 - }] + cond_params (dict): Keys DB names, values ParameterConditionAttribute Returns: str: A unique name used for the table of conditions. @@ -242,9 +235,9 @@ def get_or_create_calibration_constant( calibration_id=cal_id, condition_id=cond_id, detector_type_id=det_type_id, - flg_auto_approve = 'true', - flg_available = 'true', - description = "", + flg_auto_approve=True, + flg_available=True, + description="", ) try: cc_id = client.get( @@ -269,18 +262,15 @@ def create_condition( cond_name = generate_unique_condition_name( detector_type, pdu_name, pdu_uuid, cond_params) - # Add the missing parameter_id value in `ParameterConditionAttribute`s. - for param, cond in cond_params.items(): - cond.parameter_id = client.parameter_by_name(param)['id'] - cond_params[param] = asdict(cond) - # Create condition table in database, if not available. cond = dict( name=cond_name, - parameters_conditions_attributes=list(cond_params.values()), - flg_available = 'true', - event_at = str(datetime.today()), # TODO: Why is this needed? it is not written in swagger. - description = '', + parameters_conditions_attributes=[ + asdict(cond) | {"parameter_name": db_name} + for (db_name, cond) in cond_params.items() + ], + flg_available=True, + description='', ) resp = client.post( "conditions/set_expected_condition", {"condition": cond} @@ -364,9 +354,9 @@ def inject_ccv(const_src, ccv_root, report_to=None, client=None): if report_to: report_path = Path(report_to).absolute().with_suffix('.pdf') resp = client.post("reports/set", dict( - name=report_path.stem, + name=report_path.name, file_path=str(report_path), - flg_available='true', + flg_available=True, description="", )) report_id = resp['id'] @@ -375,7 +365,7 @@ def inject_ccv(const_src, ccv_root, report_to=None, client=None): pdu_id = client.pdu_by_name(pdu_name)['id'] # Prepare CCV data and inject it to CALCAT. - start_idx = '0' + start_idx = 0 ccv = dict( name=create_unique_ccv_name(start_idx), file_name=const_filename, @@ -389,10 +379,10 @@ def inject_ccv(const_src, ccv_root, report_to=None, client=None): end_validity_at='', begin_at=begin_at, start_idx=start_idx, - end_idx = '0', - flg_deployed = 'true', - flg_good_quality = 'true', - description = '', + end_idx=0, + flg_deployed=True, + flg_good_quality=True, + description='', ) try: client.post("calibration_constant_versions", ccv)