Class: URBANopt::Reporting::DefaultReports::ScenarioPowerDistribution

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

Overview

scenario_power_distribution include eletrical power distribution systems information.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ ScenarioPowerDistribution

ScenarioPowerDistribution class initialize all scenario_power_distribution attributes: :substations , :distribution_lines

parameters:

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



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

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

  @substations = hash[:substations]
  @distribution_lines = hash[:distribution_lines]
  @capacitors = hash[:capacitors]

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

Instance Attribute Details

#capacitorsObject

Returns the value of attribute capacitors.



53
54
55
# File 'lib/urbanopt/reporting/default_reports/scenario_power_distribution.rb', line 53

def capacitors
  @capacitors
end

#distribution_linesObject

Returns the value of attribute distribution_lines.



53
54
55
# File 'lib/urbanopt/reporting/default_reports/scenario_power_distribution.rb', line 53

def distribution_lines
  @distribution_lines
end

#substationsObject

Returns the value of attribute substations.



53
54
55
# File 'lib/urbanopt/reporting/default_reports/scenario_power_distribution.rb', line 53

def substations
  @substations
end

Instance Method Details

#add_capacitor(hash = {}) ⇒ Object

Add a capacitor



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

def add_capacitor(hash = {})
  hash.delete_if { |k, v| v.nil? }
  hash = defaults.merge(hash)
  # fields: nominal_capacity
  cap = {}
  cap['nominal_capacity'] = hash[:nominal_capacity]
  cap
end

#add_line(hash = {}) ⇒ Object

Add a line



122
123
124
125
126
127
128
129
130
131
132
# File 'lib/urbanopt/reporting/default_reports/scenario_power_distribution.rb', line 122

def add_line(hash = {})
  hash.delete_if { |k, v| v.nil? }
  hash = defaults.merge(hash)
  # fields: length, ampacity, commercial_line_type
  line = {}
  line['length'] = hash[:length]
  line['ampacity'] = hash[:ampacity]
  line['commercial_line_type'] = hash[:commercial_line_type]

  @distribution_lines << line
end

#add_substation(hash = {}) ⇒ Object

Add a substation



110
111
112
113
114
115
116
117
# File 'lib/urbanopt/reporting/default_reports/scenario_power_distribution.rb', line 110

def add_substation(hash = {})
  hash.delete_if { |k, v| v.nil? }
  hash = defaults.merge(hash)
  # field: nominal_voltage
  substation = {}
  substation['nominal_voltage'] = hash[:nominal_voltage]
  @substations << substation
end

#defaultsObject

Assigns default values if attribute values do not exist.



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

def defaults
  hash = {}
  hash[:substations] = []
  hash[:distribution_lines] = []
  hash[:capacitors] = []

  return hash
end

#to_hashObject

Converts to a Hash equivalent for JSON serialization.

  • Exclude attributes with nil values.

  • Validate power_distribution hash properties against schema.



93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/urbanopt/reporting/default_reports/scenario_power_distribution.rb', line 93

def to_hash
  result = {}
  result[:substations] = @substations if @substations
  result[:distribution_lines] = @distribution_lines if @distribution_lines
  result[:capacitors] = @capacitors if @capacitors

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

  return result
end