Skip to content

Commit

Permalink
Merge pull request #1665 from pnnl/remove_master_json_when_diaggregat…
Browse files Browse the repository at this point in the history
…e_json_tests

Remove master json when diaggregate json tests
  • Loading branch information
weilixu authored Feb 25, 2025
2 parents ef58a49 + 8c64fba commit 3e83e81
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 18 deletions.
18 changes: 14 additions & 4 deletions rct229/rulesets/ashrae9012019/data_fns/extra_schema_fns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
26 changes: 16 additions & 10 deletions rct229/utils/minify_jsons.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)

Expand Down

0 comments on commit 3e83e81

Please sign in to comment.