Skip to content

Instantly share code, notes, and snippets.

@lightcap
Created March 15, 2010 19:53
Show Gist options
  • Save lightcap/333249 to your computer and use it in GitHub Desktop.
Save lightcap/333249 to your computer and use it in GitHub Desktop.
## monitor_poll_test.rb
require 'test_helper'
class MonitorPollTest < ActiveSupport::TestCase
should_belong_to :inverter
should_belong_to :inverter_property
context "An instance of MonitorPoll" do
setup do
@model = Factory(:inverter_model)
@inverter = Factory(:inverter, :inverter_model => @model)
@inverter.save!
@poll = Factory(:monitor_poll, :inverter => @inverter)
end
should "save" do
# assert @poll.save!
end
end
end
## inverter.rb
class Inverter < ActiveRecord::Base
has_many :fault_polls
has_many :monitor_polls
has_many :event_polls
belongs_to :inverter_model, :foreign_key => "model_id"
has_many :inverter_properties
def last_poll=(poll_id)
self.last_poll_id = poll_id if MonitorPoll.find(poll_id)
end
end
## inverter_model.rb
class InverterModel < ActiveRecord::Base
set_table_name :models
has_many :inverters, :foreign_key => "model_id"
end
# monitor_poll.rb
class MonitorPoll < ActiveRecord::Base
set_table_name :inverter_monitor_polls
belongs_to :inverter
belongs_to :inverter_state
belongs_to :inverter_property
belongs_to :old_inverter_state, :foreign_key => :inverter_state_old_id
end
## factories.rb
class Factory
undef :id
end
Factory.define :inverter do |i|
i.serial_number "PV2600BBAF0110100069"
i.fault_msg_count 0
i.monitor_poll_count 0
i.first_reported Time.now - 2.days
i.last_ip_addr "4.2.2.2"
i.association :inverter_model
end
Factory.define :inverter_model do |m|
m.model_name "PVP1100"
m.model_number 287
end
Factory.define :monitor_poll do |p|
p.inverter {|a| a.association :inverter}
p.association :inverter_property
p.association :old_inverter_state
p.association :inverter_state
p.timestamp_poll Time.now
p.timestamp_valid_asserted 1
p.ip_addr "4.2.2.2"
p.status_pvm 0
p.fault_asserted 0
p.fault_class 0
p.fault_sys 0
p.fault_drive 0
p.fault_temp 0
p.fault_volt 0
p.fault_grid 0
p.warning 0
p.fault_old_0 0
p.fault_old_1 0
p.fault_old_2 0
p.power_ac 133564.39
p.power_dc 143904.00
p.volts_ac_a_n 289.60
p.volts_ac_b_n 281.87
p.volts_ac_c_n 288.57
p.volts_dc_pv 368.46
p.volts_dc_bus 365.85
p.volts_dc_ps_5 4.91
p.volts_dc_ps_10 10.72
p.volts_dc_ps_15 16.27
p.volts_dc_ps_15_neg 16.22
p.volts_dc_ps_24 20.50
p.volts_dc_ps_48 52.33
p.volts_dc_ps_48_status 0
p.volts_dc_ps_3_3_analog 0.00
p.current_ac_output_a 156.88
p.current_ac_output_b 160.34
p.current_ac_output_c 156.18
p.current_dc_input 394.32
p.current_dc_pv_ground 0.00
p.current_dc_ps_48 518.84
p.current_dc_ps_15 415.50
p.current_dc_ps_5 409.57
p.frequency_ac_output 60.14
p.energy_ac_output_real 133564.39
p.temp_drive_a1 60.94
p.temp_drive_a2 62.08
p.temp_drive_b1 62.00
p.temp_drive_b2 0.00
p.temp_drive_c1 63.01
p.temp_drive_c2 56.32
p.temp_air_inlet 27.53
p.temp_magnetics 89.04
p.temp_pcb 31.96
p.speed_fan_command 5376.00
p.speed_fan_control_mode 3.00
p.speed_fan_1 390
p.speed_fan_2 387
p.speed_fan_3 378
p.total_kwh 64624.00
end
Factory.define :inverter_property do |p|
p.association :inverter
p.address_modbus 50
p.address_mac "00409D3B8A4B"
p.version_firmware_dsp 33.0000
p.version_firmware_pvm 3.2
p.version_firmware_pvm_micro 9
p.version_protocol_dsp 0.0000
p.config_inverter 260
p.trip_frequency_high 0.00
p.trip_frequency_low 0.00
p.trip_frequency_high_time 0.00
p.trip_frequency_low_time 0.00
p.trip_volts_ac_high_slow 0.00
p.trip_volts_ac_high_fast 0.00
p.trip_volts_ac_low_slow 0.00
p.trip_volts_ac_low_fast 0.00
p.cal_volts_ac_slope_a 0.00
p.cal_volts_ac_slope_b 0.00
p.cal_volts_ac_slope_c 0.00
p.cal_volts_dc_offset 0.00
p.cal_volts_dc_slope 0.00
p.cal_current_ac_slope_a 0.00
p.cal_current_ac_slope_b 0.00
p.cal_current_ac_slope_c 0.00
p.cal_current_dc_slope 0.00
p.cal_power_ac_output_slope 0.00
p.cal_power_ac_output_offset 0.00
end
Factory.define :inverter_state do |s|
s.name "Power Track State"
s.description "Normal operation"
s.id 5
end
Factory.define :old_inverter_state do |s|
s.name "peak power tracking"
s.id 21
end
Factory.sequence :time do |t|
Time.now - t.minutes
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment