Class: URBANopt::Reporting::DefaultReports::EndUse

Inherits:
Object
  • Object
show all
Defined in:
lib/urbanopt/reporting/default_reports/end_use.rb

Overview

Enduse class all enduse energy consumption results.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ EndUse

EndUse class intialize all enduse atributes: :heating , :cooling , :interior_lighting , :exterior_lighting , :interior_equipment , :exterior_equipment , :fans , :pumps , :heat_rejection , :humidification , :heat_recovery , :water_systems , :refrigeration , :generators

parameters:

hash - Hash - A hash which may contain a deserialized end_use.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/urbanopt/reporting/default_reports/end_use.rb', line 62

def initialize(hash = {})
  hash.delete_if { |k, v| v.nil? }
  hash = defaults.merge(hash)

  @heating = hash[:heating]
  @cooling = hash[:cooling]
  @interior_lighting = hash[:interior_lighting]
  @exterior_lighting = hash[:exterior_lighting]
  @interior_equipment = hash[:interior_equipment]
  @exterior_equipment = hash[:exterior_equipment]
  @electric_vehicles = hash[:electric_vehicles]
  @fans = hash[:fans]
  @pumps = hash[:pumps]
  @heat_rejection = hash[:heat_rejection]
  @humidification = hash[:humidification]
  @heat_recovery = hash[:heat_recovery]
  @water_systems = hash[:water_systems]
  @refrigeration = hash[:refrigeration]
  @generators = hash[:generators]

  # initialize class variables @@validator and @@schema
  @@validator ||= Validator.new
  @@schema ||= @@validator.schema
end

Instance Attribute Details

#coolingObject

Returns the value of attribute cooling.



51
52
53
# File 'lib/urbanopt/reporting/default_reports/end_use.rb', line 51

def cooling
  @cooling
end

#electric_vehiclesObject

Returns the value of attribute electric_vehicles.



51
52
53
# File 'lib/urbanopt/reporting/default_reports/end_use.rb', line 51

def electric_vehicles
  @electric_vehicles
end

#exterior_equipmentObject

Returns the value of attribute exterior_equipment.



51
52
53
# File 'lib/urbanopt/reporting/default_reports/end_use.rb', line 51

def exterior_equipment
  @exterior_equipment
end

#exterior_lightingObject

Returns the value of attribute exterior_lighting.



51
52
53
# File 'lib/urbanopt/reporting/default_reports/end_use.rb', line 51

def exterior_lighting
  @exterior_lighting
end

#fansObject

Returns the value of attribute fans.



51
52
53
# File 'lib/urbanopt/reporting/default_reports/end_use.rb', line 51

def fans
  @fans
end

#generatorsObject

Returns the value of attribute generators.



51
52
53
# File 'lib/urbanopt/reporting/default_reports/end_use.rb', line 51

def generators
  @generators
end

#heat_recoveryObject

Returns the value of attribute heat_recovery.



51
52
53
# File 'lib/urbanopt/reporting/default_reports/end_use.rb', line 51

def heat_recovery
  @heat_recovery
end

#heat_rejectionObject

Returns the value of attribute heat_rejection.



51
52
53
# File 'lib/urbanopt/reporting/default_reports/end_use.rb', line 51

def heat_rejection
  @heat_rejection
end

#heatingObject

Returns the value of attribute heating.



51
52
53
# File 'lib/urbanopt/reporting/default_reports/end_use.rb', line 51

def heating
  @heating
end

#humidificationObject

Returns the value of attribute humidification.



51
52
53
# File 'lib/urbanopt/reporting/default_reports/end_use.rb', line 51

def humidification
  @humidification
end

#interior_equipmentObject

Returns the value of attribute interior_equipment.



51
52
53
# File 'lib/urbanopt/reporting/default_reports/end_use.rb', line 51

def interior_equipment
  @interior_equipment
end

#interior_lightingObject

Returns the value of attribute interior_lighting.



51
52
53
# File 'lib/urbanopt/reporting/default_reports/end_use.rb', line 51

def interior_lighting
  @interior_lighting
end

#pumpsObject

Returns the value of attribute pumps.



51
52
53
# File 'lib/urbanopt/reporting/default_reports/end_use.rb', line 51

def pumps
  @pumps
end

#refrigerationObject

Returns the value of attribute refrigeration.



51
52
53
# File 'lib/urbanopt/reporting/default_reports/end_use.rb', line 51

def refrigeration
  @refrigeration
end

#water_systemsObject

Returns the value of attribute water_systems.



51
52
53
# File 'lib/urbanopt/reporting/default_reports/end_use.rb', line 51

def water_systems
  @water_systems
end

Instance 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 EndUse attribute.

new_value - Float - A value corresponding to a EndUse attribute.



153
154
155
156
157
158
159
160
# File 'lib/urbanopt/reporting/default_reports/end_use.rb', line 153

def 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

#defaultsObject

Assign default values if values does not exist



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/urbanopt/reporting/default_reports/end_use.rb', line 90

def defaults
  hash = {}

  hash[:heating] = nil
  hash[:cooling] = nil
  hash[:interior_lighting] = nil
  hash[:exterior_lighting] = nil
  hash[:interior_equipment] = nil
  hash[:exterior_equipment] = nil
  hash[:electric_vehicles] = nil
  hash[:fans] = nil
  hash[:pumps] = nil
  hash[:heat_rejection] = nil
  hash[:humidification] = nil
  hash[:heat_recovery] = nil
  hash[:water_systems] = nil
  hash[:refrigeration] = nil
  hash[:generators] = nil

  return hash
end

#merge_end_use!(other) ⇒ Object

Aggregate values of each EndUse attribute.

Parameters:

other - EndUse - An object of EndUse class.



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/urbanopt/reporting/default_reports/end_use.rb', line 168

def merge_end_use!(other)
  @heating = add_values(@heating, other.heating)
  @cooling = add_values(@cooling, other.cooling)
  @interior_lighting = add_values(@interior_lighting, other.interior_lighting)
  @exterior_lighting = add_values(@exterior_lighting, other.exterior_lighting)
  @interior_equipment = add_values(@interior_equipment, other.interior_equipment)
  @exterior_equipment = add_values(@exterior_equipment, other.exterior_equipment)
  @electric_vehicles = add_values(@electric_vehicles, other.electric_vehicles)
  @fans = add_values(@fans, other.fans)
  @pumps = add_values(@pumps, other.pumps)
  @heat_rejection = add_values(@heat_rejection, other.heat_rejection)
  @humidification = add_values(@humidification, other.humidification)
  @heat_recovery = add_values(@heat_recovery, other.heat_recovery)
  @water_systems = add_values(@water_systems, other.water_systems)
  @refrigeration = add_values(@refrigeration, other.refrigeration)
  @generators = add_values(@generators, other.generators)

  return self
end

#to_hashObject

Convert to a Hash equivalent for JSON serialization.

  • Exclude attributes with nil values.

  • Validate end_use hash properties against schema.



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
# File 'lib/urbanopt/reporting/default_reports/end_use.rb', line 118

def to_hash
  result = {}

  result[:heating] = @heating
  result[:cooling] = @cooling
  result[:interior_lighting] = @interior_lighting
  result[:exterior_lighting] = @exterior_lighting
  result[:interior_equipment] = @interior_equipment
  result[:exterior_equipment] = @exterior_equipment
  result[:electric_vehicles] = @electric_vehicles
  result[:fans] = @fans
  result[:pumps] = @pumps
  result[:heat_rejection] = @heat_rejection
  result[:humidification] = @humidification
  result[:heat_recovery] = @heat_recovery
  result[:water_systems] = @water_systems
  result[:refrigeration] = @refrigeration
  result[:generators] = @generators

  # validate end_use properties against schema
  if @@validator.validate(@@schema[:definitions][:EndUse][:properties], result).any?
    raise "end_use properties does not match schema: #{@@validator.validate(@@schema[:definitions][:EndUse][:properties], result)}"
  end

  return result
end