Skip to content

Commit

Permalink
Merge pull request #684 from rfbgo/json_order
Browse files Browse the repository at this point in the history
Update json output ordering
  • Loading branch information
douglasjacobsen authored Oct 4, 2024
2 parents 6f9efe7 + 8de116a commit bf1fb26
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions lib/ramble/ramble/experiment_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
from ramble.namespace import namespace


_DICT_MAPPING = {
_OUTPUT_MAPPING = {
"name": "name",
"status": "RAMBLE_STATUS",
"experiment_chain": "EXPERIMENT_CHAIN",
namespace.n_repeats: "N_REPEATS",
namespace.tags: "TAGS",
"keys": "keys",
"contexts": "CONTEXTS",
namespace.variables: "RAMBLE_VARIABLES",
"raw_variables": "RAMBLE_RAW_VARIABLES",
"contexts": "CONTEXTS",
namespace.tags: "TAGS",
"experiment_chain": "EXPERIMENT_CHAIN",
}


Expand Down Expand Up @@ -54,13 +55,18 @@ def to_dict(self):
"""
import copy

output = {}
obj_keys = {}

obj_dict = copy.deepcopy(self.__dict__)

if "keys" in obj_dict:
res = obj_dict["keys"]
else:
res = {}
for name, val in obj_dict.items():
if name in _DICT_MAPPING:
res[_DICT_MAPPING[name]] = val
obj_keys = obj_dict["keys"]

for lookup_key, output_val in _OUTPUT_MAPPING.items():
if lookup_key == "keys":
output.update(obj_keys)
else:
output[output_val] = obj_dict[lookup_key]

return res
return output

0 comments on commit bf1fb26

Please sign in to comment.