Module: OsLib_Reporting_example
- Defined in:
- lib/measures/example_report/resources/os_lib_reporting_example.rb
Class Method Summary collapse
-
.general_building_information_section(model, sqlFile, runner, name_only = false) ⇒ Object
section for general building information.
-
.general_building_information_table(model, sqlFile, runner) ⇒ Object
create table with general building information this table shows how to pull information out of the model and the sql file.
-
.mat_prop_section(model, sqlFile, runner, name_only = false) ⇒ Object
section for sample material properties.
-
.mat_prop_table(model, sqlFile, runner) ⇒ Object
sample material property table using scatter plot.
-
.setup(runner) ⇒ Object
setup - get model, sql, and setup web assets path.
-
.template_section(model, sqlFile, runner, name_only = false) ⇒ Object
create template section.
-
.template_table(model, sqlFile, runner) ⇒ Object
create template section.
Class Method Details
.general_building_information_section(model, sqlFile, runner, name_only = false) ⇒ Object
section for general building information
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/measures/example_report/resources/os_lib_reporting_example.rb', line 174 def self.general_building_information_section(model, sqlFile, runner, name_only = false) # array to hold tables tables = [] # gather data for section @mat_prop = {} @mat_prop[:title] = 'General Building Information' @mat_prop[:tables] = tables # stop here if only name is requested this is used to populate display name for arguments if name_only == true return @mat_prop end # using helper method that generates table for second example tables << OsLib_Reporting_example.general_building_information_table(model, sqlFile, runner) return @mat_prop end |
.general_building_information_table(model, sqlFile, runner) ⇒ Object
create table with general building information this table shows how to pull information out of the model and the sql file
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/measures/example_report/resources/os_lib_reporting_example.rb', line 196 def self.general_building_information_table(model, sqlFile, runner) # general building information type data output general_building_information = {} general_building_information[:title] = 'Building Summary' # name will be with section general_building_information[:header] = ['Information', 'Value', 'Units'] general_building_information[:units] = [] # won't populate for this table since each row has different units. general_building_information[:data] = [] # structure ID / building name display = 'Building Name' target_units = 'building_name' value = model.getBuilding.name.to_s general_building_information[:data] << [display, value, target_units] runner.registerValue(display.downcase.tr(' ', '_'), value, target_units) # net site energy display = 'Net Site Energy' source_units = 'GJ' target_units = 'kBtu' value = OpenStudio.convert(sqlFile.netSiteEnergy.get, source_units, target_units).get value_neat = OpenStudio.toNeatString(value, 0, true) general_building_information[:data] << [display, value_neat, target_units] runner.registerValue(display.downcase.tr(' ', '_'), value, target_units) # total building area query = 'SELECT Value FROM tabulardatawithstrings WHERE ' query << "ReportName='AnnualBuildingUtilityPerformanceSummary' and " query << "ReportForString='Entire Facility' and " query << "TableName='Building Area' and " query << "RowName='Total Building Area' and " query << "ColumnName='Area' and " query << "Units='m2';" query_results = sqlFile.execAndReturnFirstDouble(query) if query_results.empty? runner.registerWarning('Did not find value for total building area.') return false else display = 'Total Building Area' source_units = 'm^2' target_units = 'ft^2' value = OpenStudio.convert(query_results.get, source_units, target_units).get value_neat = OpenStudio.toNeatString(value, 0, true) general_building_information[:data] << [display, value_neat, target_units] runner.registerValue(display.downcase.tr(' ', '_'), value, target_units) end # temp code to check OS vs. E+ area energy_plus_area = query_results.get open_studio_area = model.getBuilding.floorArea if energy_plus_area != open_studio_area runner.registerWarning("EnergyPlus reported area is #{query_results.get} (m^2). OpenStudio reported area is #{model.getBuilding.floorArea} (m^2).") end # EUI eui = sqlFile.netSiteEnergy.get / query_results.get display = 'EUI' source_units = 'GJ/m^2' target_units = 'kBtu/ft^2' if query_results.get > 0.0 # don't calculate EUI if building doesn't have any area value = OpenStudio.convert(eui, source_units, target_units).get value_neat = OpenStudio.toNeatString(value, 2, true) runner.registerValue(display.downcase.tr(' ', '_'), value, target_units) # is it ok not to calc EUI if no area in model else value_neat = "can't calculate EUI." end general_building_information[:data] << ["#{display} (Based on Net Site Energy and Total Building Area)", value_neat, target_units] return general_building_information end |
.mat_prop_section(model, sqlFile, runner, name_only = false) ⇒ Object
section for sample material properties
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/measures/example_report/resources/os_lib_reporting_example.rb', line 120 def self.mat_prop_section(model, sqlFile, runner, name_only = false) # array to hold tables tables = [] # gather data for section @mat_prop = {} @mat_prop[:title] = 'Material Properties' @mat_prop[:tables] = tables # stop here if only name is requested this is used to populate display name for arguments if name_only == true return @mat_prop end # using helper method that generates table for second example tables << OsLib_Reporting_example.mat_prop_table(model, sqlFile, runner) return @mat_prop end |
.mat_prop_table(model, sqlFile, runner) ⇒ Object
sample material property table using scatter plot
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/measures/example_report/resources/os_lib_reporting_example.rb', line 141 def self.mat_prop_table(model, sqlFile, runner) # create table mat_prop_table = {} mat_prop_table[:title] = 'Metals' mat_prop_table[:header] = ['Material', 'Notes/Index', 'Density', 'Tension'] mat_prop_table[:units] = ['', '', 'Kg/m^3', 'MPa'] mat_prop_table[:data] = [] # create chart mat_prop_table[:chart_type] = 'scatter' mat_prop_table[:chart_attributes] = { label_x: mat_prop_table[:header][2], label_y: mat_prop_table[:header][3] } mat_prop_table[:chart] = [] # add data to table and chart source_data = [] source_data << ['Steel', 'Structural', 7860.0, 400.0] source_data << ['Steel', 'High-strength-low-allow', 7860.0, 480.0] source_data << ['Steel', 'Quenched and tempered alloy', 7860.0, 825.0] source_data << ['Steel', 'Cold-rolled', 7920.0, 860.0] source_data << ['Steel', 'Annealed', 7920.0, 620.0] source_data << ['Cast Iron', '', 7200.0, 170.0] source_data << ['Aluminum', '', 2710.0, 110.0] source_data << ['Brass', '', 8470.0, 540.0] source_data << ['Titanium', '', 4460.0, 900.0] source_data.each do |mat| mat_prop_table[:data] << [mat[0], mat[1], mat[2], mat[3]] mat_prop_table[:chart] << JSON.generate(label: mat[0], index: mat[1], label_x: mat[2], label_y: mat[3]) end return mat_prop_table end |
.setup(runner) ⇒ Object
setup - get model, sql, and setup web assets path
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/measures/example_report/resources/os_lib_reporting_example.rb', line 10 def self.setup(runner) results = {} # get the last model model = runner.lastOpenStudioModel if model.empty? runner.registerError('Cannot find last model.') return false end model = model.get # get the last idf workspace = runner.lastEnergyPlusWorkspace if workspace.empty? runner.registerError('Cannot find last idf file.') return false end workspace = workspace.get # get the last sql file sqlFile = runner.lastEnergyPlusSqlFile if sqlFile.empty? runner.registerError('Cannot find last sql file.') return false end sqlFile = sqlFile.get model.setSqlFile(sqlFile) # populate hash to pass to measure results[:model] = model # results[:workspace] = workspace results[:sqlFile] = sqlFile results[:web_asset_path] = OpenStudio.getSharedResourcesPath / OpenStudio::Path.new('web_assets') return results end |
.template_section(model, sqlFile, runner, name_only = false) ⇒ Object
create template section
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/measures/example_report/resources/os_lib_reporting_example.rb', line 60 def self.template_section(model, sqlFile, runner, name_only = false) # array to hold tables template_tables = [] # gather data for section @template_section = {} @template_section[:title] = 'Tasty Treats' @template_section[:tables] = template_tables # stop here if only name is requested this is used to populate display name for arguments if name_only == true return @template_section end # create table template_table_01 = {} template_table_01[:title] = 'Fruit' template_table_01[:header] = ['Type', 'Quantity'] template_table_01[:units] = ['', 'lbs'] template_table_01[:data] = [] # add rows to table template_table_01[:data] << ['Banana', 100] template_table_01[:data] << ['Apple', 250] template_table_01[:data] << ['Orange', 175] # create chart template_table_01[:chart_type] = 'simple_pie' template_table_01[:chart] = [] template_table_01[:data].each do |row| template_table_01[:chart] << JSON.generate(label: row[0], value: row[1]) end # add table to array of tables template_tables << template_table_01 # use helper method that generates additional table for section template_tables << OsLib_Reporting_example.template_table(model, sqlFile, runner) return @template_section end |
.template_table(model, sqlFile, runner) ⇒ Object
create template section
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/measures/example_report/resources/os_lib_reporting_example.rb', line 103 def self.template_table(model, sqlFile, runner) # create a second table template_table = {} template_table[:title] = 'Ice Cream' template_table[:header] = ['Type', 'Base Flavor', 'Toppings', 'Value'] template_table[:units] = ['', '', '', 'scoop'] template_table[:data] = [] # add rows to table template_table[:data] << ['Vanilla', 'Vanilla', 'NA', 1.5] template_table[:data] << ['Rocky Road', 'Chocolate', 'Nuts', 1.5] template_table[:data] << ['Mint Chip', 'Mint', 'Chocolate Chips', 1.5] return template_table end |