Class: RunReportingMeasures
- Inherits:
-
Object
- Object
- RunReportingMeasures
- Includes:
- OpenStudio::Workflow::ApplyMeasures
- Defined in:
- lib/openstudio/workflow/jobs/run_reporting_measures/run_reporting_measures.rb
Constant Summary
Constants included from OpenStudio::Workflow::ApplyMeasures
OpenStudio::Workflow::ApplyMeasures::MEASURE_TYPES
Instance Method Summary collapse
-
#add_data(sql, query, hdr, area, val) ⇒ Object
add results from sql method.
-
#add_data2(sql, query, hdr, area, val) ⇒ Object
add results from sql method.
-
#add_data3(sql, query, hdr, area, val) ⇒ Object
add results from sql method.
-
#add_data4(sql, query, hdr, area, val) ⇒ Object
add results from sql method.
- #add_element(hash, var_name, value, xpath = nil) ⇒ Object
-
#initialize(directory, logger, adapter, options = {}) ⇒ RunReportingMeasures
constructor
A new instance of RunReportingMeasures.
- #perform ⇒ Object
- #run_extract_inputs_and_outputs ⇒ Object
- #sql_query(sql, report_name, query) ⇒ Object
Methods included from OpenStudio::Workflow::ApplyMeasures
#apply_arguments, #apply_measure, #apply_measures, #apply_variables
Constructor Details
#initialize(directory, logger, adapter, options = {}) ⇒ RunReportingMeasures
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/openstudio/workflow/jobs/run_reporting_measures/run_reporting_measures.rb', line 30 def initialize(directory, logger, adapter, = {}) defaults = {} = defaults.merge() @directory = directory @run_directory = "#{@directory}/run" @adapter = adapter @logger = logger @results = {} @output_attributes = {} # TODO: we shouldn't have to keep loading this file if we need it. It should be availabe for any job. # TODO: passing in the options everytime is ridiculuous @analysis_json = @adapter.get_problem(@directory, ) @logger.info "#{self.class} passed the following options #{@options}" @model = load_model [:run_openstudio][:osm] # TODO: should read the name of the sql output file via the :run_openstudio options hash # I want to reiterate that this is cheezy! @sql_filename = "#{@run_directory}/eplusout.sql" fail "EnergyPlus SQL file did not exist #{@sql_filename}" unless File.exist? @sql_filename @objective_functions = {} end |
Instance Method Details
#add_data(sql, query, hdr, area, val) ⇒ Object
add results from sql method
290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/openstudio/workflow/jobs/run_reporting_measures/run_reporting_measures.rb', line 290 def add_data(sql, query, hdr, area, val) row = [] val = sql_query(sql, 'AnnualBuildingUtilityPerformanceSummary', query) if val.nil? row << hdr if area.nil? row << val else row << (val * 1000) / area end row end |
#add_data2(sql, query, hdr, area, val) ⇒ Object
add results from sql method
303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/openstudio/workflow/jobs/run_reporting_measures/run_reporting_measures.rb', line 303 def add_data2(sql, query, hdr, area, val) row = [] val = sql_query(sql, 'BUILDING ENERGY PERFORMANCE - ELECTRICITY', query) if val.nil? row << hdr if area.nil? row << val else row << (val * 1000) / area end row end |
#add_data3(sql, query, hdr, area, val) ⇒ Object
add results from sql method
316 317 318 319 320 321 322 323 324 325 326 |
# File 'lib/openstudio/workflow/jobs/run_reporting_measures/run_reporting_measures.rb', line 316 def add_data3(sql, query, hdr, area, val) row = [] val = sql_query(sql, 'BUILDING ENERGY PERFORMANCE - NATURAL GAS', query) if val.nil? row << hdr if area.nil? row << val else row << (val * 1000) / area end row end |
#add_data4(sql, query, hdr, area, val) ⇒ Object
add results from sql method
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
# File 'lib/openstudio/workflow/jobs/run_reporting_measures/run_reporting_measures.rb', line 329 def add_data4(sql, query, hdr, area, val) row = [] if val.nil? val = 0 ['INTERIORLIGHTS:ELECTRICITY', 'EXTERIORLIGHTS:ELECTRICITY', 'INTERIOREQUIPMENT:ELECTRICITY', 'EXTERIOREQUIPMENT:ELECTRICITY', 'FANS:ELECTRICITY', 'PUMPS:ELECTRICITY', 'HEATING:ELECTRICITY', 'COOLING:ELECTRICITY', 'HEATREJECTION:ELECTRICITY', 'HUMIDIFIER:ELECTRICITY', 'HEATRECOVERY:ELECTRICITY', 'WATERSYSTEMS:ELECTRICITY', 'COGENERATION:ELECTRICITY', 'REFRIGERATION:ELECTRICITY'].each do |end_use| tmp_query = query + " AND ColumnName='#{end_use}'" tmp_val = sql_query(sql, 'BUILDING ENERGY PERFORMANCE - ELECTRICITY', tmp_query) val += tmp_val unless tmp_val.nil? end end row << hdr if area.nil? row << val else row << (val * 1000) / area end row end |
#add_element(hash, var_name, value, xpath = nil) ⇒ Object
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 |
# File 'lib/openstudio/workflow/jobs/run_reporting_measures/run_reporting_measures.rb', line 262 def add_element(hash, var_name, value, xpath = nil) values_hash = {} values_hash['name'] = var_name # store correct datatype store_val = nil if value.nil? store_val = nil elsif value == 'true' store_val = true elsif value == 'false' store_val = false else test = value.to_s value = test.match('\.').nil? ? Integer(test) : Float(test) rescue test.to_s if value.is_a?(Fixnum) || value.is_a?(Float) store_val = value.to_f else store_val = value.to_s end end values_hash['value'] = store_val values_hash['xpath'] = xpath unless xpath.nil? hash['data']['variables'] << values_hash end |
#perform ⇒ Object
56 57 58 59 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 |
# File 'lib/openstudio/workflow/jobs/run_reporting_measures/run_reporting_measures.rb', line 56 def perform @logger.info "Calling #{__method__} in the #{self.class} class" @logger.info 'RunPostProcess Retrieving datapoint and problem' begin @datapoint_json = @adapter.get_datapoint(@directory, ) @analysis_json = @adapter.get_problem(@directory, ) if [:use_monthly_reports] run_monthly_postprocess else run_standard_postprocess end translate_csv_to_json run_packaged_measures if @analysis_json && @analysis_json[:analysis] apply_measures(:reporting_measure) end @logger.info 'Saving reporting measures output attributes JSON' File.open("#{@run_directory}/reporting_measure_attributes.json", 'w') do |f| f << JSON.pretty_generate(@output_attributes) end run_extract_inputs_and_outputs @logger.info "Objective Function JSON is #{@objective_functions}" obj_fun_file = "#{@directory}/objectives.json" FileUtils.rm_f(obj_fun_file) if File.exist?(obj_fun_file) File.open(obj_fun_file, 'w') { |f| f << JSON.pretty_generate(@objective_functions) } rescue => e = "Runner error #{__FILE__} failed with #{e.message}, #{e.backtrace.join("\n")}" raise end @results end |
#run_extract_inputs_and_outputs ⇒ Object
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 |
# File 'lib/openstudio/workflow/jobs/run_reporting_measures/run_reporting_measures.rb', line 98 def run_extract_inputs_and_outputs # For xml, the measure attributes are in the measure_attributes_xml.json file # TODO: somehow pass the metadata around on which JSONs to suck into the database if File.exist? "#{@run_directory}/measure_attributes_xml.json" temp_json = JSON.parse(File.read("#{@run_directory}/measure_attributes_xml.json"), symbolize_names: true) @results.merge! temp_json end # Inputs are in the measure_attributes.json file if File.exist? "#{@run_directory}/measure_attributes.json" temp_json = JSON.parse(File.read("#{@run_directory}/measure_attributes.json"), symbolize_names: true) @results.merge! temp_json end # Inputs are in the reporting_measure_attributes.jsonfile if File.exist? "#{@run_directory}/reporting_measure_attributes.json" temp_json = JSON.parse(File.read("#{@run_directory}/reporting_measure_attributes.json"), symbolize_names: true) @results.merge! temp_json end # Initialize the objective function variable @objective_functions = {} if File.exist? "#{@run_directory}/standard_report_legacy.json" @results[:standard_report_legacy] = JSON.parse(File.read("#{@run_directory}/standard_report_legacy.json"), symbolize_names: true) @logger.info 'Iterating over Analysis JSON Output Variables' # Save the objective functions to the object for sending back to the simulation executive @analysis_json[:analysis][:output_variables].each do |variable| # determine which ones are the objective functions (code smell: todo: use enumerator) if variable[:objective_function] @logger.info "Looking for objective function #{variable[:name]}" # TODO: move this to cleaner logic. Use ostruct? if variable[:name].include? '.' k, v = variable[:name].split('.') if @results.key?(k.to_sym) && @results[k.to_sym][v.to_sym] @objective_functions["objective_function_#{variable[:objective_function_index] + 1}"] = @results[k.to_sym][v.to_sym] if variable[:objective_function_target] @logger.info "Found objective function target for #{variable[:name]}" @objective_functions["objective_function_target_#{variable[:objective_function_index] + 1}"] = variable[:objective_function_target].to_f end if variable[:scaling_factor] @logger.info "Found scaling factor for #{variable[:name]}" @objective_functions["scaling_factor_#{variable[:objective_function_index] + 1}"] = variable[:scaling_factor].to_f end if variable[:objective_function_group] @logger.info "Found objective function group for #{variable[:name]}" @objective_functions["objective_function_group_#{variable[:objective_function_index] + 1}"] = variable[:objective_function_group].to_f end else @logger.warn "No results for objective function #{variable[:name]}" @objective_functions["objective_function_#{variable[:objective_function_index] + 1}"] = Float::MAX @objective_functions["objective_function_target_#{variable[:objective_function_index] + 1}"] = nil @objective_functions["scaling_factor_#{variable[:objective_function_index] + 1}"] = nil @objective_functions["objective_function_group_#{variable[:objective_function_index] + 1}"] = nil end else # variable name is not nested with the '.' -- this is for legacy purposes and should be deleted on 9/30/2014 if @results[variable[:name]] @objective_functions["objective_function_#{variable[:objective_function_index] + 1}"] = @results[k.to_sym][v.to_sym] if variable[:objective_function_target] @logger.info "Found objective function target for #{variable[:name]}" @objective_functions["objective_function_target_#{variable[:objective_function_index] + 1}"] = variable[:objective_function_target].to_f end if variable[:scaling_factor] @logger.info "Found scaling factor for #{variable[:name]}" @objective_functions["scaling_factor_#{variable[:objective_function_index] + 1}"] = variable[:scaling_factor].to_f end if variable[:objective_function_group] @logger.info "Found objective function group for #{variable[:name]}" @objective_functions["objective_function_group_#{variable[:objective_function_index] + 1}"] = variable[:objective_function_group].to_f end else @logger.warn "No results for objective function #{variable[:name]}" @objective_functions["objective_function_#{variable[:objective_function_index] + 1}"] = Float::MAX @objective_functions["objective_function_target_#{variable[:objective_function_index] + 1}"] = nil @objective_functions["scaling_factor_#{variable[:objective_function_index] + 1}"] = nil @objective_functions["objective_function_group_#{variable[:objective_function_index] + 1}"] = nil end end end end end end |
#sql_query(sql, report_name, query) ⇒ Object
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/openstudio/workflow/jobs/run_reporting_measures/run_reporting_measures.rb', line 245 def sql_query(sql, report_name, query) val = nil result = sql.execAndReturnFirstDouble("SELECT Value FROM TabularDataWithStrings WHERE ReportName='#{report_name}' AND #{query}") if result.empty? @logger.warn "Query for run_monthly_postprocess failed for #{query}" else begin val = result.get rescue => e @logger.info "#{__FILE__} failed with #{e.message}, #{e.backtrace.join("\n")}" val = nil end end val end |