Skip to content
Draft
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
14 changes: 14 additions & 0 deletions rct229/rulesets/ashrae9012022/data/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import glob
import json
from os.path import basename, dirname, join

# A dictionary that will contain all the data in this folder
data = {}

# Get a list of the JSON file names in this folder
_json_paths = glob.glob(join(dirname(__file__), "*.json"))

# Import each JSON file and store the contents in data
for json_path in _json_paths:
with open(json_path) as file:
data[basename(json_path)[:-5]] = json.load(file)
148 changes: 148 additions & 0 deletions rct229/rulesets/ashrae9012022/data/ashrae_90_1_table_J_6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
{
"performance_curve_coefficient": [
{
"Set": "V",
"EIR-f-T": [
2.044998,
-0.047515,
0.000505,
-0.008787,
0.000175,
-0.00012
],
"CAP-f-T": [
-0.981909,
0.076674,
-0.000687,
0.00392,
-0.000058,
0.000006
],
"EIR-f-PLR": [
0.276037,
0.253577,
0.466353
]
},
{
"Set": "X",
"EIR-f-T": [
1.037805,
-0.024695,
0.000329,
0.00313,
0.000102,
-0.000159
],
"CAP-f-T": [
-0.683858,
0.065283,
-0.000602,
0.002347,
-0.00005,
0.000036
],
"EIR-f-PLR": [
0.250801,
0.345915,
0.399138
]
},
{
"Set": "Y",
"EIR-f-T": [
1.188945,
-0.039426,
0.000413,
0.012888,
0.000002,
-0.000098
],
"CAP-f-T": [
-0.160681,
0.04439,
-0.000429,
0.001024,
-0.000035,
0.000055
],
"EIR-f-PLR": [
0.320097,
0.074356,
0.602938
]
},
{
"Set": "Z",
"EIR-f-T": [
0.857485,
-0.036148,
0.000314,
0.022356,
-0.000108,
0.000001
],
"CAP-f-T": [
-0.061958,
0.054739,
-0.00055,
-0.008177,
0.000005,
0.000101
],
"EIR-f-PLR": [
0.281669,
0.202762,
0.515409
]
},
{
"Set": "AA",
"EIR-f-T": [
0.479847,
-0.035964,
0.000225,
0.031377,
-0.000183,
0.000085
],
"CAP-f-T": [
-0.128081,
0.050459,
-0.000581,
-0.004297,
-0.000049,
0.0002
],
"EIR-f-PLR": [
0.339494,
0.04909,
0.611582
]
},
{
"Set": "AB",
"EIR-f-T": [
0.74721,
-0.038874,
0.000313,
0.027638,
-0.000133,
-0.000008
],
"CAP-f-T": [
0.117208,
0.04294,
-0.000478,
-0.00393,
-0.000045,
0.000155
],
"EIR-f-PLR": [
0.309752,
0.153649,
0.536462
]
}
]
}
33 changes: 33 additions & 0 deletions rct229/rulesets/ashrae9012022/data_fns/table_J_6_fns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from rct229.rulesets.ashrae9012022.data import data
from rct229.rulesets.ashrae9012022.data_fns.table_utils import find_osstd_table_entry


def table_J_6_lookup(Set: str, output_variable: str) -> list[float]:
"""Returns the performance curve coefficients as specified in ASHRAE 90.1 Table J-6

Parameters
----------
Set : str
One of the set specified in Table J-6 ("V", "X", "Y", "Z", "AA", "AB")
output_variable: str
One of the performance curve types ("EIR-f-T", "CAP-f-T", "EIR-f_PLR")

Returns
-------
list of floats

"""

if Set not in ("V", "X", "Y", "Z", "AA", "AB"):
return None

if output_variable not in ("EIR-f-T", "CAP-f-T", "EIR-f-PLR"):
return None

osstd_entry = find_osstd_table_entry(
[("Set", Set)],
osstd_table=data["ashrae_90_1_table_J_6"],
)
performance_coefficient = osstd_entry[output_variable]

return performance_coefficient
29 changes: 29 additions & 0 deletions rct229/rulesets/ashrae9012022/data_fns/table_J_6_fns_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from rct229.rulesets.ashrae9012022.data_fns.table_J_6_fns import (
table_J_6_lookup,
)


def test__table_J_6_X_EIR_f_T():
assert table_J_6_lookup("X", "EIR-f-T") == [
1.037805,
-0.024695,
0.000329,
0.00313,
0.000102,
-0.000159,
]


def test__table_J_6_Y_CAP_f_T():
assert table_J_6_lookup("Y", "CAP-f-T") == [
-0.160681,
0.04439,
-0.000429,
0.001024,
-0.000035,
0.000055,
]


def test__table_J_6_AA_EIR_f_PLR():
assert table_J_6_lookup("AA", "EIR-f-PLR") == [0.339494, 0.04909, 0.611582]
161 changes: 161 additions & 0 deletions rct229/rulesets/ashrae9012022/data_fns/table_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
from rct229.schema.schema_enums import SchemaEnums


def find_osstd_table_entry(match_field_name_value_pairs, osstd_table):
"""Find a specific entry in an OSSTD table

This takes advantage of the consistent structure across all the OSSTD
JSON files. Each file contains a dictionary with a single key. The value
associated with that key is a list of dictionaries. This function searches
through those inner dictionaries to find one that matches all the
provided
match_field_name: match_field_value
pairs.

Parameters
----------
match_field_name_value_pairs : list of 2-tuples
List of (match_field_name, match_field_value) tuples
osstd_table : dict
The OSSTD table data as loaded from its JSON file

Returns
-------
dict
The matching table entry
"""
assert type(osstd_table) is dict

keys = list(osstd_table)
assert len(keys) == 1

data_list = osstd_table[keys[0]]
assert type(data_list) is list

matching_entries = list(
filter(
lambda entry: all(
[
entry[match_field_name] == match_field_value
for (
match_field_name,
match_field_value,
) in match_field_name_value_pairs
]
),
data_list,
)
)
assert (
len(matching_entries) == 1
), f"Not exactly one match in OSSTD for {match_field_name_value_pairs}, found {len(matching_entries)} instead."

matching_entry = matching_entries[0]
assert type(matching_entry) is dict

return matching_entries[0]


def find_osstd_table_entries(match_field_name_value_pairs, osstd_table: dict):
"""Find specific entries in an OSSTD table

This takes advantage of the consistent structure accross all the OSSTD
JSON files. Each file contains a dictionary with a single key. The value
associated with that key is a list of dictionaries. This function searches
through those inner dictionaries to find all entries that match all the
provided match_field_name_value_pairs

Parameters
----------
match_field_name_value_pairs : list of 2-tuples
List of (match_field_name, match_field_value) tuples
osstd_table : dict
The OSSTD table data as loaded from its JSON file

Returns
-------
list
The matching table entries
"""
assert type(osstd_table) is dict

keys = list(osstd_table)
assert len(keys) == 1

data_list = osstd_table[keys[0]]
assert type(data_list) is list

matching_entries = list(
filter(
lambda entry: all(
[
entry[match_field_name] == match_field_value
for (
match_field_name,
match_field_value,
) in match_field_name_value_pairs
]
),
data_list,
)
)

assert len(matching_entries) > 0, "No entries found in the table"

for matching_entry in matching_entries:
assert type(matching_entry) is dict

return matching_entries


def check_enumeration_to_osstd_match_field_value_map(
match_field_name,
enum_type,
osstd_table,
enumeration_to_match_field_value_map,
exclude_enum_names=[],
):
"""A sanity check for an enumeration to OSSTD match field value map

Checks that
1. Each enumerated value (except for those in exclude_enum_names) is a
key in the map
2. There is actually a matching entry in the underlying OSSTD table
corresponding to each enumated value

This function only applies to OSSTD tables that have a field name,
match_field_name, whose values are unique in the OSSTD table.

Parameters
----------
match_field_name : str
Field name for the OSSTD lookup
enum_type : str
The name of an enumeration from the ruleset
osstd_table : dict
An OSSTD table
enumeration_to_match_field_value_map : dict
The map to be checked
exclude_enum_names: list
A list of strings of the enumeration names to be excluded from the check
For example, "NONE" may be used as a flag that is not intended to be
looked up.

Returns
-------
dict
The matching table entry
"""
for e in SchemaEnums.schema_enums[enum_type].get_list():
if e in exclude_enum_names:
continue

# Make sure each space type in the enumeration is in our map
match_field_value = enumeration_to_match_field_value_map[e]
assert match_field_value is not None, f"{e} is not in the map"

# Make sure there is a corresponding entry in the OSSTD table
# find_osstd_table_entry() will throw if not
entry = find_osstd_table_entry(
[(match_field_name, match_field_value)], osstd_table
)
Loading
Loading