Class: VentilationQAQC
- Inherits:
-
OpenStudio::Measure::ReportingMeasure
- Object
- OpenStudio::Measure::ReportingMeasure
- VentilationQAQC
- Defined in:
- lib/measures/VentilationQAQC/measure.rb
Overview
start the measure
Instance Attribute Summary collapse
-
#outData ⇒ Object
readonly
Returns the value of attribute outData.
Instance Method Summary collapse
-
#arguments(model = nil) ⇒ Object
note - there is no ‘model’ argument provided here.
- #calculateOutdoorAirFlow(spaceMetrics, spec) ⇒ Object
- #energyPlusOutputRequests(runner, user_arguments) ⇒ Object
- #getAirChangesPerHour(spaceMetrics) ⇒ Object
- #getFlowPerPerson(spaceMetrics) ⇒ Object
- #getResourceFileData(fileName) ⇒ Object
- #getTimeSeries(name, index, envperiod, rate, runner) ⇒ Object
- #getTimesForSeries(name, index, envperiod, rate, runner) ⇒ Object
-
#name ⇒ Object
define the name that a user will see, this method may be deprecated as the display name in PAT comes from the name field in measure.xml.
-
#run(runner, user_arguments) ⇒ Object
define what happens when the measure is run.
-
#to_JSTime(os_time) ⇒ Object
Method to translate from OpenStudio’s time formatting to Javascript time formatting OpenStudio time 2009-May-14 00:10:00 Raw string Javascript time 2009/07/12 12:34:56.
- #writeResourceFileData(fileName, data) ⇒ Object
Instance Attribute Details
#outData ⇒ Object (readonly)
Returns the value of attribute outData.
310 311 312 |
# File 'lib/measures/VentilationQAQC/measure.rb', line 310 def outData @outData end |
Instance Method Details
#arguments(model = nil) ⇒ Object
note - there is no ‘model’ argument provided here. This may cause an issue.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/measures/VentilationQAQC/measure.rb', line 43 def arguments(model = nil) args = OpenStudio::Measure::OSArgumentVector.new # Future functionality # zone_titles = [] # model.getThermalZones.each do |thermalZone| # zone_name = thermalZone.name.empty? ? thermalZone.name.get : '' # zone_titles.push( zone_name ) # end # Choice list of measure_zones measure_zones = ['All Zones'] measure_zone = OpenStudio::Measure::OSArgument.makeChoiceArgument('measure_zone', measure_zones, measure_zones, true) measure_zone.setDefaultValue('All Zones') measure_zone.setDisplayName('Pick a Zone (or all Zones)') args << measure_zone return args end |
#calculateOutdoorAirFlow(spaceMetrics, spec) ⇒ Object
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
# File 'lib/measures/VentilationQAQC/measure.rb', line 368 def calculateOutdoorAirFlow(spaceMetrics, spec) # Calculate airflows for all methods. Airflows are in native units (m3/s) flows = [ spec.outdoorAirFlowperPerson * spaceMetrics[:calculatedPeople], spec.outdoorAirFlowperFloorArea * spaceMetrics[:floorAreaM2], spec.outdoorAirFlowAirChangesperHour * spaceMetrics[:volumeM3] / 3600, spec.outdoorAirFlowRate ] # Depending on the outdoorAirMethod chosen, we return either the sum or maximum of the above flows if spec.outdoorAirMethod == 'Sum' return flows.inject(0) { |sum, i| sum + i } end if spec.outdoorAirMethod == 'Maximum' return flows.max end end |
#energyPlusOutputRequests(runner, user_arguments) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/measures/VentilationQAQC/measure.rb', line 16 def energyPlusOutputRequests(runner, user_arguments) super(runner, user_arguments) result = OpenStudio::IdfObjectVector.new if !runner.validateUserArguments(arguments, user_arguments) return result end ventilation = OpenStudio::IdfObject.load('Output:Variable,,Zone Mechanical Ventilation Current Density Volume Flow Rate,Hourly;').get result << ventilation ach = OpenStudio::IdfObject.load('Output:Variable,,Zone Infiltration Air Change Rate,Hourly;').get result << ach people = OpenStudio::IdfObject.load('Output:Variable,,Zone People Occupant Count,Hourly;').get result << people return result end |
#getAirChangesPerHour(spaceMetrics) ⇒ Object
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
# File 'lib/measures/VentilationQAQC/measure.rb', line 409 def getAirChangesPerHour(spaceMetrics) out = 0 i = 0 # translate existing metrics into airChangesPerHour and sum for all designFlowRate structures secondsPerHourPerVolume = 3600 / spaceMetrics[:volumeM3] spaceMetrics[:designFlowRates].each do |flowRate| curr = 0 if !spaceMetrics[:designFlowRates][i][:designFlowRate].nil? curr = spaceMetrics[:designFlowRates][i][:designFlowRate] * secondsPerHourPerVolume elsif !spaceMetrics[:designFlowRates][i][:flowPerSpaceFloorArea].nil? curr = spaceMetrics[:designFlowRates][i][:flowPerSpaceFloorArea] * spaceMetrics[:floorAreaM2] * secondsPerHourPerVolume elsif !spaceMetrics[:designFlowRates][i][:flowPerExteriorSurfaceArea].nil? curr = spaceMetrics[:designFlowRates][i][:flowPerExteriorSurfaceArea] * spaceMetrics[:exteriorAreaM2] * secondsPerHourPerVolume elsif !spaceMetrics[:designFlowRates][i][:airChangesperHour].nil? curr = spaceMetrics[:designFlowRates][i][:airChangesperHour] end out += curr i += 1 end return out end |
#getFlowPerPerson(spaceMetrics) ⇒ Object
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 |
# File 'lib/measures/VentilationQAQC/measure.rb', line 386 def getFlowPerPerson(spaceMetrics) out = 0 if !spaceMetrics[:specOutdoorAirFlowperPerson].nil? out = spaceMetrics[:specOutdoorAirFlowperPerson] elsif !spaceMetrics[:specOutdoorAirFlowperFloorArea].nil? if spaceMetrics[:peoplePerFloorArea] != 0 out = spec.getOutdoorAirFlowperFloorArea.value * (1 / spaceMetrics[:peoplePerFloorArea]) end elsif !spaceMetrics[:specOutdoorAirFlowRate].nil? if spaceMetrics[:calculatedPeople] != 0 out = spec.outdoorAirFlowRate / spaceMetrics[:calculatedPeople] end elsif !spaceMetrics[:specOutdoorAirFlowAirChangesperHour].nil? if spaceMetrics[:calculatedPeople] != 0 out = spec.getOutdoorAirFlowAirChangesperHour.value / 60 * spaceMetrics[:volumeM3] / spaceMetrics[:calculatedPeople] end end end |
#getResourceFileData(fileName) ⇒ Object
312 313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'lib/measures/VentilationQAQC/measure.rb', line 312 def getResourceFileData(fileName) data_in_path = "#{File.dirname(__FILE__)}/resources/#{fileName}" if !File.exist?(data_in_path) data_in_path = "#{File.dirname(__FILE__)}/#{fileName}" end html_in = '' File.open(data_in_path, 'r') do |file| html_in = file.read end html_in end |
#getTimeSeries(name, index, envperiod, rate, runner) ⇒ Object
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'lib/measures/VentilationQAQC/measure.rb', line 338 def getTimeSeries(name, index, envperiod, rate, runner) series = @sqlFile.timeSeries(envperiod, rate, name, index) if series.empty? runner.registerWarning("No data found for '#{name}' '#{index}'") return nil else series = series.get end series_collection = series.values series_vals = [] for i in 0..(series_collection.size - 1) series_vals << series_collection[i] end series_vals end |
#getTimesForSeries(name, index, envperiod, rate, runner) ⇒ Object
356 357 358 359 360 361 362 363 364 365 366 |
# File 'lib/measures/VentilationQAQC/measure.rb', line 356 def getTimesForSeries(name, index, envperiod, rate, runner) series = @sqlFile.timeSeries(envperiod, rate, name, index) if series.empty? runner.registerWarning("No data found for '#{name}' '#{index}'") return nil else series = series.get end series.dateTimes end |
#name ⇒ Object
define the name that a user will see, this method may be deprecated as the display name in PAT comes from the name field in measure.xml
12 13 14 |
# File 'lib/measures/VentilationQAQC/measure.rb', line 12 def name return 'Ventilation Report' end |
#run(runner, user_arguments) ⇒ Object
define what happens when the measure is run
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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 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 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 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 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/measures/VentilationQAQC/measure.rb', line 64 def run(runner, user_arguments) super(runner, user_arguments) # use the built-in error checking if !runner.validateUserArguments(arguments, user_arguments) return false end # get the last model and sql file model = runner.lastOpenStudioModel if model.empty? runner.registerError('Cannot find last model.') return false end model = model.get @sqlFile = runner.lastEnergyPlusSqlFile if @sqlFile.empty? runner.registerError('Cannot find last sql file.') return false end @sqlFile = @sqlFile.get model.setSqlFile(@sqlFile) # Get the weather file (as opposed to design day) run period annEnvPd = nil @sqlFile.availableEnvPeriods.each do |envPd| envType = @sqlFile.environmentType(envPd) if !envType.empty? if envType.get == 'WeatherRunPeriod'.to_EnvironmentType annEnvPd = envPd end else puts('Could not get weather file info') end end # binding.pry # put data into variables, these are available in the local scope binding zoneCollection = [] spaceCollection = [] annualGraphData = [] warnings = [] model.getThermalZones.sort.each do |thermalZone| zone_name = !thermalZone.name.empty? ? thermalZone.name.get : '' puts("Zone:#{zone_name}") # Get the hourly ventilation in cfm puts('Get Ventilation') zone_mechanical_ventilation_vals = getTimeSeries('Zone Mechanical Ventilation Current Density Volume Flow Rate', zone_name.upcase, annEnvPd, 'Hourly', runner) if zone_mechanical_ventilation_vals zone_mechanical_ventilation_vals.map! { |v| v * 2118.882 } max_ventilation = zone_mechanical_ventilation_vals.max || 0 # max of an empty array is nil, so use 0 for max ventilation in this case else max_ventilation = 0 end puts('Get Infiltration') zone_infiltration_vals = getTimeSeries('Zone Infiltration Air Change Rate', zone_name.upcase, annEnvPd, 'Hourly', runner) zone_occupant_vals = getTimeSeries('Zone People Occupant Count', zone_name.upcase, annEnvPd, 'Hourly', runner) zone_occupant_max = !zone_occupant_vals.nil? ? zone_occupant_vals.max : 0 # stop here if zone_occupant_max is 0 is don't divide by 0 and catch zone_occupant_vals when nil before .map if zone_occupant_max == 0 runner.registerInfo("Skipping #{zone_name}, can't noramlize occupancy with max of 0.") else zone_occupant_normalized = zone_occupant_vals.map { |v| v / zone_occupant_max } unoccupied = 0 lightly_occupied = 0 coordinated = zone_occupant_normalized.zip(zone_mechanical_ventilation_vals) coordinated.each do |vals| normalized_occupancy = vals[0] zone_mech_vent = vals[1] if normalized_occupancy == 0 && zone_mech_vent > 0 unoccupied += 1 end if normalized_occupancy < 0.05 && zone_mech_vent > 20 lightly_occupied += 1 end end puts "Unoccupied: #{unoccupied}, Lightly Occupied: #{lightly_occupied}" if unoccupied > 10 warnings.push("Thermal Zone <strong>#{zone_name}</strong> appears to have mechanical ventilation during periods when the zone is unoccupied, resulting in potentially unnecessary ventilation energy. This occurs <strong>#{unoccupied}</strong> hours per run period. Please ensure this is a correct representation of the modeling scenario. Minimum fraction OA schedules may need adjusting.") end if lightly_occupied > 1500 warnings.push("Thermal Zone <strong>#{zone_name}</strong> appears to have mechanical ventilation during periods when the zone is lightly occupied, resulting in potentially unnecessary ventilation energy. This occurs <strong>#{lightly_occupied}</strong> hours per run period. Please ensure this is a correct representation of the modeling scenario.") end end times = getTimesForSeries('Zone Infiltration Air Change Rate', zone_name.upcase, annEnvPd, 'Hourly', runner) if !times.nil? js_date_times = times.map { |t| to_JSTime(t) } # Create an array of arrays [timestamp, zone_mechanical_ventilation_vals, zone_infiltration_vals] if zone_infiltration_vals hourly_vals = js_date_times.zip(zone_infiltration_vals) else hourly_vals = nil end # Add the hourly load data to JSON for the report.html graph = {} graph['title'] = "#{zone_name} - Hourly Infiltration" graph['xaxislabel'] = 'Time' graph['yaxislabel'] = 'Infiltration (ACH)' graph['labels'] = ['Date', 'Infiltration (ACH)'] graph['colors'] = ['#FF5050', '#0066FF'] graph['timeseries'] = hourly_vals # This measure requires ruby 2.0.0 to create the JSON for the report graph if RUBY_VERSION >= '2.0.0' annualGraphData << graph end end zoneMetrics = {} zoneMetrics[:zoneWeightedCFM] = 0 thermalZone.spaces.each do |space| spaceMetrics = {} spaceMetrics[:name] = !space.name.empty? ? space.name.get : '' spaceMetrics[:isPartOfTotalFloorArea] = space.partofTotalFloorArea spaceMetrics[:floorAreaM2] = space.floorArea spaceMetrics[:volumeM3] = space.volume spaceMetrics[:peoplePerFloorArea] = space.peoplePerFloorArea # spaceMetrics[:exteriorAreaM2] = space.exteriorArea spaceMetrics[:calculatedPeople] = space.floorArea * space.peoplePerFloorArea if !space.designSpecificationOutdoorAir.empty? spec = space.designSpecificationOutdoorAir.get # spaceMetrics[:specMethod] = spec.outdoorAirMethod spaceMetrics[:specOutdoorAirFlowperPerson] = spec.outdoorAirFlowperPerson spaceMetrics[:specOutdoorAirFlowperFloorArea] = spec.outdoorAirFlowperFloorArea spaceMetrics[:specOutdoorAirFlowRate] = spec.outdoorAirFlowRate spaceMetrics[:specOutdoorAirFlowAirChangesperHour] = spec.outdoorAirFlowAirChangesperHour # Outdoor Air Method # Outdoor Air Flow per Person {m3/s-person} # Outdoor Air Flow per Floor Area {m3/s-m2} # Outdoor Air Flow Rate {m3/s} # Outdoor Air Flow Air Changes per Hour {1/hr} # Outdoor Air Flow Rate Fraction Schedule Name outdoorAirFlow = calculateOutdoorAirFlow(spaceMetrics, spec) if spaceMetrics[:calculatedPeople] > 0 spaceMetrics[:outsideAirPerPerson] = OpenStudio.convert(outdoorAirFlow, 'm^3/s', 'cfm').get / spaceMetrics[:calculatedPeople] else spaceMetrics[:outsideAirPerPerson] = 0 end else spaceMetrics[:outsideAirPerPerson] = 0 end i = 0 spaceMetrics[:designFlowRates] = {} space.spaceInfiltrationDesignFlowRates.each do |designFlowRate| spaceMetrics[:designFlowRates][i] = {} spaceMetrics[:designFlowRates][i][:calcMethod] = designFlowRate.designFlowRateCalculationMethod spaceMetrics[:designFlowRates][i][:designFlowRate] = !designFlowRate.designFlowRate.empty? ? designFlowRate.designFlowRate.get : nil spaceMetrics[:designFlowRates][i][:flowPerSpaceFloorArea] = !designFlowRate.flowperSpaceFloorArea.empty? ? designFlowRate.flowperSpaceFloorArea.get : nil spaceMetrics[:designFlowRates][i][:flowPerExteriorSurfaceArea] = !designFlowRate.flowperExteriorSurfaceArea.empty? ? designFlowRate.flowperExteriorSurfaceArea.get : nil spaceMetrics[:designFlowRates][i][:airChangesperHour] = !designFlowRate.airChangesperHour.empty? ? designFlowRate.airChangesperHour.get : nil i += 1 end spaceMetrics[:airChangesPerHour] = space.infiltrationDesignAirChangesPerHour i = 0 spaceMetrics[:effectiveLeakageAreas] = {} space.spaceInfiltrationEffectiveLeakageAreas.each do |effectiveLeakageArea| spaceMetrics[:effectiveLeakageAreas][i] = {} spaceMetrics[:effectiveLeakageAreas][i][:leakageArea] = effectiveLeakageArea.effectiveAirLeakageArea i += 1 end designFlow = spaceMetrics[:outsideAirPerPerson] ? spaceMetrics[:outsideAirPerPerson] * spaceMetrics[:calculatedPeople] : 0 spaceWeight = spaceMetrics[:floorAreaM2] / thermalZone.floorArea spaceMetrics[:spaceWeightedCFM] = spaceWeight * designFlow spaceCollection.push(spaceMetrics) zoneMetrics[:zoneWeightedCFM] = zoneMetrics[:zoneWeightedCFM] + spaceMetrics[:spaceWeightedCFM] end if zoneMetrics[:zoneWeightedCFM] / 2 > max_ventilation warnings.push("Thermal Zone <strong>#{zone_name}</strong> appears to have excessive outside air assignments. Check the number of Design Specification Outdoor Air Objects associated with this zone.") end zoneCollection.push(zoneMetrics) end spaceCollection.sort! { |a, b| a[:name].downcase <=> b[:name].downcase } output = "Measure Name = #{name}" # Convert the graph data to JSON # This measure requires ruby 2.0.0 to create the JSON for the report graph if RUBY_VERSION >= '2.0.0' require 'json' annualGraphData = annualGraphData.to_json else runner.registerInfo("This Measure needs Ruby 2.0.0 to generate timeseries graphs on the report. You have Ruby #{RUBY_VERSION}. OpenStudio 1.4.2 and higher user Ruby 2.0.0.") end web_asset_path = OpenStudio.getSharedResourcesPath / OpenStudio::Path.new('web_assets') html_in = getResourceFileData('report.html.in') # configure template with variable values renderer = ERB.new(html_in) html_out = renderer.result(binding) writeResourceFileData('report.html', html_out) # closing the sql file @sqlFile.close # reporting final condition runner.registerFinalCondition('Goodbye.') @outData = { spaceCollection: spaceCollection, zoneCollection: zoneCollection, warnings: warnings } return true end |
#to_JSTime(os_time) ⇒ Object
Method to translate from OpenStudio’s time formatting to Javascript time formatting OpenStudio time 2009-May-14 00:10:00 Raw string Javascript time 2009/07/12 12:34:56
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 |
# File 'lib/measures/VentilationQAQC/measure.rb', line 446 def to_JSTime(os_time) js_time = os_time.to_s # Replace the '-' with '/' js_time = js_time.tr('-', '/') # Replace month abbreviations with numbers js_time = js_time.gsub('Jan', '01') js_time = js_time.gsub('Feb', '02') js_time = js_time.gsub('Mar', '03') js_time = js_time.gsub('Apr', '04') js_time = js_time.gsub('May', '05') js_time = js_time.gsub('Jun', '06') js_time = js_time.gsub('Jul', '07') js_time = js_time.gsub('Aug', '08') js_time = js_time.gsub('Sep', '09') js_time = js_time.gsub('Oct', '10') js_time = js_time.gsub('Nov', '11') js_time = js_time.gsub('Dec', '12') return js_time end |
#writeResourceFileData(fileName, data) ⇒ Object
326 327 328 329 330 331 332 333 334 335 336 |
# File 'lib/measures/VentilationQAQC/measure.rb', line 326 def writeResourceFileData(fileName, data) File.open("./#{fileName}", 'w') do |file| file << data # make sure data is written to the disk one way or the other begin file.fsync rescue StandardError file.flush end end end |