]> rtime.felk.cvut.cz Git - hubacji1/iamcar2.git/commitdiff
Add sort dictionary decorator
authorJiri Vlasak <hubacji1@fel.cvut.cz>
Thu, 13 Feb 2020 11:33:15 +0000 (12:33 +0100)
committerJiri Vlasak <hubacji1@fel.cvut.cz>
Fri, 14 Feb 2020 11:39:14 +0000 (12:39 +0100)
scripts/scenario.py

index 342708e49e5f4d415d3d8a633f9ad29ee3efae0b..4e36cf854d21486e5e60b6ca9732d93540b9e1a9 100644 (file)
@@ -18,6 +18,14 @@ from os import listdir
 
 DNAME = "out"
 
+def sort_dict(f):
+    """Sort dict returned by ``f``."""
+    def w(*args, **kwargs):
+        d = f(*args, **kwargs)
+        d = {k: v for k, v in sorted(d.items(), key=lambda i: i[0])}
+        return d
+    return w
+
 def load(fname):
     """Load scenario from file.
 
@@ -51,6 +59,7 @@ def load_dir(dname=DNAME):
             scenarios.append(s)
     return scenarios
 
+@sort_dict
 def grep_all(what="time"):
     """Return the dictionary of ``fname``'s and corresponding list of values.
 
@@ -70,6 +79,7 @@ def grep_all(what="time"):
             filtered[s["fname"]].append(-1)
     return filtered
 
+@sort_dict
 def grep(what="time"):
     """Return the dictionary of ``fname``'s and corresponding list of values.