1 """Procedures for loading, parsing, and processing JSON scenarios.
3 The structure of input directory (``dname``) must be the
16 from json import loads
17 from os import listdir
22 """Load scenario from file.
28 raise ValueError("File name as argument needed")
29 with open(fname, "r") as f:
31 scenario = loads(f.read())
33 scenario = {"error": "Bad JSON format."}
36 def load_dir(dname=DNAME):
37 """Load scenarios from directory.
40 dname -- Directory name.
43 raise ValueError("Directory name as argument needed")
45 for d in listdir(dname):
46 for f in listdir("{}/{}".format(dname, d)):
47 s = load("{}/{}/{}".format(dname, d, f))
50 s["fname"] = f.split(".")[0]
54 def grep_all(what="time"):
55 """Return the dictionary of ``fname``'s and corresponding list of values.
57 If ``what`` not present, use ``-1`` instead.
60 what -- What to filter.
63 scenarios = load_dir(DNAME)
65 if s["fname"] not in filtered:
66 filtered[s["fname"]] = []
68 filtered[s["fname"]].append(s[what])
70 filtered[s["fname"]].append(-1)
73 def grep(what="time"):
74 """Return the dictionary of ``fname``'s and corresponding list of values.
77 what -- What to filter.
80 scenarios = load_dir(DNAME)
82 if s["fname"] not in filtered:
83 filtered[s["fname"]] = []
85 filtered[s["fname"]].append(s[what])