diff --git a/carbontracker/parser.py b/carbontracker/parser.py index 7db1dcd..817ef97 100644 --- a/carbontracker/parser.py +++ b/carbontracker/parser.py @@ -409,13 +409,14 @@ def get_avg_power_usages(std_log_data): for component in components: powers: list[list[float]] = [] for comp, power in matches: - if power == "None": - powers.append([0.0]) - continue if comp == component: - p_list = power.strip("[").strip("]").split(" ") - p_power = [float(num) for num in p_list if num != ""] - powers.append(p_power) + if power == "None": + powers.append([0.0]) + continue + else: + p_list = power.strip("[").strip("]").split(" ") + p_power = [float(num) for num in p_list if num != ""] + powers.append(p_power) avg_power_usages[component] = powers return avg_power_usages diff --git a/tests/test_parser.py b/tests/test_parser.py index e7cc29d..78187dd 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -992,3 +992,7 @@ def test_parse_epoch_mismatch( log_dir, "10151_2024-03-26T105926Z_carbontracker_output.log" ), ) + + def test_parse_logs_mismatch(self): + results = parser.get_avg_power_usages("2024-03-26 10:51:53 - Epoch 1:\n2024-03-26 10:51:53 - Duration: 0:00:00.00\n2024-03-26 10:51:53 - Average power usage (W) for cpu: None\n2024-03-26 10:51:53 - Average power usage (W) for gpu: None") + self.assertEqual(results, {"cpu": [[0.0]], "gpu": [[0.0]]}) \ No newline at end of file