|
| 1 | +from building_energy_standards_data.database_engine.database import DBOperation |
| 2 | +from building_energy_standards_data.database_engine.database_util import ( |
| 3 | + is_float, |
| 4 | + getattr_either, |
| 5 | +) |
| 6 | + |
| 7 | +RECORD_HELP = """ |
| 8 | +Must provide a tuple that contains: |
| 9 | +template: TEXT |
| 10 | +device: TEXT |
| 11 | +adjustment_in_wc: NUMERIC |
| 12 | +adjustment_in_wc_at_fan_system_design_conditions: TEXT |
| 13 | +adjustment_in_wc_2_times_at_fan_system_design_conditions: TEXT |
| 14 | +adjustment_in_wc_effectiveness_multiplier: NUMERIC |
| 15 | +adjustment_in_wc_per_100_ft_of_verticaul_duct_exceeding_75_ft: NUMERIC |
| 16 | +annotation: TEXT (optional) |
| 17 | +""" |
| 18 | + |
| 19 | +CREATE_SYSTEM_requirements_fan_power_allowance_pressure_drop_adjustment_TABLE = """ |
| 20 | +CREATE TABLE IF NOT EXISTS %s |
| 21 | +(id INTEGER PRIMARY KEY, |
| 22 | +template TEXT NOT NULL, |
| 23 | +device TEXT, |
| 24 | +adjustment_in_wc NUMERIC, |
| 25 | +adjustment_in_wc_at_fan_system_design_conditions TEXT, |
| 26 | +adjustment_in_wc_2_times_at_fan_system_design_conditions TEXT, |
| 27 | +adjustment_in_wc_effectiveness_multiplier NUMERIC, |
| 28 | +adjustment_in_wc_per_100_ft_of_verticaul_duct_exceeding_75_ft NUMERIC, |
| 29 | +annotation TEXT); |
| 30 | +""" |
| 31 | + |
| 32 | +INSERT_A_SYSTEM_requirements_fan_power_allowance_pressure_drop_adjustment_RECORD = """ |
| 33 | + INSERT INTO %s ( |
| 34 | +template, |
| 35 | +device, |
| 36 | +adjustment_in_wc, |
| 37 | +adjustment_in_wc_at_fan_system_design_conditions, |
| 38 | +adjustment_in_wc_2_times_at_fan_system_design_conditions, |
| 39 | +adjustment_in_wc_effectiveness_multiplier, |
| 40 | +adjustment_in_wc_per_100_ft_of_verticaul_duct_exceeding_75_ft, |
| 41 | +annotation |
| 42 | +) |
| 43 | +VALUES (?, ?, ?, ?, ?, ?, ?, ?); |
| 44 | +""" |
| 45 | + |
| 46 | +RECORD_TEMPLATE = { |
| 47 | + "template": "", |
| 48 | + "device": "", |
| 49 | + "adjustment_in_wc": 0.0, |
| 50 | + "adjustment_in_wc_at_fan_system_design_conditions": "", |
| 51 | + "adjustment_in_wc_2_times_at_fan_system_design_conditions": "", |
| 52 | + "adjustment_in_wc_effectiveness_multiplier": 0.0, |
| 53 | + "adjustment_in_wc_per_100_ft_of_verticaul_duct_exceeding_75_ft": 0.0, |
| 54 | + "annotation": "", |
| 55 | +} |
| 56 | + |
| 57 | + |
| 58 | +class SystemRequirementsFanPowerAllowancePressureDropAdjustment(DBOperation): |
| 59 | + def __init__(self, table_name, initial_data_directory): |
| 60 | + super(SystemRequirementsFanPowerAllowancePressureDropAdjustment, self).__init__( |
| 61 | + table_name=table_name, |
| 62 | + record_template=RECORD_TEMPLATE, |
| 63 | + initial_data_directory=initial_data_directory, |
| 64 | + create_table_query=CREATE_SYSTEM_requirements_fan_power_allowance_pressure_drop_adjustment_TABLE |
| 65 | + % table_name, |
| 66 | + insert_record_query=INSERT_A_SYSTEM_requirements_fan_power_allowance_pressure_drop_adjustment_RECORD |
| 67 | + % table_name, |
| 68 | + ) |
| 69 | + |
| 70 | + def get_record_info(self): |
| 71 | + """ |
| 72 | + A function to return the record info of the table |
| 73 | + :return: |
| 74 | + """ |
| 75 | + return RECORD_HELP |
| 76 | + |
| 77 | + def validate_record_datatype(self, record): |
| 78 | + str_expected = [ |
| 79 | + "template", |
| 80 | + "device" "adjustment_in_wc_at_fan_system_design_conditions", |
| 81 | + "adjustment_in_wc_2_times_at_fan_system_design_conditions", |
| 82 | + ] |
| 83 | + |
| 84 | + for f in str_expected: |
| 85 | + if record.get(f): |
| 86 | + assert isinstance( |
| 87 | + record[f], str |
| 88 | + ), f"{f} requires to be a string, instead got {record[f]}" |
| 89 | + |
| 90 | + float_expected = [ |
| 91 | + "adjustment_in_wc", |
| 92 | + "adjustment_in_wc_effectiveness_multiplier", |
| 93 | + "adjustment_in_wc_per_100_ft_of_verticaul_duct_exceeding_75_ft", |
| 94 | + ] |
| 95 | + |
| 96 | + for f in float_expected: |
| 97 | + if record.get(f): |
| 98 | + assert is_float( |
| 99 | + record.get(f) |
| 100 | + ), f"{f} requires to be numeric data type, instead got {record[f]}" |
| 101 | + return True |
| 102 | + |
| 103 | + def _preprocess_record(self, record): |
| 104 | + """ |
| 105 | +
|
| 106 | + :param record: dict |
| 107 | + :return: |
| 108 | + """ |
| 109 | + |
| 110 | + return ( |
| 111 | + getattr_either("template", record), |
| 112 | + getattr_either("device", record), |
| 113 | + getattr_either("adjustment_in_wc", record), |
| 114 | + getattr_either("adjustment_in_wc_at_fan_system_design_conditions", record), |
| 115 | + getattr_either( |
| 116 | + "adjustment_in_wc_2_times_at_fan_system_design_conditions", record |
| 117 | + ), |
| 118 | + getattr_either("adjustment_in_wc_effectiveness_multiplier", record), |
| 119 | + getattr_either( |
| 120 | + "adjustment_in_wc_per_100_ft_of_verticaul_duct_exceeding_75_ft", record |
| 121 | + ), |
| 122 | + getattr_either("annotation", record), |
| 123 | + ) |
0 commit comments