Commit 68ae81be authored by Joanne Hugé's avatar Joanne Hugé

Add options to the measure analysis script

parent 2c34b5e5
......@@ -17,14 +17,21 @@ class MeasureSetHandler:
self.measure_sets = json.load(measure_sets_file)
def __str__(self):
s = "List of measures:\n\n"
for measure_set in self.measure_sets:
print("List of measures:\n\n")
print(" " + measure_set)
s += " {} : {}".format(measure_set, self.measure_sets[measure_set])
return s
def save(self):
with open(MeasureSetHandler.measure_sets_path, 'w') as measure_sets_file:
json.dump(self.measure_sets, measure_sets_file)
def get_measure_set(self, measure_name):
measure_set = MeasureSet()
measure_path = "{}/{}".format(self.measures_dir, measure_name)
measure_set.import_from_json(measure_path, False)
return measure_set
def add_measure_set(self, measure_set):
mtype = measure_set.measure_type
......@@ -41,6 +48,8 @@ class MeasureSetHandler:
self.save()
print("Saved measure as {}{}".format(mtype, next_id))
def remove_measure_set(self, mtype, mid):
if mtype in self.measure_sets and len(self.measure_sets[mtype]['ids']) > 0:
......@@ -103,11 +112,12 @@ class MeasureSet:
measure_type = data['measure_type']
interval = data['interval']
col_names = data['col_names']
values = data['values']
units = data['units']
if flat:
values = data['values']
nb_cols = len(col_names)
cols = [[] for c in range(nb_cols)]
......@@ -129,11 +139,12 @@ class MeasureSet:
self.avg,
self.var]
headers = ["Name", "Min", "Max", "Avg", "Var"]
values = [[ (format(m[j][i], '.4f') + self.units[i]) for j in range(len(m))] for i in range(len(m[0]))]
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 = [headers]
table += [([("*" + self.col_names[i] + "*")] + values[i]) for i in range(len(values))]
table += [["**" + " - ".join(self.col_names) + "**"] * len(headers)]
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))]
......@@ -149,20 +160,31 @@ def parse():
parser = argparse.ArgumentParser(description='Measure analysis')
parser.add_argument('-i', nargs=1, required=False, help='import file')
parser.add_argument('--remove_all', action='store_true', help='remove all measure sets')
parser.add_argument('-t', action='store_true', help='generate table')
parser.add_argument('-t', nargs='?', const='input_file', required=False, help='generate table')
parser.add_argument('-s', action='store_true', help='show measures')
args = parser.parse_args()
ms_handler = MeasureSetHandler()
if args.i is not None:
measure_set = MeasureSet()
measure_set.import_from_json(args.i[0], True)
ms_handler.add_measure_set(measure_set)
if args.t is not None:
print(measure_set.generate_table())
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())
if args.remove_all:
confirm = input("Are you sure all measure sets should be removed ? [Yes] / [No]: ")
if confirm == "Yes":
ms_handler.remove_all()
if args.i is not None:
measure_set = MeasureSet()
measure_set.import_from_json(args.i[0], True)
ms_handler.add_measure_set(measure_set)
if args.s:
print( ms_handler)
parse()
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