1 """Print JSON formatted scenarios statistics.
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 os import listdir
20 from sys import argv, exit
22 def get_scenario(fname):
23 """Load scenario from file.
29 raise ValueError("File name as argument needed")
30 with open(fname, "r") as f:
32 scenario = loads(f.read())
34 scenario = {"error": "Bad JSON format."}
37 def get_scenarios(dname):
38 """Load scenarios from directiory.
41 dname -- Directory name.
44 raise ValueError("Directory name as argument needed")
46 for d in listdir(dname):
47 for f in listdir("{}/{}".format(dname, d)):
54 "sc": get_scenario("{}/{}/{}".format(dname, d, f)),
58 def compute_stats(sl={}, what="time"):
59 """Return ``mean``, ``std``, ``med``, ``max``, and ``min`` of ``what``.
63 what -- The variable in scenario stats to compute with.
67 s["sc"][what] for s in sl
72 and s["sc"]["cost"] != 9999
79 and s["sc"]["cost"] != 9999
80 and s["sc"]["cost"] != -1
89 wl_mean = sum(wl) / len(wl)
90 wl_tmp = [(x - wl_mean)**2 for x in wl]
91 wl_std = (sum(wl_tmp) / len(wl_tmp))**0.5
95 wl_med = wl[round(len(wl) / 2)]
97 "err": 100 * (len(sl) - len(el)) / len(sl),
105 if __name__ == "__main__":
112 """Generate output string for values.
115 h -- String for header?
117 pr = "{:<16.2f}" if not h else "{:<16}"
122 for i in range(30): # 5 (from compute_stats) x 6 (stats in README)
123 pr += "{:<16.6f}" if not h else "{:<16}"
126 scenarios = get_scenarios(SCEN_DIR)
129 key=lambda kv: int(kv[0]) if kv[0].isnumeric() else kv[0]
131 print(gos(True).format(
132 "%--------------|", "---------------|", "---------------|",
133 "---------------|", "---------------|",
135 "----------------", "----------------",
137 "----------------", "---------------|",
139 "----------------", "----------------",
141 "----------------", "---------------|",
143 "----------------", "----------------",
145 "----------------", "---------------|",
147 "----------------", "----------------",
149 "----------------", "---------------|",
151 "----------------", "----------------",
152 "connecteds-in-pa", "th",
155 "----------------", "----------------",
157 "----------------", "---------------|",
159 print(gos(True).format(
160 "%err [%]", "planner", "filename",
162 "avg [s]", "std [s]", "med [s]", "max [s]", "min [s]", # time
163 "avg [-]", "std [-]", "med [-]", "max [-]", "min [-]", # iterations
164 "avg [m]", "std [m]", "med [m]", "max [m]", "min [m]", # cost
165 "avg [-]", "std [-]", "med [-]", "max [-]", "min [-]", # cusps-in-p
166 "avg [-]", "std [-]", "med [-]", "max [-]", "min [-]", # connecteds
167 "avg [-]", "std [-]", "med [-]", "max [-]", "min [-]", # nodes
170 for (f, sl) in scenarios:
171 assert f == sl[0]["fn"]
172 tl = compute_stats(sl, "time")
173 il = compute_stats(sl, "iterations")
174 cl = compute_stats(sl, "cost")
175 cul = compute_stats(sl, "cusps-in-path")
176 col = compute_stats(sl, "connecteds-in-path")
177 nl = compute_stats(sl, "nodes")
179 tl["err"], sl[0]["dn"][:15], sl[0]["fn"],
181 tl["avg"], tl["std"], tl["med"], tl["max"], tl["min"],
182 il["avg"], il["std"], il["med"], il["max"], il["min"],
183 cl["avg"], cl["std"], cl["med"], cl["max"], cl["min"],
184 cul["avg"], cul["std"], cul["med"], cul["max"], cul["min"],
185 col["avg"], col["std"], col["med"], col["max"], col["min"],
186 nl["avg"], nl["std"], nl["med"], nl["max"], nl["min"],