Class: URBANopt::Reporting::DefaultReports::PowerDistribution

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

Overview

power_distribution include eletrical power distribution systems information.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ PowerDistribution

PowerDistribution class initialize all power_distribution attributes: :under_voltage_hours , :over_voltage_hours, :nominal_capacity, :reactance_resistance_ratio

parameters:

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



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/urbanopt/reporting/default_reports/power_distribution.rb', line 29

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

  @under_voltage_hours = hash[:under_voltage_hours]
  @over_voltage_hours = hash[:over_voltage_hours]
  @nominal_capacity = hash[:nominal_capacity]
  @reactance_resistance_ratio = hash[:reactance_resistance_ratio]
  @nominal_voltage = hash[:nominal_voltage] # in V
  @max_power_kw = hash[:max_power_kw]
  @max_reactive_power_kvar = hash[:max_reactive_power_kvar]
  @tx_incoming_voltage = hash[:tx_incoming_voltage]
  @tx_outgoing_voltage = hash[:tx_outgoing_voltage]
  # initialize class variables @@validator and @@schema
  @@validator ||= Validator.new
  @@schema ||= @@validator.schema
end

Instance Attribute Details

#max_power_kwObject

Returns the value of attribute max_power_kw.



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

def max_power_kw
  @max_power_kw
end

#max_reactive_power_kvarObject

Returns the value of attribute max_reactive_power_kvar.



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

def max_reactive_power_kvar
  @max_reactive_power_kvar
end

#nominal_capacityObject

Returns the value of attribute nominal_capacity.



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

def nominal_capacity
  @nominal_capacity
end

#nominal_voltageObject

Returns the value of attribute nominal_voltage.



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

def nominal_voltage
  @nominal_voltage
end

#over_voltage_hoursObject

Returns the value of attribute over_voltage_hours.



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

def over_voltage_hours
  @over_voltage_hours
end

#reactance_resistance_ratioObject

Returns the value of attribute reactance_resistance_ratio.



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

def reactance_resistance_ratio
  @reactance_resistance_ratio
end

#tx_incoming_voltageObject

Returns the value of attribute tx_incoming_voltage.



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

def tx_incoming_voltage
  @tx_incoming_voltage
end

#tx_outgoing_voltageObject

Returns the value of attribute tx_outgoing_voltage.



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

def tx_outgoing_voltage
  @tx_outgoing_voltage
end

#under_voltage_hoursObject

Returns the value of attribute under_voltage_hours.



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

def under_voltage_hours
  @under_voltage_hours
end

Instance Method Details

#defaultsObject

Assigns default values if attribute values do not exist.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/urbanopt/reporting/default_reports/power_distribution.rb', line 50

def defaults
  hash = {}
  hash[:under_voltage_hours] = nil
  hash[:over_voltage_hours] = nil
  hash[:nominal_capacity] = nil
  hash[:reactance_resistance_ratio] = nil
  hash[:nominal_voltage] = nil
  hash[:max_power_kw] = nil
  hash[:max_reactive_power_kvar] = nil
  hash[:tx_incoming_voltage] = nil
  hash[:tx_outgoing_voltage] = nil

  return hash
end

#merge_power_distributionObject

Merges multiple power distribution results together.

new_costs - Array - An array of ConstructionCost objects.



95
96
97
# File 'lib/urbanopt/reporting/default_reports/power_distribution.rb', line 95

def merge_power_distribution
  # method to be developed for any attributes to be aggregated or merged
end

#to_hashObject

Converts to a Hash equivalent for JSON serialization.

  • Exclude attributes with nil values.

  • Validate power_distribution hash properties against schema.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/urbanopt/reporting/default_reports/power_distribution.rb', line 71

def to_hash
  result = {}
  result[:under_voltage_hours] = @under_voltage_hours if @under_voltage_hours
  result[:over_voltage_hours] = @over_voltage_hours if @over_voltage_hours
  result[:nominal_capacity] = @nominal_capacity if @nominal_capacity
  result[:reactance_resistance_ratio] = @reactance_resistance_ratio if @reactance_resistance_ratio
  result[:nominal_voltage] = @nominal_voltage if @nominal_voltage
  result[:max_power_kw] = @max_power_kw if @max_power_kw
  result[:max_reactive_power_kvar] = @max_reactive_power_kvar if @max_reactive_power_kvar
  result[:tx_incoming_voltage] = @tx_incoming_voltage if @tx_incoming_voltage
  result[:tx_outgoing_voltage] = @tx_outgoing_voltage if @tx_outgoing_voltage

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

  return result
end