Class: URBANopt::Reporting::DefaultReports::ReportingPeriod
- Inherits:
-
Object
- Object
- URBANopt::Reporting::DefaultReports::ReportingPeriod
- Defined in:
- lib/urbanopt/reporting/default_reports/reporting_period.rb
Overview
ReportingPeriod includes all the results of a specific reporting period.
Instance Attribute Summary collapse
-
#comfort_result ⇒ Object
Returns the value of attribute comfort_result.
-
#day_of_month ⇒ Object
Returns the value of attribute day_of_month.
-
#demand_cost_dollar ⇒ Object
Returns the value of attribute demand_cost_dollar.
-
#district_cooling_kwh ⇒ Object
Returns the value of attribute district_cooling_kwh.
-
#district_heating_kwh ⇒ Object
Returns the value of attribute district_heating_kwh.
-
#electricity_kwh ⇒ Object
Returns the value of attribute electricity_kwh.
-
#electricity_produced_kwh ⇒ Object
Returns the value of attribute electricity_produced_kwh.
-
#end_date ⇒ Object
Returns the value of attribute end_date.
-
#end_uses ⇒ Object
Returns the value of attribute end_uses.
-
#energy_production_kwh ⇒ Object
Returns the value of attribute energy_production_kwh.
-
#fuel_oil_kwh ⇒ Object
Returns the value of attribute fuel_oil_kwh.
-
#fuel_type ⇒ Object
Returns the value of attribute fuel_type.
-
#hours_out_of_comfort_bounds_PMV ⇒ Object
Returns the value of attribute hours_out_of_comfort_bounds_PMV.
-
#hours_out_of_comfort_bounds_PPD ⇒ Object
Returns the value of attribute hours_out_of_comfort_bounds_PPD.
-
#id ⇒ Object
Returns the value of attribute id.
-
#month ⇒ Object
Returns the value of attribute month.
-
#multiplier ⇒ Object
Returns the value of attribute multiplier.
-
#name ⇒ Object
Returns the value of attribute name.
-
#natural_gas_kwh ⇒ Object
Returns the value of attribute natural_gas_kwh.
-
#net_site_energy_kwh ⇒ Object
Returns the value of attribute net_site_energy_kwh.
-
#net_source_energy_kwh ⇒ Object
Returns the value of attribute net_source_energy_kwh.
-
#net_utility_cost_dollar ⇒ Object
Returns the value of attribute net_utility_cost_dollar.
-
#other_fuels_kwh ⇒ Object
Returns the value of attribute other_fuels_kwh.
-
#photovoltaic ⇒ Object
Returns the value of attribute photovoltaic.
-
#propane_kwh ⇒ Object
Returns the value of attribute propane_kwh.
-
#site_EUI_kbtu_per_ft2 ⇒ Object
Returns the value of attribute site_EUI_kbtu_per_ft2.
-
#site_EUI_kwh_per_m2 ⇒ Object
Returns the value of attribute site_EUI_kwh_per_m2.
-
#source_EUI_kbtu_per_ft2 ⇒ Object
Returns the value of attribute source_EUI_kbtu_per_ft2.
-
#source_EUI_kwh_per_m2 ⇒ Object
Returns the value of attribute source_EUI_kwh_per_m2.
-
#start_date ⇒ Object
Returns the value of attribute start_date.
-
#time_setpoint_not_met_during_occupied_cooling ⇒ Object
Returns the value of attribute time_setpoint_not_met_during_occupied_cooling.
-
#time_setpoint_not_met_during_occupied_heating ⇒ Object
Returns the value of attribute time_setpoint_not_met_during_occupied_heating.
-
#time_setpoint_not_met_during_occupied_hours ⇒ Object
Returns the value of attribute time_setpoint_not_met_during_occupied_hours.
-
#total_cost_dollar ⇒ Object
Returns the value of attribute total_cost_dollar.
-
#total_site_energy_kwh ⇒ Object
Returns the value of attribute total_site_energy_kwh.
-
#total_source_energy_kwh ⇒ Object
Returns the value of attribute total_source_energy_kwh.
-
#total_utility_cost_dollar ⇒ Object
Returns the value of attribute total_utility_cost_dollar.
-
#usage_cost_dollar ⇒ Object
Returns the value of attribute usage_cost_dollar.
-
#utility_costs_dollar ⇒ Object
Returns the value of attribute utility_costs_dollar.
-
#water_qbft ⇒ Object
Returns the value of attribute water_qbft.
-
#year ⇒ Object
Returns the value of attribute year.
Class Method Summary collapse
-
.add_values(existing_value, new_value) ⇒ Object
Adds up
existing_valueandnew_valuesif not nill. -
.merge_reporting_period(existing_period, new_period) ⇒ Object
Merges an
existing_periodwith anew_periodif not nil. -
.merge_reporting_periods(existing_periods, new_periods) ⇒ Object
Merges multiple reporting periods together.
Instance Method Summary collapse
-
#defaults ⇒ Object
Assigns default values if values do not exist.
-
#initialize(hash = {}) ⇒ ReportingPeriod
constructor
ReportingPeriod class initializes the reporting period attributes:
:id,:name,:multiplier,:start_date,:end_date,:month,:day_of_month,:year,:total_site_energy_kwh,:total_source_energy_kwh,:site_EUI_kwh_per_m2,:site_EUI_kbtu_per_ft2,:source_EUI_kwh_per_m2,:source_EUI_kbtu_per_ft2,:net_site_energy_kwh,:net_source_energy_kwh, +:total_utility_cost_dollar ,:net_utility_cost_dollar,:utility_costs_dollar,:electricity_kwh,:natural_gas_kwh,:propane_kwh,:fuel_oil_kwh,:other_fuels_kwh,:district_cooling_kwh,:district_heating_kwh,:water_qbft,:electricity_produced_kwh,:end_uses,:energy_production_kwh,:photovoltaic_kwh,:fuel_type,:total_cost_dollar,:usage_cost_dollar,:demand_cost_dollar,:comfort_result,:time_setpoint_not_met_during_occupied_cooling,:time_setpoint_not_met_during_occupied_heating,:time_setpoint_not_met_during_occupied_hours. -
#to_hash ⇒ Object
Converts to a Hash equivalent for JSON serialization.
Constructor Details
#initialize(hash = {}) ⇒ ReportingPeriod
ReportingPeriod class initializes the reporting period attributes: :id , :name , :multiplier , :start_date , :end_date , :month , :day_of_month , :year , :total_site_energy_kwh , :total_source_energy_kwh , :site_EUI_kwh_per_m2, :site_EUI_kbtu_per_ft2, :source_EUI_kwh_per_m2, :source_EUI_kbtu_per_ft2, :net_site_energy_kwh , :net_source_energy_kwh , +:total_utility_cost_dollar , :net_utility_cost_dollar , :utility_costs_dollar , :electricity_kwh , :natural_gas_kwh , :propane_kwh , :fuel_oil_kwh , :other_fuels_kwh , :district_cooling_kwh , :district_heating_kwh , :water_qbft , :electricity_produced_kwh , :end_uses , :energy_production_kwh , :photovoltaic_kwh , :fuel_type , :total_cost_dollar , :usage_cost_dollar , :demand_cost_dollar , :comfort_result , :time_setpoint_not_met_during_occupied_cooling , :time_setpoint_not_met_during_occupied_heating , :time_setpoint_not_met_during_occupied_hours
- parameters:
-
hash- Hash - A hash which may contain a deserialized reporting_period.
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 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 61 def initialize(hash = {}) hash.delete_if { |k, v| v.nil? } hash = defaults.merge(hash) @id = hash[:id] @name = hash[:name] @multiplier = hash[:multiplier] @start_date = Date.new(hash[:start_date]) @end_date = Date.new(hash[:end_date]) @total_site_energy_kwh = hash[:total_site_energy_kwh] @total_source_energy_kwh = hash[:total_source_energy_kwh] @site_EUI_kwh_per_m2 = hash[:site_EUI_kwh_per_m2] @site_EUI_kbtu_per_ft2 = hash[:site_EUI_kbtu_per_ft2] @source_EUI_kwh_per_m2 = hash[:source_EUI_kwh_per_m2] @source_EUI_kbtu_per_ft2 = hash[:source_EUI_kbtu_per_ft2] @net_site_energy_kwh = hash[:net_site_energy_kwh] @net_source_energy_kwh = hash[:net_source_energy_kwh] @net_utility_cost_dollar = hash[:net_utility_cost_dollar] @total_utility_cost_dollar = hash[:total_utility_cost_dollar] @electricity_kwh = hash[:electricity_kwh] @natural_gas_kwh = hash[:natural_gas_kwh] @propane_kwh = hash[:propane_kwh] @fuel_oil_kwh = hash[:fuel_oil_kwh] @other_fuels_kwh = hash[:other_fuels_kwh] @district_cooling_kwh = hash[:district_cooling_kwh] @district_heating_kwh = hash[:district_heating_kwh] @water_qbft = hash[:water_qbft] @electricity_produced_kwh = hash[:electricity_produced_kwh] @end_uses = EndUses.new(hash[:end_uses]) @energy_production_kwh = hash[:energy_production_kwh] @utility_costs_dollar = hash[:utility_costs_dollar] @comfort_result = hash[:comfort_result] # initialize class variables @@validator and @@schema @@validator ||= Validator.new @@schema ||= @@validator.schema end |
Instance Attribute Details
#comfort_result ⇒ Object
Returns the value of attribute comfort_result.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def comfort_result @comfort_result end |
#day_of_month ⇒ Object
Returns the value of attribute day_of_month.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def day_of_month @day_of_month end |
#demand_cost_dollar ⇒ Object
Returns the value of attribute demand_cost_dollar.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def demand_cost_dollar @demand_cost_dollar end |
#district_cooling_kwh ⇒ Object
Returns the value of attribute district_cooling_kwh.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def district_cooling_kwh @district_cooling_kwh end |
#district_heating_kwh ⇒ Object
Returns the value of attribute district_heating_kwh.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def district_heating_kwh @district_heating_kwh end |
#electricity_kwh ⇒ Object
Returns the value of attribute electricity_kwh.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def electricity_kwh @electricity_kwh end |
#electricity_produced_kwh ⇒ Object
Returns the value of attribute electricity_produced_kwh.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def electricity_produced_kwh @electricity_produced_kwh end |
#end_date ⇒ Object
Returns the value of attribute end_date.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def end_date @end_date end |
#end_uses ⇒ Object
Returns the value of attribute end_uses.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def end_uses @end_uses end |
#energy_production_kwh ⇒ Object
Returns the value of attribute energy_production_kwh.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def energy_production_kwh @energy_production_kwh end |
#fuel_oil_kwh ⇒ Object
Returns the value of attribute fuel_oil_kwh.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def fuel_oil_kwh @fuel_oil_kwh end |
#fuel_type ⇒ Object
Returns the value of attribute fuel_type.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def fuel_type @fuel_type end |
#hours_out_of_comfort_bounds_PMV ⇒ Object
Returns the value of attribute hours_out_of_comfort_bounds_PMV.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def hours_out_of_comfort_bounds_PMV @hours_out_of_comfort_bounds_PMV end |
#hours_out_of_comfort_bounds_PPD ⇒ Object
Returns the value of attribute hours_out_of_comfort_bounds_PPD.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def hours_out_of_comfort_bounds_PPD @hours_out_of_comfort_bounds_PPD end |
#id ⇒ Object
Returns the value of attribute id.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def id @id end |
#month ⇒ Object
Returns the value of attribute month.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def month @month end |
#multiplier ⇒ Object
Returns the value of attribute multiplier.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def multiplier @multiplier end |
#name ⇒ Object
Returns the value of attribute name.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def name @name end |
#natural_gas_kwh ⇒ Object
Returns the value of attribute natural_gas_kwh.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def natural_gas_kwh @natural_gas_kwh end |
#net_site_energy_kwh ⇒ Object
Returns the value of attribute net_site_energy_kwh.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def net_site_energy_kwh @net_site_energy_kwh end |
#net_source_energy_kwh ⇒ Object
Returns the value of attribute net_source_energy_kwh.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def net_source_energy_kwh @net_source_energy_kwh end |
#net_utility_cost_dollar ⇒ Object
Returns the value of attribute net_utility_cost_dollar.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def net_utility_cost_dollar @net_utility_cost_dollar end |
#other_fuels_kwh ⇒ Object
Returns the value of attribute other_fuels_kwh.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def other_fuels_kwh @other_fuels_kwh end |
#photovoltaic ⇒ Object
Returns the value of attribute photovoltaic.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def photovoltaic @photovoltaic end |
#propane_kwh ⇒ Object
Returns the value of attribute propane_kwh.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def propane_kwh @propane_kwh end |
#site_EUI_kbtu_per_ft2 ⇒ Object
Returns the value of attribute site_EUI_kbtu_per_ft2.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def site_EUI_kbtu_per_ft2 @site_EUI_kbtu_per_ft2 end |
#site_EUI_kwh_per_m2 ⇒ Object
Returns the value of attribute site_EUI_kwh_per_m2.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def site_EUI_kwh_per_m2 @site_EUI_kwh_per_m2 end |
#source_EUI_kbtu_per_ft2 ⇒ Object
Returns the value of attribute source_EUI_kbtu_per_ft2.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def source_EUI_kbtu_per_ft2 @source_EUI_kbtu_per_ft2 end |
#source_EUI_kwh_per_m2 ⇒ Object
Returns the value of attribute source_EUI_kwh_per_m2.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def source_EUI_kwh_per_m2 @source_EUI_kwh_per_m2 end |
#start_date ⇒ Object
Returns the value of attribute start_date.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def start_date @start_date end |
#time_setpoint_not_met_during_occupied_cooling ⇒ Object
Returns the value of attribute time_setpoint_not_met_during_occupied_cooling.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def time_setpoint_not_met_during_occupied_cooling @time_setpoint_not_met_during_occupied_cooling end |
#time_setpoint_not_met_during_occupied_heating ⇒ Object
Returns the value of attribute time_setpoint_not_met_during_occupied_heating.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def time_setpoint_not_met_during_occupied_heating @time_setpoint_not_met_during_occupied_heating end |
#time_setpoint_not_met_during_occupied_hours ⇒ Object
Returns the value of attribute time_setpoint_not_met_during_occupied_hours.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def time_setpoint_not_met_during_occupied_hours @time_setpoint_not_met_during_occupied_hours end |
#total_cost_dollar ⇒ Object
Returns the value of attribute total_cost_dollar.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def total_cost_dollar @total_cost_dollar end |
#total_site_energy_kwh ⇒ Object
Returns the value of attribute total_site_energy_kwh.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def total_site_energy_kwh @total_site_energy_kwh end |
#total_source_energy_kwh ⇒ Object
Returns the value of attribute total_source_energy_kwh.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def total_source_energy_kwh @total_source_energy_kwh end |
#total_utility_cost_dollar ⇒ Object
Returns the value of attribute total_utility_cost_dollar.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def total_utility_cost_dollar @total_utility_cost_dollar end |
#usage_cost_dollar ⇒ Object
Returns the value of attribute usage_cost_dollar.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def usage_cost_dollar @usage_cost_dollar end |
#utility_costs_dollar ⇒ Object
Returns the value of attribute utility_costs_dollar.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def utility_costs_dollar @utility_costs_dollar end |
#water_qbft ⇒ Object
Returns the value of attribute water_qbft.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def water_qbft @water_qbft end |
#year ⇒ Object
Returns the value of attribute year.
46 47 48 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 46 def year @year end |
Class Method Details
.add_values(existing_value, new_value) ⇒ Object
Adds up existing_value and new_values if not nill.
- parameter:
-
existing_value- Float - A value corresponding to a ReportingPeriod attribute.new_value- Float - A value corresponding to a ReportingPeriod attribute.
213 214 215 216 217 218 219 220 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 213 def self.add_values(existing_value, new_value) if existing_value && new_value existing_value += new_value elsif new_value existing_value = new_value end return existing_value end |
.merge_reporting_period(existing_period, new_period) ⇒ Object
Merges an existing_period with a new_period if not nil.
- Parameters:
-
existing_period- ReportingPeriod - An object of ReportingPeriod class.new_period- ReportingPeriod - An object of ReportingPeriod class.
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 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 230 def self.merge_reporting_period(existing_period, new_period) # modify the existing_period by summing up the results existing_period.total_site_energy_kwh = add_values(existing_period.total_site_energy_kwh, new_period.total_site_energy_kwh) existing_period.total_source_energy_kwh = add_values(existing_period.total_source_energy_kwh, new_period.total_source_energy_kwh) existing_period.net_source_energy_kwh = add_values(existing_period.net_source_energy_kwh, new_period.net_source_energy_kwh) existing_period.net_utility_cost_dollar = add_values(existing_period.net_utility_cost_dollar, new_period.net_utility_cost_dollar) existing_period.total_utility_cost_dollar = add_values(existing_period.total_utility_cost_dollar, new_period.total_utility_cost_dollar) existing_period.electricity_kwh = add_values(existing_period.electricity_kwh, new_period.electricity_kwh) existing_period.natural_gas_kwh = add_values(existing_period.natural_gas_kwh, new_period.natural_gas_kwh) existing_period.propane_kwh = add_values(existing_period.propane_kwh, new_period.propane_kwh) existing_period.fuel_oil_kwh = add_values(existing_period.fuel_oil_kwh, new_period.fuel_oil_kwh) existing_period.other_fuels_kwh = add_values(existing_period.other_fuels_kwh, new_period.other_fuels_kwh) existing_period.district_cooling_kwh = add_values(existing_period.district_cooling_kwh, new_period.district_cooling_kwh) existing_period.district_heating_kwh = add_values(existing_period.district_heating_kwh, new_period.district_heating_kwh) existing_period.water_qbft = add_values(existing_period.water_qbft, new_period.water_qbft) existing_period.electricity_produced_kwh = add_values(existing_period.electricity_produced_kwh, new_period.electricity_produced_kwh) # merge end uses new_end_uses = new_period.end_uses existing_period.end_uses&.merge_end_uses!(new_end_uses) if existing_period.energy_production_kwh if existing_period.energy_production_kwh[:electricity_produced_kwh] existing_period.energy_production_kwh[:electricity_produced_kwh][:photovoltaic_kwh] = add_values(existing_period.energy_production_kwh[:electricity_produced][:photovoltaic], new_period.energy_production_kwh[:electricity_produced_kwh][:photovoltaic_kwh]) end end existing_period.utility_costs_dollar&.each_with_index do |item, i| existing_period.utility_costs_dollar[i][:fuel_type] = existing_period.utility_costs_dollar[i][:fuel_type] existing_period.utility_costs_dollar[i][:total_cost] = add_values(existing_period.utility_costs_dollar[i][:total_cost], new_period.utility_costs_dollar[i][:total_cost]) existing_period.utility_costs_dollar[i][:usage_cost] = add_values(existing_period.utility_costs_dollar[i][:usage_cost], new_period.utility_costs_dollar[i][:usage_cost]) existing_period.utility_costs_dollar[i][:demand_cost] = add_values(existing_period.utility_costs_dollar[i][:demand_cost], new_period.utility_costs_dollar[i][:demand_cost]) end if existing_period.comfort_result existing_period.comfort_result[:time_setpoint_not_met_during_occupied_cooling] = add_values(existing_period.comfort_result[:time_setpoint_not_met_during_occupied_cooling], new_period.comfort_result[:time_setpoint_not_met_during_occupied_cooling]) existing_period.comfort_result[:time_setpoint_not_met_during_occupied_heating] = add_values(existing_period.comfort_result[:time_setpoint_not_met_during_occupied_heating], new_period.comfort_result[:time_setpoint_not_met_during_occupied_heating]) existing_period.comfort_result[:time_setpoint_not_met_during_occupied_hours] = add_values(existing_period.comfort_result[:time_setpoint_not_met_during_occupied_hours], new_period.comfort_result[:time_setpoint_not_met_during_occupied_hours]) existing_period.comfort_result[:hours_out_of_comfort_bounds_PMV] = add_values(existing_period.comfort_result[:hours_out_of_comfort_bounds_PMV], new_period.comfort_result[:hours_out_of_comfort_bounds_PMV]) existing_period.comfort_result[:hours_out_of_comfort_bounds_PPD] = add_values(existing_period.comfort_result[:hours_out_of_comfort_bounds_PPD], new_period.comfort_result[:hours_out_of_comfort_bounds_PPD]) end return existing_period end |
.merge_reporting_periods(existing_periods, new_periods) ⇒ Object
Merges multiple reporting periods together.
-
If
existing_periodsandnew_periodsids are equal,
modify the existing_periods by merging the new periods results
-
If existing periods are empty, initialize with new_periods.
-
Raise an error if the existing periods are not identical with new periods (cannot have different reporting period ids).
- parameters:
-
existing_periods- Array - An array of ReportingPeriod objects.new_periods- Array - An array of ReportingPeriod objects.
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 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 288 def self.merge_reporting_periods(existing_periods, new_periods) id_list_existing = [] id_list_new = [] id_list_existing = existing_periods.collect(&:id) id_list_new = new_periods.collect(&:id) if id_list_existing == id_list_new existing_periods.each_index do |index| # if +existing_periods+ and +new_periods+ ids are equal, # modify the existing_periods by merging the new periods results existing_periods[index] = merge_reporting_period(existing_periods[index], new_periods[index]) end elsif existing_periods.empty? # if existing periods are empty, initialize with new_periods # the = operator would link existing_periods and new_periods to the same object in memory # we want to initialize with a deep clone of new_periods existing_periods = Marshal.load(Marshal.dump(new_periods)) else # raise an error if the existing periods are not identical with new periods (cannot have different reporting period ids) raise 'cannot merge different reporting periods' end return existing_periods end |
Instance Method Details
#defaults ⇒ Object
Assigns default values if values do not exist.
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 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 106 def defaults hash = {} hash[:id] = nil hash[:name] = nil hash[:multiplier] = nil hash[:start_date] = Date.new.to_hash hash[:end_date] = Date.new.to_hash hash[:total_site_energy_kwh] = nil hash[:total_source_energy_kwh] = nil hash[:site_EUI_kwh_per_m2] = nil hash[:site_EUI_kbtu_per_ft2] = nil hash[:source_EUI_kwh_per_m2] = nil hash[:source_EUI_kbtu_per_ft2] = nil hash[:net_site_energy_kwh] = nil hash[:net_source_energy_kwh] = nil hash[:net_utility_cost_dollar] = nil hash[:total_utility_cost_dollar] = nil hash[:electricity_kwh] = nil hash[:natural_gas_kwh] = nil hash[:propane_kwh] = nil hash[:fuel_oil_kwh] = nil hash[:other_fuels_kwh] = nil hash[:district_cooling_kwh] = nil hash[:district_heating_kwh] = nil hash[:electricity_produced_kwh] = nil hash[:end_uses] = EndUses.new.to_hash hash[:energy_production_kwh] = { electricity_produced: { photovoltaic: nil } } hash[:utility_costs_dollar] = [{ fuel_type: nil, total_cost_dollar: nil, usage_cost_dollar: nil, demand_cost_dollar: nil }] hash[:comfort_result] = { time_setpoint_not_met_during_occupied_cooling: nil, time_setpoint_not_met_during_occupied_heating: nil, time_setpoint_not_met_during_occupied_hours: nil, hours_out_of_comfort_bounds_PMV: nil, hours_out_of_comfort_bounds_PPD: nil } return hash end |
#to_hash ⇒ Object
Converts to a Hash equivalent for JSON serialization.
-
Exclude attributes with nil values.
-
Validate reporting_period hash properties against schema.
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 |
# File 'lib/urbanopt/reporting/default_reports/reporting_period.rb', line 149 def to_hash result = {} result[:id] = @id if @id result[:name] = @name if @name result[:multiplier] = @multiplier if @multiplier result[:start_date] = @start_date.to_hash if @start_date result[:end_date] = @end_date.to_hash if @end_date result[:total_site_energy_kwh] = @total_site_energy_kwh if @total_site_energy_kwh result[:total_source_energy_kwh] = @total_source_energy_kwh if @total_source_energy_kwh result[:site_EUI_kwh_per_m2] = @site_EUI_kwh_per_m2 if @site_EUI_kwh_per_m2 result[:site_EUI_kbtu_per_ft2] = @site_EUI_kbtu_per_ft2 if @site_EUI_kbtu_per_ft2 result[:source_EUI_kwh_per_m2] = @source_EUI_kwh_per_m2 if @source_EUI_kwh_per_m2 result[:source_EUI_kbtu_per_ft2] = @source_EUI_kbtu_per_ft2 if @source_EUI_kbtu_per_ft2 result[:net_site_energy_kwh] = @net_site_energy_kwh if @net_site_energy_kwh result[:net_source_energy_kwh] = @net_source_energy_kwh if @net_source_energy_kwh result[:net_utility_cost_dollar] = @net_utility_cost_dollar if @net_utility_cost_dollar result[:total_utility_cost_dollar] = @total_utility_cost_dollar if @total_utility_cost_dollar result[:electricity_kwh] = @electricity_kwh if @electricity_kwh result[:natural_gas_kwh] = @natural_gas_kwh if @natural_gas_kwh result[:propane_kwh] = @propane_kwh if @propane_kwh result[:fuel_oil_kwh] = @fuel_oil_kwh if @fuel_oil_kwh result[:other_fuels_kwh] = @other_fuels_kwh if @other_fuels_kwh result[:district_cooling_kwh] = @district_cooling_kwh if @district_cooling_kwh result[:district_heating_kwh] = @district_heating_kwh if @district_heating_kwh result[:water_qbft] = @water_qbft if @water_qbft result[:electricity_produced_kwh] = @electricity_produced_kwh if @electricity_produced_kwh result[:end_uses] = @end_uses.to_hash if @end_uses energy_production_kwh_hash = @energy_production_kwh if @energy_production_kwh energy_production_kwh_hash.delete_if { |k, v| v.nil? } energy_production_kwh_hash.each do |eph| eph.delete_if { |k, v| v.nil? } end result[:energy_production_kwh] = energy_production_kwh_hash if @energy_production_kwh if @utility_costs_dollar.any? result[:utility_costs_dollar] = @utility_costs_dollar @utility_costs_dollar.each do |uc| uc&.delete_if { |k, v| v.nil? } end end comfort_result_hash = @comfort_result if @comfort_result comfort_result_hash.delete_if { |k, v| v.nil? } result[:comfort_result] = comfort_result_hash if @comfort_result # validates +reporting_period+ properties against schema for reporting period. if @@validator.validate(@@schema[:definitions][:ReportingPeriod][:properties], result).any? raise "feature_report properties does not match schema: #{@@validator.validate(@@schema[:definitions][:ReportingPeriod][:properties], result)}" end return result end |