From 5e75e8ed97bca91817765473c3bd4b40a2d4fb72 Mon Sep 17 00:00:00 2001 From: "Xu, Weili" Date: Mon, 27 Jan 2025 10:55:54 -0800 Subject: [PATCH 1/4] add code to remove master json once it is processed. --- .../scripts/json_generation_utilities.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/rct229/ruletest_engine/ruletest_jsons/scripts/json_generation_utilities.py b/rct229/ruletest_engine/ruletest_jsons/scripts/json_generation_utilities.py index 04af6529b7..9fc5dedc7d 100644 --- a/rct229/ruletest_engine/ruletest_jsons/scripts/json_generation_utilities.py +++ b/rct229/ruletest_engine/ruletest_jsons/scripts/json_generation_utilities.py @@ -459,10 +459,19 @@ def disaggregate_master_ruletest_json(master_json_name, ruleset_doc): master_json_path = os.path.join( file_dir, "..", ruleset_doc, master_json_name ) # os.path.join(file_dir, "..", ruleset_doc, master_json_name) - - # Initialize master JSON dictionary - with open(master_json_path) as f: - master_dict = json.load(f) + master_dict = None + try: + # Check if the master JSON file exists + if not os.path.exists(master_json_path): + raise FileNotFoundError(f"File not found: {master_json_path}") + + # Initialize master JSON dictionary + with open(master_json_path) as f: + master_dict = json.load(f) + except FileNotFoundError as e: + print(f"Error: {e}") + except Exception as e: + print(f"An error occurred: {e}") # Initialize dictionary used to break out master dictionary into sections and rules rule_dictionary = {} @@ -521,6 +530,8 @@ def write_ruletest_json(section, rule, ruleset_doc): # Write out final rule dictionary write_ruletest_json(prev_section, prev_rule, ruleset_doc) + # Remove the master json file: + os.remove(master_json_path) def disaggregate_master_rmd_json(master_json_name, output_dir, ruleset_doc): From 7184d4b83cf7184a8b180451a46a54bee42e2729 Mon Sep 17 00:00:00 2001 From: "Xu, Weili" Date: Mon, 27 Jan 2025 11:03:12 -0800 Subject: [PATCH 2/4] remove any remaining master jsons in the build process. --- rct229/utils/minify_jsons.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/rct229/utils/minify_jsons.py b/rct229/utils/minify_jsons.py index 07d263d805..6b022bb3b0 100644 --- a/rct229/utils/minify_jsons.py +++ b/rct229/utils/minify_jsons.py @@ -13,14 +13,21 @@ def minify_json_file(file_path): ------- """ - try: - with open(file_path, "r") as f: - data = json.load(f) - with open(file_path, "w") as f: - json.dump(data, f, separators=(",", ":")) - print(f"Minified: {file_path}") - except Exception as e: - print(f"Failed to minify {file_path}: {e}") + # Step 1. If the json file name ends with _master, remove it + if file_path.endsWith("_master.json"): + try: + os.remove(file_path) + except Exception as e: + print(f"Could not remove {file_path}: {e}") + else: + try: + with open(file_path, "r") as f: + data = json.load(f) + with open(file_path, "w") as f: + json.dump(data, f, separators=(",", ":")) + print(f"Minified: {file_path}") + except Exception as e: + print(f"Failed to minify {file_path}: {e}") def recursively_minify_json_files(directory): @@ -44,11 +51,10 @@ def recursively_minify_json_files(directory): def main(): # Get the directory of the current script utils_directory = os.path.dirname(os.path.abspath(__file__)) - # Navigate up two levels to get to the `src` directory + # Navigate up two levels to get to the `rct229` directory project_directory = os.path.abspath( os.path.join(utils_directory, os.pardir, os.pardir) ) - # Start the minification process recursively_minify_json_files(project_directory) From 4c42085e8508c5c9991fc1e732fc08f65cec5394 Mon Sep 17 00:00:00 2001 From: "Xu, Weili" Date: Mon, 24 Feb 2025 11:06:11 -0800 Subject: [PATCH 3/4] remove the remove action of master jsons --- .../ruletest_jsons/scripts/json_generation_utilities.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/rct229/ruletest_engine/ruletest_jsons/scripts/json_generation_utilities.py b/rct229/ruletest_engine/ruletest_jsons/scripts/json_generation_utilities.py index 9fc5dedc7d..dcdecfa4ab 100644 --- a/rct229/ruletest_engine/ruletest_jsons/scripts/json_generation_utilities.py +++ b/rct229/ruletest_engine/ruletest_jsons/scripts/json_generation_utilities.py @@ -530,8 +530,6 @@ def write_ruletest_json(section, rule, ruleset_doc): # Write out final rule dictionary write_ruletest_json(prev_section, prev_rule, ruleset_doc) - # Remove the master json file: - os.remove(master_json_path) def disaggregate_master_rmd_json(master_json_name, output_dir, ruleset_doc): From 8c64fbabaddcc00f89ba3d34b361734b0469935e Mon Sep 17 00:00:00 2001 From: "Xu, Weili" Date: Tue, 25 Feb 2025 11:30:02 -0800 Subject: [PATCH 4/4] fix the extra schema updates --- .../ashrae9012019/data_fns/extra_schema_fns.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/rct229/rulesets/ashrae9012019/data_fns/extra_schema_fns.py b/rct229/rulesets/ashrae9012019/data_fns/extra_schema_fns.py index 89c20c697e..a9449e1950 100644 --- a/rct229/rulesets/ashrae9012019/data_fns/extra_schema_fns.py +++ b/rct229/rulesets/ashrae9012019/data_fns/extra_schema_fns.py @@ -49,9 +49,13 @@ def get_extra_schema_by_data_type(data_type): dict | str | None """ - if data_type.startswith("[") or data_type.startswith("{"): + if ( + data_type.startswith("[") + or data_type.startswith("{") + or data_type.startswith("(") + ): # this is a data group - data_type = "".join(re.findall(r"[\w\s]+", data_type)) + data_type = "".join(re.findall(r"\{([^}]+)\}", data_type)) if ( EXTRA_SCHEMA.get(data_type) and EXTRA_SCHEMA[data_type]["Object Type"] == "Data Group" @@ -108,6 +112,7 @@ def compare_context_pair( extra_schema_data_group = get_extra_schema_by_data_type( key_schema["Data Type"] ) + new_extra_schema = ( extra_schema_data_group if extra_schema_data_group @@ -178,9 +183,14 @@ def compare_context_pair( f"path: {element_json_path}: index context data: {index_context} does not equal to compare context data: {compare_context}" ) matched = False - else: - matched = False + # if the two index_context and compare_context are identical at this point, then it pass, otherwise it failed + if ( + type(index_context) != type(compare_context) + or index_context != compare_context + ): + # accomodating to mix reference and object type data - in this case, it is a string referenced. + matched = False return matched