diff options
author | Birte Kristina Friesel <birte.friesel@uos.de> | 2024-03-08 10:52:59 +0100 |
---|---|---|
committer | Birte Kristina Friesel <birte.friesel@uos.de> | 2024-03-08 10:52:59 +0100 |
commit | f14522292b4952456dbcf7aeaa2d33b78dc3c953 (patch) | |
tree | f2fd606fe1ca98b709544ebba0e81c53ef75fe73 | |
parent | b09b01fe74eeb446fb14f4449f927cf6130cf1db (diff) |
Add CSV support; right now hard-coded for kaggle acher linux-kernel-size
-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 |