]> rtime.felk.cvut.cz Git - hubacji1/iamcar2.git/commitdiff
Use compute statistics function
authorJiri Vlasak <hubacji1@fel.cvut.cz>
Tue, 8 Oct 2019 07:34:37 +0000 (09:34 +0200)
committerJiri Vlasak <hubacji1@fel.cvut.cz>
Tue, 8 Oct 2019 08:18:00 +0000 (10:18 +0200)
scripts/print_json_objects_scenaris_statistics.py

index 4eb9c007a5505c62f17409aceeef7e38631ea6d6..897150e34be2cc01a0612b4b82f8e56420c3eef5 100644 (file)
@@ -119,39 +119,17 @@ if __name__ == "__main__":
     ))
     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)
+        tl = compute_stats(sl, "time")
+        cl = compute_stats(sl, "cost")
         print(gos().format(
-                100 * (len(sl) - len(tl)) / len(sl),
+                tl["err"],
                 f,
-                tl_max,
-                tl_min,
-                tl_mean,
-                tl_std,
-                cl_max,
-                cl_min,
-                cl_mean,
-                cl_std,
+                tl["max"],
+                tl["min"],
+                tl["mean"],
+                tl["std"],
+                cl["max"],
+                cl["min"],
+                cl["mean"],
+                cl["std"],
         ))