From ee593a488ca89fe4a6abc476457b8f083b302b32 Mon Sep 17 00:00:00 2001 From: noopur Date: Wed, 18 Dec 2024 10:00:41 +0000 Subject: [PATCH] Corrected summary logic Signed-off-by: noopur --- tests/end_to_end/utils/summary_helper.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/end_to_end/utils/summary_helper.py b/tests/end_to_end/utils/summary_helper.py index 6237981ded..36f431a8d7 100644 --- a/tests/end_to_end/utils/summary_helper.py +++ b/tests/end_to_end/utils/summary_helper.py @@ -44,16 +44,16 @@ def get_aggregated_accuracy(agg_log_file): 0.15911591053009033, 'round': 0} """ try: - with open(agg_log_file, "r") as file: - lines = file.readlines() - for line in lines: - match = re.search( - r"'metric_origin': 'aggregator', 'task_name': 'aggregated_model_validation', 'metric_name': 'accuracy', 'metric_value':\s*([\d.]+)", - line, - ) - if match: - agg_accuracy = float(match.group(1)) - break + with open(agg_log_file, 'r') as f: + for line in f: + if "'metric_origin': 'aggregator'" in line and "aggregated_model_validation" in line: + # In Python versions < 3.11, aggregator.py file name appears in the line + # whereas in Python version 3.11, it is utils.py + line = line.split("aggregator.py:")[0].strip() + line = line.split("utils.py:")[0].strip() + # If the line does not contain closing bracket "}", then concatenate the next line + reqd_line = line if "}" in line else line + next(f).strip() + agg_accuracy = eval(reqd_line.split("METRIC")[1].strip('"'))["metric_value"] except Exception as e: # Do not fail the test if the accuracy cannot be fetched print(f"Error while reading aggregator log file: {e}")