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

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

Overview

power_distributio 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.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/urbanopt/reporting/default_reports/power_distribution.rb', line 63

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]
  # 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.



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

def max_power_kw
  @max_power_kw
end

#max_reactive_power_kvarObject

Returns the value of attribute max_reactive_power_kvar.



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

def max_reactive_power_kvar
  @max_reactive_power_kvar
end

#nominal_capacityObject

Returns the value of attribute nominal_capacity.



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

def nominal_capacity
  @nominal_capacity
end

#nominal_voltageObject

Returns the value of attribute nominal_voltage.



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

def nominal_voltage
  @nominal_voltage
end

#over_voltage_hoursObject

Returns the value of attribute over_voltage_hours.



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

def over_voltage_hours
  @over_voltage_hours
end

#reactance_resistance_ratioObject

Returns the value of attribute reactance_resistance_ratio.



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

def reactance_resistance_ratio
  @reactance_resistance_ratio
end

#under_voltage_hoursObject

Returns the value of attribute under_voltage_hours.



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

def under_voltage_hours
  @under_voltage_hours
end

Instance Method Details

#defaultsObject

Assigns default values if attribute values do not exist.



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/urbanopt/reporting/default_reports/power_distribution.rb', line 82

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

  return hash
end

#merge_power_distributionObject

Merges muliple power distribution results together.

new_costs - Array - An array of ConstructionCost objects.



123
124
125
# File 'lib/urbanopt/reporting/default_reports/power_distribution.rb', line 123

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.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/urbanopt/reporting/default_reports/power_distribution.rb', line 101

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

  # 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