Class: Solar::Simulator::Panel

Inherits:
Object
  • Object
show all
Defined in:
lib/solar/simulator/panel.rb

Constant Summary collapse

MonthToSeason =
[3, 3, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3]
Seasons =
[[3240, 700],[3600, 600],[3120, 850],[2880, 1000]]
GammaVoltage =
11
GammaCurrent =
12

Class Method Summary collapse

Class Method Details

.run(options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/solar/simulator/panel.rb', line 10

def self.run(options = {})
  options[:time] ||= Time.now
  options[:nominal_power] ||= 6000.0
  options[:max_current] = options[:nominal_power]/230.0
  timestamp = options[:time].to_i

  lux = self.simulate_lux(options)
  voltage = self.simulate_voltage(options) 
  current = self.simulate_current(lux, options)

  payload = {}
  payload[:timestamp] = timestamp
  payload[:values] = voltage.zip(current).flatten << lux
  return payload
end

.simulate_current(lux, options) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/solar/simulator/panel.rb', line 45

def self.simulate_current(lux, options)
  max_delta = (options[:max_current] * lux / 1023.0) * (GammaCurrent / 100.0)
  delta = rand * max_delta
  if Random.rand(2)
    [(options[:max_current]*lux/1023.0)+delta]
  else
    [(options[:max_current]*lux/1023.0)-delta]
  end
end

.simulate_lux(options) ⇒ Object



26
27
28
29
30
31
# File 'lib/solar/simulator/panel.rb', line 26

def self.simulate_lux(options)
  slot = (options[:time]-options[:time].beginning_of_day).to_i/15
  season = Seasons[MonthToSeason[options[:time].month-1]]
  lux = ( 1/(season[1] * Math.sqrt(2*Math::PI) ) ) * Math.exp(-((slot-season[0])**2.0)/(2*(season[1]**2.0)))
  return (lux*1539344).ceil
end

.simulate_voltage(options) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/solar/simulator/panel.rb', line 33

def self.simulate_voltage(options)
  sign = Random.rand(2)
  delta = rand*GammaVoltage
  base_voltage = 230

  if sign
    [(base_voltage + delta).round(2)]
  else
    [(base_voltage - delta).round(2)]
  end
end