Method: GenericQAQC#run
- Defined in:
- lib/measures/generic_qaqc/measure.rb
#run(runner, user_arguments) ⇒ Object
define what happens when the measure is run
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 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'lib/measures/generic_qaqc/measure.rb', line 199 def run(runner, user_arguments) super(runner, user_arguments) # make the runner a class variable @runner = runner # if true errors on QAQC sections will show full backtrace. Use for diagnostics @error_backtrace = true # register initial condition runner.registerInitialCondition('Starting QAQC report generation') # get sql, model, and web assets setup = OsLib_Reporting.setup(runner) unless setup return false end @model = setup[:model] # workspace = setup[:workspace] @sql = setup[:sqlFile] web_asset_path = setup[:web_asset_path] # temp code to address climate zone problem mentioned in OpenStudio issue# 3148 climateZones = @model.getClimateZones cz = climateZones.getClimateZones('ASHRAE').first.value climateZones.clear climateZones.setClimateZone('ASHRAE', cz) # assign the user inputs to variables args = runner.getArgumentValues(arguments, user_arguments) args = Hash[args.collect{ |k, v| [k.to_s, v] }] unless args return false end # vector to store the results and checks report_elems = OpenStudio::AttributeVector.new # used for edapt programs to populate xml file with extra data # report_elems << create_results # lookup and replace argument values from upstream measures if args['use_upstream_args'] == true args.each do |arg, value| next if arg == 'use_upstream_args' # this argument should not be changed value_from_osw = runner.getPastStepValuesForName(arg) value_from_osw = value_from_osw.collect{ |k, v| Hash[:measure_name => k, :value => v] }.first if !value_from_osw.empty? if !value_from_osw.empty? runner.registerInfo("Replacing argument named #{arg} from current measure with a value of #{value_from_osw[:value]} from #{value_from_osw[:measure_name]}.") new_val = value_from_osw[:value] # TODO: - make code to handle non strings more robust. check_upstream_measure_for_arg coudl pass bakc the argument type if arg == 'total_bldg_floor_area' args[arg] = new_val.to_f elsif arg == 'num_stories_above_grade' args[arg] = new_val.to_f elsif arg == 'zipcode' args[arg] = new_val.to_i else args[arg] = new_val end end end end # utility name to to used by some qaqc checks @utility_name = nil # for utility QAQC string is passed in default_target_standard = args['template'] # for utility QAQC this is hard coded, for generic it is user argument # get building type, different standards path if multifamily building_type = '' if @model.getBuilding.standardsBuildingType.is_initialized building_type = @model.getBuilding.standardsBuildingType.get end # create an attribute vector to hold the checks check_elems = OpenStudio::AttributeVector.new # loop through QAQC categories where bool is true possible_check_categories.each do |hash| # skip if bool arg for this method is false next if args[hash[:method_name]] == false cat = hash[:cat] cat_input = "\'#{cat}\'" if hash[:standards] standards_input = ",\'#{default_target_standard}\'" else standards_input = '' end if hash[:data].nil? data_input = '' else data_input = ",#{hash[:data]}" end # get min tol if args.key?("#{hash[:method_name]}_tol") # get tol value tol = args["#{hash[:method_name]}_tol"] # set min inputs if tol.is_a? Float min_input = ",#{tol}" else min_input = '' end else min_input = '' end # get max tol if args.key?("#{hash[:method_name]}_max_tol") # get tol value max_tol = args["#{hash[:method_name]}_max_tol"] # set max inputs if max_tol.is_a? Float max_input = ",#{max_tol}" elsif (hash[:tol_max] == true) && hash[:tol_min].is_a?(Float) # if true then use double from min_tol max_input = ",#{args["#{hash[:method_name]}_tol"]}" else max_input = '' end else if (hash[:tol_max] == true) && hash[:tol_min].is_a?(Float) # if true then use double from min_tol max_input = ",#{args["#{hash[:method_name]}_tol"]}" else max_input = '' end end # run QAQC check eval("check_elems << #{hash[:method_name]}(#{cat_input}#{data_input}#{standards_input}#{min_input}#{max_input},false)") end # add checks to report_elems report_elems << OpenStudio::Attribute.new('checks', check_elems) # create an extra layer of report. the first level gets thrown away. top_level_elems = OpenStudio::AttributeVector.new top_level_elems << OpenStudio::Attribute.new('report', report_elems) # create the report result = OpenStudio::Attribute.new('summary_report', top_level_elems) result.saveToXml(OpenStudio::Path.new('report.xml')) # closing the sql file @sql.close # reporting final condition runner.registerFinalCondition('Finished generating report.xml.') # populate sections using attributes sections = OsLib_Reporting.sections_from_check_attributes(check_elems, runner) # generate html output OsLib_Reporting.gen_html("#{File.dirname(__FILE__)}report.html.erb", web_asset_path, sections, name) return true end |