1 """Print JSON formatted scenarios histograms.
3 The structure of input directory (``sys.argv[1]``) must be the
16 from json import loads
17 from math import cos, inf, pi, sin
18 from matplotlib import pyplot as plt
19 from numpy import histogram
20 from os import listdir
21 from sys import argv, exit
23 def get_scenario(fname):
24 """Load scenario from file.
30 raise ValueError("File name as argument needed")
31 with open(fname, "r") as f:
33 scenario = loads(f.read())
35 scenario = {"error": "Bad JSON format."}
38 def get_scenarios(dname):
39 """Load scenarios from directiory.
42 dname -- Directory name.
45 raise ValueError("Directory name as argument needed")
47 for d in listdir(dname):
48 for f in listdir("{}/{}".format(dname, d)):
55 "sc": get_scenario("{}/{}/{}".format(dname, d, f)),
59 def compute_stats(sl={}, what="time", **kwargs):
60 """Return histogram of ``what``.
64 what -- The variable in scenario stats to compute with.
65 **kwargs -- Keyword arguments for ``numpy.histogram``.
68 wl = [s["sc"][what] for s in sl if "sc" in s and what in s["sc"]]
69 return histogram(wl, **kwargs)
71 if __name__ == "__main__":
77 scenarios = get_scenarios(SCEN_DIR)
80 key=lambda kv: int(kv[0]) if kv[0].isnumeric() else kv[0]
93 for (f, sl) in scenarios:
94 assert f == sl[0]["fn"]
95 dirs.append(sl[0]["dn"])
96 files.append(sl[0]["fn"])
98 tmp_hist = compute_stats(sl, w)
99 delta = (tmp_hist[1][1] - tmp_hist[1][0]) / 2
103 in zip(tmp_hist[1][1:], tmp_hist[0])
105 assert len(dirs) == len(files)
106 tmp_dirs = list(dirs)
107 tmp_files = list(files)
120 h0 += "{:<%s}" % (int(len(files) * 32 / len(what) - 1))
122 h0 += "{:<%s}" % (int(len(files) * 32 / len(what)))
123 print(h0.format(*what))
131 print(h1.format(*dirs))
132 print(h2.format(*files))
135 data += "{:<16.2f}{:<16}"
136 assert len(histograms) > 0
137 bins = len(histograms[0])
138 for i in range(bins):
142 print(data.format(*val))