diff options
-rwxr-xr-x | bin/analyze-log.py | 9 | ||||
-rw-r--r-- | lib/utils.py | 25 |
2 files changed, 31 insertions, 3 deletions
diff --git a/bin/analyze-log.py b/bin/analyze-log.py index d6ae27a..1deb438 100755 --- a/bin/analyze-log.py +++ b/bin/analyze-log.py @@ -21,15 +21,18 @@ import time def parse_logfile(filename): - lf = dfatool.utils.Logfile() + if ".csv" in filename: + loader = dfatool.utils.CSVfile() + else: + loader = dfatool.utils.Logfile() if filename.endswith("xz"): import lzma with lzma.open(filename, "rt") as f: - return lf.load(f) + return loader.load(f) with open(filename, "r") as f: - return lf.load(f) + return loader.load(f) def main(): diff --git a/lib/utils.py b/lib/utils.py index af705b9..61cb6f1 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -33,6 +33,31 @@ class NpEncoder(json.JSONEncoder): return super(NpEncoder, self).default(obj) +class CSVfile: + def __init__(self): + pass + + def load(self, f): + observations = list() + for lineno, line in enumerate(f): + if lineno == 0: + param_names = line.split(",")[1:-1] + attr_names = line.removesuffix("\n").split(",")[-1:] + else: + param_values = list(map(soft_cast_int, line.split(",")[1:-1])) + attr_values = list( + map(soft_cast_float, line.removesuffix("\n").split(",")[-1:]) + ) + observations.append( + { + "name": "CSVFile", + "param": dict(zip(param_names, param_values)), + "attribute": dict(zip(attr_names, attr_values)), + } + ) + return observations + + class Logfile: def __init__(self): pass |