33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
import csv
|
|
import pandas as pd
|
|
import os
|
|
|
|
class CsvLogger:
|
|
def __init__(self, outfile="log.csv"):
|
|
self.outfile = outfile
|
|
# self.init_logfile()
|
|
|
|
# def init_logfile(self):
|
|
# if not os.path.isfile(self.outfile.replace(".csv", ".avg.csv")):
|
|
# os.makedirs(self.outfile.replace(".csv", ".avg.csv"), exist_ok=True)
|
|
# if not os.path.isfile(self.outfile.replace(".csv", ".lang.avg.csv")):
|
|
# os.makedirs(self.outfile.replace(".csv", ".lang.csv"), exist_ok=True)
|
|
# return
|
|
|
|
def log_lang_results(self, results: dict, config="gfun-default", notes=None):
|
|
df = pd.DataFrame.from_dict(results, orient="columns")
|
|
df["config"] = config["gFun"]["simple_id"]
|
|
df["aggfunc"] = config["gFun"]["aggfunc"]
|
|
df["dataset"] = config["gFun"]["dataset"]
|
|
df["id"] = config["gFun"]["id"]
|
|
df["optimc"] = config["gFun"]["optimc"]
|
|
df["timing"] = config["gFun"]["timing"]
|
|
df["notes"] = notes
|
|
with open(self.outfile, 'a') as f:
|
|
df.to_csv(f, mode='a', header=f.tell()==0)
|
|
|
|
|
|
|
|
|
|
|