Class: URBANopt::Reporting::DefaultReports::EndUses
- Inherits:
-
Object
- Object
- URBANopt::Reporting::DefaultReports::EndUses
- Defined in:
- lib/urbanopt/reporting/default_reports/end_uses.rb
Overview
Enduses class include results for each fuel type.
Instance Attribute Summary collapse
-
#district_cooling_kwh ⇒ Object
:nodoc:.
-
#district_heating_kwh ⇒ Object
:nodoc:.
-
#electricity_kwh ⇒ Object
:nodoc:.
-
#fuel_oil_kwh ⇒ Object
:nodoc:.
-
#natural_gas_kwh ⇒ Object
:nodoc:.
-
#other_fuels_kwh ⇒ Object
:nodoc:.
-
#propane_kwh ⇒ Object
:nodoc:.
-
#water_qbft ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#defaults ⇒ Object
Assigns default values if values do not exist.
-
#initialize(hash = {}) ⇒ EndUses
constructor
EndUses class initialize end_uses(fuel type) attributes:
:electricity_kwh
,:natural_gas_kwh
,:propane_kwh
,:fuel_oil_kwh
,:other_fuels_kwh
,:district_cooling_kwh
,:district_heating_kwh
,:water_qbft
. -
#merge_end_uses!(new_end_uses) ⇒ Object
Aggregates the values of each EndUse attribute.
-
#to_hash ⇒ Object
Converts to a Hash equivalent for JSON serialization.
Constructor Details
#initialize(hash = {}) ⇒ EndUses
EndUses class initialize end_uses(fuel type) attributes: :electricity_kwh
, :natural_gas_kwh
, :propane_kwh
, :fuel_oil_kwh
, :other_fuels_kwh
, :district_cooling_kwh
, :district_heating_kwh
, :water_qbft
- parameters:
-
hash
- Hash - A hash which may contain a deserialized end_uses.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/urbanopt/reporting/default_reports/end_uses.rb', line 26 def initialize(hash = {}) hash.delete_if { |k, v| v.nil? } hash = defaults.merge(hash) @electricity_kwh = EndUse.new(hash[:electricity_kwh]) @natural_gas_kwh = EndUse.new(hash[:natural_gas_kwh]) @propane_kwh = EndUse.new(hash[:propane_kwh]) @fuel_oil_kwh = EndUse.new(hash[:fuel_oil_kwh]) @other_fuels_kwh = EndUse.new(hash[:other_fuels_kwh]) @district_cooling_kwh = EndUse.new(hash[:district_cooling_kwh]) @district_heating_kwh = EndUse.new(hash[:district_heating_kwh]) @water_qbft = EndUse.new(hash[:water_qbft]) # initialize class variables @@validator and @@schema @@validator ||= Validator.new @@schema ||= @@validator.schema end |
Instance Attribute Details
#district_cooling_kwh ⇒ Object
:nodoc:
17 18 19 |
# File 'lib/urbanopt/reporting/default_reports/end_uses.rb', line 17 def district_cooling_kwh @district_cooling_kwh end |
#district_heating_kwh ⇒ Object
:nodoc:
17 18 19 |
# File 'lib/urbanopt/reporting/default_reports/end_uses.rb', line 17 def district_heating_kwh @district_heating_kwh end |
#electricity_kwh ⇒ Object
:nodoc:
17 18 19 |
# File 'lib/urbanopt/reporting/default_reports/end_uses.rb', line 17 def electricity_kwh @electricity_kwh end |
#fuel_oil_kwh ⇒ Object
:nodoc:
17 18 19 |
# File 'lib/urbanopt/reporting/default_reports/end_uses.rb', line 17 def fuel_oil_kwh @fuel_oil_kwh end |
#natural_gas_kwh ⇒ Object
:nodoc:
17 18 19 |
# File 'lib/urbanopt/reporting/default_reports/end_uses.rb', line 17 def natural_gas_kwh @natural_gas_kwh end |
#other_fuels_kwh ⇒ Object
:nodoc:
17 18 19 |
# File 'lib/urbanopt/reporting/default_reports/end_uses.rb', line 17 def other_fuels_kwh @other_fuels_kwh end |
#propane_kwh ⇒ Object
:nodoc:
17 18 19 |
# File 'lib/urbanopt/reporting/default_reports/end_uses.rb', line 17 def propane_kwh @propane_kwh end |
#water_qbft ⇒ Object
:nodoc:
17 18 19 |
# File 'lib/urbanopt/reporting/default_reports/end_uses.rb', line 17 def water_qbft @water_qbft end |
Instance Method Details
#defaults ⇒ Object
Assigns default values if values do not exist.
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/urbanopt/reporting/default_reports/end_uses.rb', line 96 def defaults hash = {} hash[:electricity_kwh] = EndUse.new.to_hash hash[:natural_gas_kwh] = EndUse.new.to_hash hash[:propane_kwh] = EndUse.new.to_hash hash[:fuel_oil_kwh] = EndUse.new.to_hash hash[:other_fuels_kwh] = EndUse.new.to_hash hash[:district_cooling_kwh] = EndUse.new.to_hash hash[:district_heating_kwh] = EndUse.new.to_hash hash[:water_qbft] = EndUse.new.to_hash return hash end |
#merge_end_uses!(new_end_uses) ⇒ Object
Aggregates the values of each EndUse attribute.
- Parameters:
-
new_end_uses
- EndUses - An object of EndUses class.
116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/urbanopt/reporting/default_reports/end_uses.rb', line 116 def merge_end_uses!(new_end_uses) # modify the existing_period by summing up the results ; # sum results only if they exist @electricity_kwh.merge_end_use!(new_end_uses.electricity_kwh) @natural_gas_kwh.merge_end_use!(new_end_uses.natural_gas_kwh) @propane_kwh.merge_end_use!(new_end_uses.propane_kwh) @fuel_oil_kwh.merge_end_use!(new_end_uses.fuel_oil_kwh) @other_fuels_kwh.merge_end_use!(new_end_uses.other_fuels_kwh) @district_cooling_kwh.merge_end_use!(new_end_uses.district_cooling_kwh) @district_heating_kwh.merge_end_use!(new_end_uses.district_heating_kwh) return self end |
#to_hash ⇒ Object
Converts to a Hash equivalent for JSON serialization.
-
Exclude attributes with nil values.
-
Validate end_uses hash properties against schema.
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 |
# File 'lib/urbanopt/reporting/default_reports/end_uses.rb', line 50 def to_hash result = {} electricity_kwh_hash = @electricity_kwh.to_hash if @electricity_kwh electricity_kwh_hash.delete_if { |k, v| v.nil? } result[:electricity_kwh] = electricity_kwh_hash if @electricity_kwh natural_gas_kwh_hash = @natural_gas_kwh.to_hash if @natural_gas_kwh natural_gas_kwh_hash.delete_if { |k, v| v.nil? } result[:natural_gas_kwh] = natural_gas_kwh_hash if @natural_gas_kwh propane_kwh_hash = @propane_kwh.to_hash if @propane_kwh propane_kwh_hash.delete_if { |k, v| v.nil? } result[:propane_kwh] = propane_kwh_hash if @propane_kwh fuel_oil_kwh_hash = @fuel_oil_kwh.to_hash if @fuel_oil_kwh fuel_oil_kwh_hash.delete_if { |k, v| v.nil? } result[:fuel_oil_kwh] = fuel_oil_kwh_hash if @fuel_oil_kwh other_fuels_kwh_hash = @other_fuels_kwh.to_hash if @other_fuels_kwh other_fuels_kwh_hash.delete_if { |k, v| v.nil? } result[:other_fuels_kwh] = other_fuels_kwh_hash if @other_fuels_kwh district_cooling_kwh_hash = @district_cooling_kwh.to_hash if @district_cooling_kwh district_cooling_kwh_hash.delete_if { |k, v| v.nil? } result[:district_cooling_kwh] = district_cooling_kwh_hash if @district_cooling_kwh district_heating_kwh_hash = @district_heating_kwh.to_hash if @district_heating_kwh district_heating_kwh_hash.delete_if { |k, v| v.nil? } result[:district_heating_kwh] = district_heating_kwh_hash if @district_heating_kwh water_qbft_hash = @water_qbft.to_hash if @water_qbft water_qbft_hash.delete_if { |k, v| v.nil? } result[:water_qbft] = water_qbft_hash if @water_qbft # validate end_uses properties against schema if @@validator.validate(@@schema[:definitions][:EndUses][:properties], result).any? raise "end_uses properties does not match schema: #{@@validator.validate(@@schema[:definitions][:EndUses][:properties], result)}" end return result end |