Skip to content

Commit

Permalink
simplified read timestamp, removed regex
Browse files Browse the repository at this point in the history
simplified read timestamp to use datetime to check validity instead of regex
  • Loading branch information
anish-mudaraddi committed Mar 29, 2023
1 parent 8cbdfbf commit 7ec7de3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion cloud-energy-collection/iriscasttools/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ pytest
psutil
pylint
pre-commit
argparse
argparse
datetime
15 changes: 12 additions & 3 deletions cloud-energy-collection/iriscasttools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import re
from typing import Dict
import logging
import datetime

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -142,14 +143,22 @@ def get_ipmi_power_stats(*args):

if stat in power_stats.keys():
if stat == "time_stamp":
stat_val = re.search(
r"\d{2}/\d{2}/\d{4}\s-\s\d{2}:\d{2}:\d{2}", raw_val
).group(0)
try:
datetime.datetime.strptime(raw_val, "%m/%d/%Y - %H:%M:%S")
stat_val = raw_val
except ValueError as read_date_err:
logger.error(
"could not read timestamp given by ipmi %s: %s",
raw_val,
repr(read_date_err),
)
stat_val = ""

elif stat == "power_measurement":
stat_val = raw_val

else:
# get integer part only. Power in Watts seems to always be whole number
stat_val = re.search("[0-9]+", raw_val).group(0)

power_stats[stat] = stat_val
Expand Down

0 comments on commit 7ec7de3

Please sign in to comment.