]> rtime.felk.cvut.cz Git - hubacji1/iamcar2.git/blobdiff - scripts/print_json_objects_scenaris_statistics.py
Do not use unicode minus
[hubacji1/iamcar2.git] / scripts / print_json_objects_scenaris_statistics.py
index 27c5ffbca93dbaf8fc2e1b0534ad5a9efffe2981..96dd4c3e516e4bff89b861b78c60d23a07cb267f 100644 (file)
@@ -48,12 +48,60 @@ def get_scenarios(dname):
             if f not in s:
                 s[f] = []
             s[f].append({
+                "dn": dname,
                 "fn": f,
                 "cnt": int(d),
                 "sc": get_scenario("{}/{}/{}".format(dname, d, f)),
             })
     return s
 
+def compute_stats(sl={}, what="time"):
+    """Return ``mean``, ``std``, ``med``, ``max``, and ``min`` of ``what``.
+
+    Keyword arguments:
+    sl -- Scenarios list.
+    what -- The variable in scenario stats to compute with.
+    """
+    assert len(sl) > 0
+    wl = [
+        s["sc"][what] for s in sl
+        if "sc" in s
+        and what in s["sc"]
+        and (
+            "cost" in s["sc"]
+            and s["sc"]["cost"] != 9999
+        )
+    ]
+    el = [
+        1 for s in sl
+        if "sc" in s
+        and "cost" in s["sc"]
+        and s["sc"]["cost"] != 9999
+        and s["sc"]["cost"] != -1
+    ]
+    if len(wl) == 0:
+        wl_mean = inf
+        wl_std = inf
+        wl_max = inf
+        wl_min = -inf
+        wl_med = inf
+    else:
+        wl_mean = sum(wl) / len(wl)
+        wl_tmp = [(x - wl_mean)**2 for x in wl]
+        wl_std = (sum(wl_tmp) / len(wl_tmp))**0.5
+        wl_max = max(wl)
+        wl_min = min(wl)
+        wl.sort()
+        wl_med = wl[round(len(wl) / 2)]
+    return {
+        "err": 100 * (len(sl) - len(el)) / len(sl),
+        "avg": wl_mean,
+        "std": wl_std,
+        "med": wl_med,
+        "max": wl_max,
+        "min": wl_min,
+    }
+
 if __name__ == "__main__":
     if (len(argv) == 2):
         SCEN_DIR = argv[1]
@@ -66,10 +114,13 @@ if __name__ == "__main__":
         Keyword arguments:
         h -- String for header?
         """
-        pr = "{:<8.2f}" if not h else "{:<8}"
+        pr = "{:<16.2f}" if not h else "{:<16}"
+        pr += "{:<16}"
+        pr += "{:<16}"
+        pr += "{:<16}"
         pr += "{:<16}"
-        for i in range(8):
-            pr += " {:<16.6f}" if not h else " {:<16}"
+        for i in range(30): # 5 (from compute_stats) x 6 (stats in README)
+            pr += "{:<16.6f}" if not h else "{:<16}"
         return pr
 
     scenarios = get_scenarios(SCEN_DIR)
@@ -78,52 +129,59 @@ if __name__ == "__main__":
         key=lambda kv: int(kv[0]) if kv[0].isnumeric() else kv[0]
     )
     print(gos(True).format(
-            "%err [%]",
-            "filename",
-            "max [s]",
-            "min [s]",
-            "avg [s]",
-            "stddev [s]",
-            "max [m]",
-            "min [m]",
-            "avg [m]",
-            "stddev [m]",
+            "%--------------|", "---------------|", "---------------|",
+            "---------------|", "---------------|",
+
+            "----------------", "----------------",
+           "time",
+            "----------------", "---------------|",
+
+            "----------------", "----------------",
+            "iterations",
+            "----------------", "---------------|",
+
+            "----------------", "----------------",
+            "cost",
+            "----------------", "---------------|",
+
+            "----------------", "----------------",
+            "cusps-in-path",
+            "----------------", "---------------|",
+
+            "----------------", "----------------",
+            "connecteds-in-pa", "th",
+            "---------------|",
+
+            "----------------", "----------------",
+            "nodes",
+            "----------------", "---------------|",
+    ))
+    print(gos(True).format(
+            "%err [%]", "planner", "filename",
+            "-", "-",
+            "avg [s]", "std [s]", "med [s]", "max [s]", "min [s]", # time
+            "avg [-]", "std [-]", "med [-]", "max [-]", "min [-]", # iterations
+            "avg [m]", "std [m]", "med [m]", "max [m]", "min [m]", # cost
+            "avg [-]", "std [-]", "med [-]", "max [-]", "min [-]", # cusps-in-p
+            "avg [-]", "std [-]", "med [-]", "max [-]", "min [-]", # connecteds
+            "avg [-]", "std [-]", "med [-]", "max [-]", "min [-]", # nodes
     ))
     print()
     for (f, sl) in scenarios:
-        tl = [s["sc"]["time"] for s in sl if "sc" in s and "time" in s["sc"]]
-        if len(tl) == 0:
-            tl_mean = inf
-            tl_std = inf
-            tl_max = inf
-            tl_min = -inf
-        else:
-            tl_mean = sum(tl) / len(tl)
-            tl_tmp = [(x - tl_mean)**2 for x in tl]
-            tl_std = (sum(tl_tmp) / len(tl_tmp))**0.5
-            tl_max = max(tl)
-            tl_min = min(tl)
-        cl = [s["sc"]["cost"] for s in sl if "sc" in s and "cost" in s["sc"]]
-        if len(cl) == 0:
-            cl_mean = -inf
-            cl_std = inf
-            cl_max = inf
-            cl_min = -inf
-        else:
-            cl_mean = sum(cl) / len(cl)
-            cl_tmp = [(x - cl_mean)**2 for x in cl]
-            cl_std = (sum(cl_tmp) / len(cl_tmp))**0.5
-            cl_max = max(cl)
-            cl_min = min(cl)
+        assert f == sl[0]["fn"]
+        tl = compute_stats(sl, "time")
+        il = compute_stats(sl, "iterations")
+        cl = compute_stats(sl, "cost")
+        cul = compute_stats(sl, "cusps-in-path")
+        col = compute_stats(sl, "connecteds-in-path")
+        nl = compute_stats(sl, "nodes")
         print(gos().format(
-                100 * (len(sl) - len(tl)) / len(sl),
-                f,
-                tl_max,
-                tl_min,
-                tl_mean,
-                tl_std,
-                cl_max,
-                cl_min,
-                cl_mean,
-                cl_std,
+                tl["err"], sl[0]["dn"][:15], sl[0]["fn"],
+                "-", "-",
+                tl["avg"], tl["std"], tl["med"], tl["max"], tl["min"],
+                il["avg"], il["std"], il["med"], il["max"], il["min"],
+                cl["avg"], cl["std"], cl["med"], cl["max"], cl["min"],
+                cul["avg"], cul["std"], cul["med"], cul["max"], cul["min"],
+                col["avg"], col["std"], col["med"], col["max"], col["min"],
+                nl["avg"], nl["std"], nl["med"], nl["max"], nl["min"],
         ))