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.



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

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.



18
19
20
# File 'lib/urbanopt/reporting/default_reports/scenario_power_distribution.rb', line 18

def capacitors
  @capacitors
end

#distribution_linesObject

Returns the value of attribute distribution_lines.



18
19
20
# File 'lib/urbanopt/reporting/default_reports/scenario_power_distribution.rb', line 18

def distribution_lines
  @distribution_lines
end

#substationsObject

Returns the value of attribute substations.



18
19
20
# File 'lib/urbanopt/reporting/default_reports/scenario_power_distribution.rb', line 18

def substations
  @substations
end

Instance Method Details

#add_capacitor(hash = {}) ⇒ Object

Add a capacitor



102
103
104
105
106
107
108
109
# File 'lib/urbanopt/reporting/default_reports/scenario_power_distribution.rb', line 102

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



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/urbanopt/reporting/default_reports/scenario_power_distribution.rb', line 87

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



75
76
77
78
79
80
81
82
# File 'lib/urbanopt/reporting/default_reports/scenario_power_distribution.rb', line 75

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.



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

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.



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/urbanopt/reporting/default_reports/scenario_power_distribution.rb', line 58

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