Skip to content

Commit

Permalink
Merge pull request #89 from Snailed/dev
Browse files Browse the repository at this point in the history
Fix double-counting of log statements in parser
  • Loading branch information
Snailed authored Nov 18, 2024
2 parents 679ceb0 + afb4d76 commit 7eddb8d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 7 additions & 6 deletions carbontracker/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]})

0 comments on commit 7eddb8d

Please sign in to comment.