diff --git a/src/cal_tools/calcat_interface.py b/src/cal_tools/calcat_interface.py index cc5c6161b5926f3bbc34e1ea4529bf37e0db3432..6f903e8eeaccc2d2a33f82462f5fa7f3cf9f4892 100644 --- a/src/cal_tools/calcat_interface.py +++ b/src/cal_tools/calcat_interface.py @@ -712,48 +712,41 @@ class CalibrationData: from IPython.display import Markdown, display from tabulate import tabulate - def remove_timezone_seconds(timestamp): - """Remove timezone and seconds. - - Args: - timestamp (str): isoformat timestamp string. - - Returns: - str: timestamp after remove the timezone and seconds. - """ - # Parse the datetime and remove timezone and seconds. - dt = datetime.fromisoformat(timestamp).replace( - tzinfo=None, second=0, microsecond=0) - return dt.strftime("%Y-%m-%d %H:%M") - - mod_to_pdu = self.mod_to_pdu - if metadata is None: metadata = self.metadata() - num_groups = max(len(mod_to_pdu) // 4, 1) - for g in range(num_groups): - group_modules = list(mod_to_pdu)[4*g:4*(g+1)] - table = [["Constants"] + group_modules] + calibrations = set() + # Get all calibrations available in the metadata for all modules. + for c in list(metadata.values()): + calibrations |= c.keys() + + cal_groups = [ + list(calibrations)[x:x+4] for x in range(0, len(calibrations), 4)] + + # Loop over groups of calibrations. + for cal_group in cal_groups: + table = [["Modules"] + cal_group] # Loop over calibrations and modules to form the next rows. - for cname in self.calibrations: - constants = [] + for mod in list(self.mod_to_pdu): + mod_consts = [] - for mod in group_modules: + for cname in cal_group: c_mdata = metadata[mod].get(cname) # A calibration that is not available in given metadata. - if c_mdata is None: - continue - else: + if c_mdata is not None: # Have the creation time a reference # link to the CCV on CALCAT. - constants.append( - f"[{remove_timezone_seconds(c_mdata['begin_validity_at'])}]" # noqa - f"({ccvs_url}/{c_mdata['ccv_id']})") + c_time = datetime.fromisoformat( + c_mdata["begin_validity_at"]).strftime( + "%Y-%m-%d %H:%M") + mod_consts.append( + f"[{c_time}]({ccvs_url}/{c_mdata['ccv_id']})") + else: + # Constant is not available for this module. + mod_consts.append("___") - if any(constants): - table.append([cname] + constants) + table.append([mod] + mod_consts) display( Markdown(