summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirte Kristina Friesel <birte.friesel@uos.de>2024-03-08 10:52:59 +0100
committerBirte Kristina Friesel <birte.friesel@uos.de>2024-03-08 10:52:59 +0100
commitf14522292b4952456dbcf7aeaa2d33b78dc3c953 (patch)
treef2fd606fe1ca98b709544ebba0e81c53ef75fe73
parentb09b01fe74eeb446fb14f4449f927cf6130cf1db (diff)
Add CSV support; right now hard-coded for kaggle acher linux-kernel-size
-rwxr-xr-xbin/analyze-log.py9
-rw-r--r--lib/utils.py25
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