From 8de116ac7502aa80b4dc8e8567b8172618d5daa9 Mon Sep 17 00:00:00 2001 From: Bob Bird Date: Fri, 4 Oct 2024 13:28:12 -0600 Subject: [PATCH] Update json output ordering --- lib/ramble/ramble/experiment_result.py | 28 ++++++++++++++++---------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/ramble/ramble/experiment_result.py b/lib/ramble/ramble/experiment_result.py index e8a8cb0cb..f707f3437 100644 --- a/lib/ramble/ramble/experiment_result.py +++ b/lib/ramble/ramble/experiment_result.py @@ -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", } @@ -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