Class: URBANopt::Reporting::DefaultReports::ScenarioPowerDistributionCost

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

Overview

scenario_power_distribution_cost include eletrical power distribution system violation and upgrade cost information.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ ScenarioPowerDistributionCost

ScenarioPowerDistributionCost class initializes all scenario_power_distribution_cost attributes: :results, :outputs, :violation_summary, :costs_per_equipment, :equipment



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/urbanopt/reporting/default_reports/scenario_power_distribution_cost.rb', line 26

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

  @results = hash[:results]
  @outputs = hash[:outputs]
  @violation_summary = hash[:violation_summary]
  @costs_per_equipment = hash[:costs_per_equipment]
  @equipment = hash[:equipment]

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

Instance Attribute Details

#costs_per_equipmentObject

Returns the value of attribute costs_per_equipment.



19
20
21
# File 'lib/urbanopt/reporting/default_reports/scenario_power_distribution_cost.rb', line 19

def costs_per_equipment
  @costs_per_equipment
end

#equipmentObject

Returns the value of attribute equipment.



19
20
21
# File 'lib/urbanopt/reporting/default_reports/scenario_power_distribution_cost.rb', line 19

def equipment
  @equipment
end

#outputsObject

Returns the value of attribute outputs.



19
20
21
# File 'lib/urbanopt/reporting/default_reports/scenario_power_distribution_cost.rb', line 19

def outputs
  @outputs
end

#resultsObject

Returns the value of attribute results.



19
20
21
# File 'lib/urbanopt/reporting/default_reports/scenario_power_distribution_cost.rb', line 19

def results
  @results
end

#violation_summaryObject

Returns the value of attribute violation_summary.



19
20
21
# File 'lib/urbanopt/reporting/default_reports/scenario_power_distribution_cost.rb', line 19

def violation_summary
  @violation_summary
end

Instance Method Details

#add_costs_per_equipmentObject

Add costs per equipment



135
136
137
138
139
140
141
142
143
144
145
# File 'lib/urbanopt/reporting/default_reports/scenario_power_distribution_cost.rb', line 135

def add_costs_per_equipment
  hash.delete_if { |k, v| v.nil? }
  hash = defaults.merge(hash)
  costs_per_equipment = {}
  costs_per_equipment['name'] = hash[:name]
  costs_per_equipment['type'] = hash[:type]
  costs_per_equipment['count'] = hash[:count]
  costs_per_equipment['total_cost_usd'] = hash[:costs_per_equipment]

  @costs_per_equipment << costs_per_equipment
end

#add_equipmentObject

Add equipment



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/urbanopt/reporting/default_reports/scenario_power_distribution_cost.rb', line 150

def add_equipment
  hash.delete_if { |k, v| v.nil? }
  hash = defaults.merge(hash)
  equipment = {}
  equipment['equipment_type'] = hash[:equipment_type]
  equipment['equipment_name'] = hash[:equipment_name]
  equipment['status'] = hash[:status]
  equipment['parameter1_name'] = hash[:parameter1_name]
  equipment['parameter1_original'] = hash[:parameter1_original]
  equipment['parameter1_upgraded'] = hash[:parameter1_upgraded]
  equipment['parameter2_name'] = hash[:parameter2_name]
  equipment['parameter2_original'] = hash[:parameter2_original]
  equipment['parameter2_upgraded'] = hash[:parameter2_upgraded]
  equipment['parameter3_name'] = hash[:parameter3_name]
  equipment['parameter3_original'] = hash[:parameter3_original]
  equipment['parameter3_upgraded'] = hash[:parameter3_upgraded]
  equipment['name'] = hash[:name]

  @equipment << equipment
end

#add_outputs(hash = {}) ⇒ Object

Add outputs



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/urbanopt/reporting/default_reports/scenario_power_distribution_cost.rb', line 90

def add_outputs(hash = {})
  hash.delete_if { |k, v| v.nil? }
  hash = defaults.merge(hash)
  output = {}
  output['log_file'] = hash[:log_file]
  output['jobs'] = []
  hash[:jobs].each do |job|
    output['jobs'] << job
  end
  @outputs = output
end

#add_result(hash = {}) ⇒ Object

Add a result



79
80
81
82
83
84
85
# File 'lib/urbanopt/reporting/default_reports/scenario_power_distribution_cost.rb', line 79

def add_result(hash = {})
  hash.delete_if { |k, v| v.nil? }
  hash = defaults.merge(hash)
  result = {}
  result['num_violations'] = hash[:num_violations]
  @results << result
end

#add_violation_summary(hash = {}) ⇒ Object

Add a violation summary



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

def add_violation_summary(hash = {})
  hash.delete_if { |k, v| v.nil? }
  hash = defaults.merge(hash)
  violation_summary = {}
  violation_summary['scenario'] = hash[:scenario]
  violation_summary['stage'] = hash[:stage]
  violation_summary['upgrade_type'] = hash[:upgrade_type]
  violation_summary['simulation_time_s'] = hash[:simulation_time_s]
  violation_summary['thermal_violations_present'] = hash[:thermal_violations_present]
  violation_summary['voltage_violations_present'] = hash[:voltage_violations_present]
  violation_summary['max_bus_voltage'] = hash[:max_bus_voltage]
  violation_summary['min_bus_voltage'] = hash[:min_bus_voltage]
  violation_summary['num_voltage_violation_buses'] = hash[:num_voltage_violation_buses]
  violation_summary['num_overvoltage_violation_buses'] = hash[:num_overvoltage_violation_buses]
  violation_summary['voltage_upper_limit'] = hash[:voltage_upper_limit]
  violation_summary['num_undervoltage_violation_buses'] = hash[:num_undervoltage_violation_buses]
  violation_summary['voltage_lower_limit'] = hash[:voltage_lower_limit]
  violation_summary['max_line_loading'] = hash[:max_line_loading]
  violation_summary['max_transformer_loading'] = hash[:max_transformer_loading]
  violation_summary['num_line_violations'] = hash[:num_line_violations]
  violation_summary['line_upper_limit'] = hash[:line_upper_limit]
  violation_summary['num_transformer_violations'] = hash[:num_transformer_violations]
  violation_summary['transformer_upper_limit'] = hash[:transformer_upper_limit]

  @violation_summary << violation_summary
end

#defaultsObject

Assigns default values if attribute values do not exist.##



43
44
45
46
47
48
49
50
51
52
# File 'lib/urbanopt/reporting/default_reports/scenario_power_distribution_cost.rb', line 43

def defaults
  hash = {}
  hash[:results] = []
  hash[:outputs] = {}
  hash[:violation_summary] = []
  hash[:costs_per_equipment] = []
  hash[:equipment] = []

  return hash
end

#to_hashObject

Converts to a Hash equivalent for JSON serialization.

  • Exclude attributes with nil values.

  • Validate power_distribution_cost hash properties against schema.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/urbanopt/reporting/default_reports/scenario_power_distribution_cost.rb', line 60

def to_hash
  result = {}
  result[:results] = @results if @results
  result[:outputs] = @outputs if !@outputs.empty?
  result[:violation_summary] = @violation_summary if @violation_summary
  result[:costs_per_equipment] = @costs_per_equipment if @costs_per_equipment
  result[:equipment] = @equipment if @equipment

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

  return result
end