13 json_files: list, console: Console =
None, output_file: click.File =
None
15 """Collate the json information into an output file."""
16 if console
is not None and output_file
is not None:
18 f
"Reading specified JSON files and outputting collated value traces to {output_file.name}"
22 jd = json.JSONDecoder()
24 if console
is not None:
25 console.log(f
"Reading info JSON file {jf.name}")
31 if "pathlib.PosixPath" in str(type(jf)):
36 while idx < len(text):
37 res = jd.raw_decode(text, idx)
40 while idx < len(text)
and text[idx] !=
'{':
45 session = jsonobj[
"origin"][
"session"]
46 application = jsonobj[
"origin"][
"application"]
48 if session
not in data:
51 if application
not in data[session]:
52 data[session][application] = {}
54 objref = data[session][application]
55 if "substructure" in jsonobj[
"origin"]:
56 for sub
in jsonobj[
"origin"][
"substructure"]:
62 jsonobj[
"measurement"].replace(
"dunedaq.",
"").replace(
"opmon.",
"")
64 if measurement
not in objref:
65 objref[measurement] = {}
66 objref = objref[measurement]
69 if "custom_origin" in jsonobj:
71 for k, v
in jsonobj[
"custom_origin"].items():
74 custom_origin += f
"{k}:{v}"
77 if custom_origin !=
"":
78 if custom_origin
not in objref:
79 objref[custom_origin] = {}
80 objref = objref[custom_origin]
82 for datapoint
in jsonobj[
"data"]:
83 if datapoint
not in objref:
84 objref[datapoint] = {}
86 for value
in jsonobj[
"data"][datapoint]:
87 objref[datapoint][jsonobj[
"time"]] = jsonobj[
"data"][datapoint][value]
89 if output_file
is not None:
90 json.dump(data, output_file, indent=4, sort_keys=
True)
91 if console
is not None:
92 console.log(
"Operation complete")