-
Notifications
You must be signed in to change notification settings - Fork 18
/
tlm_json_parser.py
98 lines (77 loc) · 2.84 KB
/
tlm_json_parser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# GSC-19165-1, "The On-Board Artificial Intelligence Research (OnAIR) Platform"
#
# Copyright © 2023 United States Government as represented by the Administrator of
# the National Aeronautics and Space Administration. No copyright is claimed in the
# United States under Title 17, U.S. Code. All Other Rights Reserved.
#
# Licensed under the NASA Open Source Agreement version 1.3
# See "NOSA GSC-19165-1 OnAIR.pdf"
import ast
import json
# parse tlm config json file
def parseTlmConfJson(file_path):
data = parseJson(file_path)
reorg_data = reorganizeTlmDict(data)
labels = []
subsys_assignments = []
mnemonic_tests = []
descriptions = []
for label in reorg_data:
curr_datapt = reorg_data[label]
subsys = curr_datapt["subsystem"]
tests = curr_datapt["tests"] if "tests" in curr_datapt else {}
if tests == {}:
mnemonics = [["NOOP"]]
else:
mnemonics = []
for key in tests:
mnemonics.append([key, curr_datapt["tests"][key]])
desc = (
curr_datapt["description"]
if "description" in curr_datapt
else ["No description"]
)
labels.append(label)
subsys_assignments.append(subsys)
mnemonic_tests.append(mnemonics)
descriptions.append(desc)
# if given an order, reorder data to match
if "order" in data and data["order"] != []:
original_order = {}
for i in range(len(data["order"])):
original_order[data["order"][i]] = i
ordering_list = []
for label in labels:
ordering_list.append(original_order[label])
labels = [y for x, y in sorted(zip(ordering_list, labels))]
subsys_assignments = [
y for x, y in sorted(zip(ordering_list, subsys_assignments))
]
mnemonic_tests = [y for x, y in sorted(zip(ordering_list, mnemonic_tests))]
descriptions = [y for x, y in sorted(zip(ordering_list, descriptions))]
configs = {}
configs["subsystem_assignments"] = subsys_assignments
configs["test_assignments"] = mnemonic_tests
configs["description_assignments"] = descriptions
configs["data_labels"] = labels
return configs
# process tlm dict into dict of labels and their attributes
def reorganizeTlmDict(data):
processed_data = {}
for s in data["subsystems"]:
for label in data["subsystems"][s]:
processed_data[label] = data["subsystems"][s][label]
processed_data[label]["subsystem"] = s
return processed_data
def str2lst(string):
try:
return ast.literal_eval(string)
except:
print("Unable to process string representation of list")
# return string
def parseJson(path):
file = open(path, "rb")
file_str = file.read()
data = json.loads(file_str)
file.close()
return data