Class: Solar::Simulator::Panel
- Inherits:
-
Object
- Object
- Solar::Simulator::Panel
- 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
- .run(options = {}) ⇒ Object
- .simulate_current(lux, options) ⇒ Object
- .simulate_lux(options) ⇒ Object
- .simulate_voltage(options) ⇒ Object
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( = {}) [:time] ||= Time.now [:nominal_power] ||= 6000.0 [:max_current] = [:nominal_power]/230.0 = [:time].to_i lux = self.simulate_lux() voltage = self.simulate_voltage() current = self.simulate_current(lux, ) payload = {} payload[: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, ) max_delta = ([:max_current] * lux / 1023.0) * (GammaCurrent / 100.0) delta = rand * max_delta if Random.rand(2) [([:max_current]*lux/1023.0)+delta] else [([: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() slot = ([:time]-[:time].beginning_of_day).to_i/15 season = Seasons[MonthToSeason[[: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() 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 |