From 6671558c1cb1a0869a5338bc988cbd82e08a4931 Mon Sep 17 00:00:00 2001 From: ahmedk <karim.ahmed@xfel.eu> Date: Wed, 5 Jul 2023 10:48:36 +0200 Subject: [PATCH] Apply MR comments 1. Remove max line for guessing group numbers 2. Account for missing constants 3. Flip the table to show modules in rows. 4.remove unneeded remove timezone and seconds functions --- src/cal_tools/calcat_interface.py | 55 ++++++++++++++----------------- 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/src/cal_tools/calcat_interface.py b/src/cal_tools/calcat_interface.py index cc5c6161b..6f903e8ee 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( -- GitLab