]> rtime.felk.cvut.cz Git - hubacji1/iamcar2.git/blobdiff - scripts/scenario.py
Add greps -- grep multiple scenario values
[hubacji1/iamcar2.git] / scripts / scenario.py
index 62d798b5469b11b82eaa75b988598930c02766d0..acf8d137c8dabcd7f2edbb101e03a2b2e577b5ba 100644 (file)
@@ -110,6 +110,24 @@ def grep(what="time", grep_all=False):
             filtered[s["fname"]].append(-1)
     return filtered
 
+def greps(what="time", grep_all=False):
+    """Return the dictionary of ``fname``'s and corresponding list of values.
+
+    If ``what`` not present, use ``-1`` instead.
+
+    Keyword arguments:
+    what -- What to filter.
+    grep_all -- Add ``-1`` if ``what`` not in scenario.
+    """
+    filtered = {}
+    scenarios = load_multidir(DNAME)
+    for s in scenarios:
+        if s["fname"] not in filtered:
+            filtered[s["fname"]] = {}
+        if what in s:
+            filtered[s["fname"]][int(s["subdname"])] = s[what]
+    return filtered
+
 def error_rate():
     """Return the dictionary of ``fname``'s and corresponding error rates."""
     f = grep("cost", True)