Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove master json when diaggregate json tests #1665

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading