Class: StandardReports
- Inherits:
-
OpenStudio::Ruleset::ReportingUserScript
- Object
- OpenStudio::Ruleset::ReportingUserScript
- StandardReports
- Defined in:
- lib/openstudio/workflow/jobs/run_reporting_measures/packaged_measures/StandardReports/measure.rb
Overview
start the measure
Instance Method Summary collapse
-
#arguments ⇒ Object
define the arguments that the user will input.
-
#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.
-
#sql_query(sql, report_name, query) ⇒ Object
sql_query method.
Instance Method Details
#arguments ⇒ Object
define the arguments that the user will input
13 14 15 16 17 |
# File 'lib/openstudio/workflow/jobs/run_reporting_measures/packaged_measures/StandardReports/measure.rb', line 13 def arguments args = OpenStudio::Ruleset::OSArgumentVector.new args 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
8 9 10 |
# File 'lib/openstudio/workflow/jobs/run_reporting_measures/packaged_measures/StandardReports/measure.rb', line 8 def name 'Standard Reports' end |
#run(runner, user_arguments) ⇒ Object
define what happens when the measure is run
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 55 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 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 |
# File 'lib/openstudio/workflow/jobs/run_reporting_measures/packaged_measures/StandardReports/measure.rb', line 30 def run(runner, user_arguments) super(runner, user_arguments) # use the built-in error checking unless runner.validateUserArguments(arguments, user_arguments) return false end os_version = OpenStudio::VersionString.new(OpenStudio.openStudioVersion) min_version_feature1 = OpenStudio::VersionString.new('1.2.3') # 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) # put data into variables, these are available in the local scope binding # building_name = model.getBuilding.name.get web_asset_path = OpenStudio.getSharedResourcesPath / OpenStudio::Path.new('web_assets') energy = "var consumption = {\n" fuel_type = '' units = '' site_energy_use = 0.0 OpenStudio::EndUseFuelType.getValues.each do |fuel_type| energy << "\t\"" fuel_type = OpenStudio::EndUseFuelType.new(fuel_type).valueDescription energy << OpenStudio::EndUseFuelType.new(fuel_type).valueDescription # append this to remove whitespace between words ".delete(' ')" energy << " Consumption\":{\n\t\t\"units\":" if fuel_type == 'Electricity' units = "\"kWh\"" unit_str = 'kWh' else units = "\"Million Btu\"" unit_str = 'MBtu' end fuel_type_aggregation = 0.0 energy << units energy << ",\n\t\t\"data\":{\n\t\t\t\"" OpenStudio::EndUseCategoryType.getValues.each do |category_type| fuel_and_category_aggregation = 0.0 category_str = OpenStudio::EndUseCategoryType.new(category_type).valueDescription energy << category_str # append this to remove whitespace between words ".delete(' ')" energy << "\":[" OpenStudio::MonthOfYear.getValues.each do |month| if month >= 1 and month <= 12 if not sqlFile.energyConsumptionByMonth(OpenStudio::EndUseFuelType.new(fuel_type), OpenStudio::EndUseCategoryType.new(category_type), OpenStudio::MonthOfYear.new(month)).empty? valInJ = sqlFile.energyConsumptionByMonth(OpenStudio::EndUseFuelType.new(fuel_type), OpenStudio::EndUseCategoryType.new(category_type), OpenStudio::MonthOfYear.new(month)).get fuel_and_category_aggregation += valInJ valInUnits = OpenStudio.convert(valInJ, 'J', unit_str).get temp = sprintf '%.3f', valInUnits energy << temp.to_s energy << ',' if os_version >= min_version_feature1 month_str = OpenStudio::MonthOfYear.new(month).valueDescription prefix_str = OpenStudio.toUnderscoreCase("#{fuel_type}_#{category_str}_#{month_str}") runner.registerValue("#{prefix_str}_si", valInJ, 'J') runner.registerValue("#{prefix_str}_ip", valInUnits, unit_str) end else energy << '0,' end end end energy = energy[0..-2] energy << "],\n\t\t\t\"" if (os_version >= min_version_feature1) prefix_str = OpenStudio.toUnderscoreCase("#{fuel_type}_#{category_str}") runner.registerValue("#{prefix_str}_si", fuel_and_category_aggregation, 'J') runner.registerValue("#{prefix_str}_ip", OpenStudio.convert(fuel_and_category_aggregation, 'J', unit_str).get, unit_str) end fuel_type_aggregation += fuel_and_category_aggregation end energy = energy[0..-7] energy << "\n\t\t}\n\t},\n" if (os_version >= min_version_feature1) runner.registerValue(OpenStudio.toUnderscoreCase("#{fuel_type}_si"), fuel_type_aggregation, 'J') runner.registerValue(OpenStudio.toUnderscoreCase("#{fuel_type}_ip"), OpenStudio.convert(fuel_type_aggregation, 'J', unit_str).get, unit_str) end site_energy_use += fuel_type_aggregation end energy = energy[0..-3] energy << "\n};\n" if (os_version >= min_version_feature1) runner.registerValue('site_energy_use_si', OpenStudio.convert(site_energy_use, 'J', 'GJ').get, 'GJ') runner.registerValue('site_energy_use_ip', OpenStudio.convert(site_energy_use, 'J', 'MBtu').get, 'MBtu') # queries that don't have API methods yet total_building_area = sql_query(sqlFile, 'AnnualBuildingUtilityPerformanceSummary', "TableName='Building Area' AND RowName='Total Building Area' AND ColumnName='Area'") runner.registerValue('total_building_area', total_building_area, 'm2') net_conditioned_building_area = sql_query(sqlFile, 'AnnualBuildingUtilityPerformanceSummary', "TableName='Building Area' AND RowName='Net Conditioned Building Area' AND ColumnName='Area'") runner.registerValue('net_conditioned_building_area', net_conditioned_building_area, 'm2') unconditioned_building_area = sql_query(sqlFile, 'AnnualBuildingUtilityPerformanceSummary', "TableName='Building Area' AND RowName='Unconditioned Building Area' AND ColumnName='Area'") runner.registerValue('unconditioned_building_area', unconditioned_building_area, 'm2') total_site_energy_eui = sql_query(sqlFile, 'AnnualBuildingUtilityPerformanceSummary', "TableName='Site and Source Energy' AND RowName='Total Site Energy' AND ColumnName='Energy Per Conditioned Building Area'") runner.registerValue('total_site_energy_eui', total_site_energy_eui, 'MJ/m2') total_source_energy_eui = sql_query(sqlFile, 'AnnualBuildingUtilityPerformanceSummary', "TableName='Site and Source Energy' AND RowName='Total Source Energy' AND ColumnName='Energy Per Conditioned Building Area'") runner.registerValue('total_source_energy_eui', total_source_energy_eui, 'MJ/m2') time_setpoint_not_met_during_occupied_heating = sql_query(sqlFile, 'AnnualBuildingUtilityPerformanceSummary', "TableName='Comfort and Setpoint Not Met Summary' AND RowName='Time Setpoint Not Met During Occupied Heating' AND ColumnName='Facility'") runner.registerValue('time_setpoint_not_met_during_occupied_heating', time_setpoint_not_met_during_occupied_heating, 'hr') time_setpoint_not_met_during_occupied_cooling = sql_query(sqlFile, 'AnnualBuildingUtilityPerformanceSummary', "TableName='Comfort and Setpoint Not Met Summary' AND RowName='Time Setpoint Not Met During Occupied Cooling' AND ColumnName='Facility'") runner.registerValue('time_setpoint_not_met_during_occupied_cooling', time_setpoint_not_met_during_occupied_cooling, 'hr') time_setpoint_not_met_during_occupied_hours = time_setpoint_not_met_during_occupied_heating + time_setpoint_not_met_during_occupied_cooling runner.registerValue('time_setpoint_not_met_during_occupied_hours', time_setpoint_not_met_during_occupied_hours, 'hr') total_life_cycle_cost = sql_query(sqlFile, 'Life-Cycle Cost Report', "TableName='Present Value by Category' AND RowName='Grand Total' AND ColumnName='Present Value'") runner.registerValue('total_life_cycle_cost', total_life_cycle_cost, '$') end # echo out our values # runner.registerInfo("This building is named #{building_name}.") # read in template html_in_path = "#{File.dirname(__FILE__)}/resources/report.html.erb" if File.exist?(html_in_path) html_in_path = html_in_path else html_in_path = "#{File.dirname(__FILE__)}/report.html.erb" end # configure template with variable values renderer = ERB.new(File.read(html_in_path)) html_out = renderer.result(binding) # write html file html_out_path = './report.html' File.open(html_out_path, 'w') do |file| file << html_out # make sure data is written to the disk one way or the other begin file.fsync rescue file.flush end end # closing the sql file sqlFile.close # reporting final condition runner.registerFinalCondition('Standard Report generated successfully.') true end |
#sql_query(sql, report_name, query) ⇒ Object
sql_query method
20 21 22 23 24 25 26 27 |
# File 'lib/openstudio/workflow/jobs/run_reporting_measures/packaged_measures/StandardReports/measure.rb', line 20 def sql_query(sql, report_name, query) val = 10e9 result = sql.execAndReturnFirstDouble("SELECT Value FROM TabularDataWithStrings WHERE ReportName='#{report_name}' AND #{query}") unless result.empty? val = result.get end val end |