Commit f13dc492 authored by Joanne Hugé's avatar Joanne Hugé

Add header, value and metadata option to generate_table

parent 68ae81be
......@@ -68,9 +68,10 @@ class MeasureSet:
def __init__(self):
self.board = "Emerald"
self.linux_version = "4.19"
self.boot_params = "isolcpus"
self.metadata = {}
self.metadata['board'] = "Emerald"
self.metadata['linux_version'] = "4.19"
self.metadata['boot_params'] = "isolcpus"
self.cols = {}
self.interval = 0
......@@ -86,13 +87,14 @@ class MeasureSet:
self.linux_version = linux_version
self.boot_params = boot_params
def add_results(self, measure_type, interval, col_names, units, cols):
def add_results(self, measure_type, interval, col_names, units, cols, metadata):
self.measure_type = measure_type
self.cols = cols
self.col_names = col_names
self.interval = interval
self.units = units
self.metadata.update(metadata)
self.max = [max(col) for col in cols]
self.min = [min(col) for col in cols]
......@@ -102,7 +104,7 @@ class MeasureSet:
def export_to_json(self, path):
with open(path, 'w') as outfile:
json.dump({'measure_type': self.measure_type, 'interval': self.interval, 'col_names': self.col_names, 'units': self.units, 'cols': self.cols}, outfile)
json.dump({'measure_type': self.measure_type, 'interval': self.interval, 'col_names': self.col_names, 'units': self.units, 'cols': self.cols, 'metadata': self.metadata}, outfile)
def import_from_json(self, path, flat):
......@@ -113,6 +115,7 @@ class MeasureSet:
interval = data['interval']
col_names = data['col_names']
units = data['units']
metadata = data['metadata']
if flat:
......@@ -127,31 +130,52 @@ class MeasureSet:
else:
cols = data['cols']
self.add_results(measure_type, interval, col_names, units, cols)
self.add_results(measure_type, interval, col_names, units, cols, metadata)
def generate_graph(self, path):
pass
def generate_table(self):
def generate_table(self, headers=True, values=True, metadata_mask={}):
m = [self.min,
self.max,
self.avg,
self.var]
if headers == False and values == False:
return ""
headers = ["Min", "Max", "Avg", "Var"]
values = [[ (format(m[i][j], '.4f') + self.units[j]) for j in range(len(m[0]))] for i in range(len(m))]
table = []
table = [headers]
table += [["**" + " - ".join(self.col_names) + "**"] * len(headers)]
table += [[" - ".join(values[i]) for i in range(len(values))]]
if headers:
headers = ["Min", "Max", "Avg", "Var"]
if metadata_mask != {}:
table += [["Metadata"] + headers]
table += [["**" + ", ".join(metadata_mask) + "**"] + ["**" + " - ".join(self.col_names) + "**"] * len(headers)]
else:
table += [headers]
table += [["**" + " - ".join(self.col_names) + "**"] * len(headers)]
if values:
m = [self.min, self.max, self.avg, self.var]
values = [[ (format(m[i][j], '.4f') + self.units[j]) for j in range(len(m[0]))] for i in range(len(m))]
if metadata_mask != {}:
metadata_info = ["{}".format(self.metadata[metadata_name]) for metadata_name in metadata_mask]
table += [[", ".join(metadata_info)] + [" - ".join(values[i]) for i in range(len(values))]]
else:
table += [[" - ".join(values[i]) for i in range(len(values))]]
col_lens = [max([len(table[i][j]) for i in range(len(table))]) for j in range(len(table[0]))]
table = [[ table[i][j].ljust(col_lens[j]) for j in range(len(table[0]))] for i in range(len(table))]
table_str = " | ".join(table[0]) + "\n"
table_str += " | ".join([ ("-" * col_lens[i]) for i in range(len(col_lens)) ]) + "\n"
table_str += "\n".join([" | ".join(line) for line in table[1:]])
table_str = ""
if headers:
table_str += " | ".join(table[0]) + "\n"
table_str += " | ".join([ ("-" * col_lens[i]) for i in range(len(col_lens)) ]) + "\n"
if values:
table_str += "\n".join([" | ".join(line) for line in table[1:]])
else:
table_str += "\n".join([" | ".join(line) for line in table])
return table_str
......@@ -177,7 +201,7 @@ def parse():
elif args.t is not None and args.t != "input_file":
measure_set = ms_handler.get_measure_set(args.t)
print(measure_set.generate_table())
print(measure_set.generate_table(True, True, {'board', 'linux_version', 'boot_params'}))
if args.remove_all:
confirm = input("Are you sure all measure sets should be removed ? [Yes] / [No]: ")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment