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: ...@@ -68,9 +68,10 @@ class MeasureSet:
def __init__(self): def __init__(self):
self.board = "Emerald" self.metadata = {}
self.linux_version = "4.19" self.metadata['board'] = "Emerald"
self.boot_params = "isolcpus" self.metadata['linux_version'] = "4.19"
self.metadata['boot_params'] = "isolcpus"
self.cols = {} self.cols = {}
self.interval = 0 self.interval = 0
...@@ -86,13 +87,14 @@ class MeasureSet: ...@@ -86,13 +87,14 @@ class MeasureSet:
self.linux_version = linux_version self.linux_version = linux_version
self.boot_params = boot_params 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.measure_type = measure_type
self.cols = cols self.cols = cols
self.col_names = col_names self.col_names = col_names
self.interval = interval self.interval = interval
self.units = units self.units = units
self.metadata.update(metadata)
self.max = [max(col) for col in cols] self.max = [max(col) for col in cols]
self.min = [min(col) for col in cols] self.min = [min(col) for col in cols]
...@@ -102,7 +104,7 @@ class MeasureSet: ...@@ -102,7 +104,7 @@ class MeasureSet:
def export_to_json(self, path): def export_to_json(self, path):
with open(path, 'w') as outfile: 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): def import_from_json(self, path, flat):
...@@ -113,6 +115,7 @@ class MeasureSet: ...@@ -113,6 +115,7 @@ class MeasureSet:
interval = data['interval'] interval = data['interval']
col_names = data['col_names'] col_names = data['col_names']
units = data['units'] units = data['units']
metadata = data['metadata']
if flat: if flat:
...@@ -127,31 +130,52 @@ class MeasureSet: ...@@ -127,31 +130,52 @@ class MeasureSet:
else: else:
cols = data['cols'] 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): def generate_graph(self, path):
pass pass
def generate_table(self): def generate_table(self, headers=True, values=True, metadata_mask={}):
m = [self.min, if headers == False and values == False:
self.max, return ""
self.avg,
self.var]
headers = ["Min", "Max", "Avg", "Var"] table = []
values = [[ (format(m[i][j], '.4f') + self.units[j]) for j in range(len(m[0]))] for i in range(len(m))]
table = [headers] if headers:
table += [["**" + " - ".join(self.col_names) + "**"] * len(headers)]
table += [[" - ".join(values[i]) for i in range(len(values))]] 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]))] 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 = [[ 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 = ""
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:]]) 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 return table_str
...@@ -177,7 +201,7 @@ def parse(): ...@@ -177,7 +201,7 @@ def parse():
elif args.t is not None and args.t != "input_file": elif args.t is not None and args.t != "input_file":
measure_set = ms_handler.get_measure_set(args.t) 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: if args.remove_all:
confirm = input("Are you sure all measure sets should be removed ? [Yes] / [No]: ") 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