Skip to content

Commit

Permalink
Merge pull request #139 from EC-DIGIT-CSIRC/battery_bdc_logging
Browse files Browse the repository at this point in the history
chg: battery_bdc parser added logging
  • Loading branch information
dario-br authored Feb 5, 2025
2 parents 6e19540 + efe889e commit 3533e41
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/sysdiagnose/parsers/battery_bdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import glob
import os
from sysdiagnose.utils.base import BaseParserInterface
from sysdiagnose.utils.base import BaseParserInterface, logger
from datetime import datetime, timezone
import csv

Expand Down Expand Up @@ -36,6 +36,7 @@ def execute(self) -> list | dict:
result = []
log_files = self.get_log_files()
for log_file in log_files:
logger.debug(f"Processing {os.path.basename(log_file)}", extra={'log_file': log_file})
# load csv using csvdictreader and convert to json dict using the header
# the field 'TimeStamp' is in the format '2021-09-01 00:00:00'
# add a field that refers to the first part of the filename (before the timestamp)
Expand All @@ -53,6 +54,7 @@ def execute(self) -> list | dict:
elif 'set_system_time' in row:
timestamp = datetime.strptime(row['set_system_time'], '%Y-%m-%d %H:%M:%S %z')
else:
logger.error(f"No known timestamp field found in CSV file", extra={'header': str(row)})
raise ValueError('No known timestamp field found in CSV file')
row['datetime'] = timestamp.isoformat(timespec='microseconds')
row['timestamp'] = timestamp.timestamp()
Expand Down

0 comments on commit 3533e41

Please sign in to comment.