Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'time.rb'
- class Sample < ActiveRecord::Base
- validates_numericality_of :windsample
- validates_numericality_of :windaverage
- validates_numericality_of :windmax
- validates_numericality_of :wdirsample
- validates_numericality_of :wdiraverage
- validates_numericality_of :baromsample
- validates_numericality_of :tempsample
- validates_numericality_of :relhumidsample
- validates_numericality_of :radiationsample
- validates_numericality_of :radiationtotal
- validates_numericality_of :raintenmin
- def initialize(fields)
- raise "Wrong field count #{fields.length} expected 15" unless fields.length == 15
- (0..3).each do |v|
- fields[v] = fields[v].to_i
- end
- (4..14).each do |v|
- fields[v] = fields[v].to_f
- end
- @sampletime = dateconv(fields[1..3])
- @windsample = fields[4]
- @windaverage = fields[5]
- @windmax = fields[6]
- @wdirsample = fields[7]
- @wdiraverage = fields[8]
- @baromsample = fields[9]
- @tempsample = fields[10]
- @relhumidsample = fields[11]
- @radiationsample = fields[12]
- @radiationtotal = fields[13]
- @raintenmin = fields[14]
- end
- def to_s
- str = @sampletime.to_s + " sample"
- end
- private
- def dateconv(fields)
- year = fields[0]
- day = fields[1]
- hourmin = fields[2]
- minutes = hourmin %100
- hours = (hourmin/100) % 24
- #$stdout.puts "y #{year} h #{hours} m #{minutes}"
- time = Time.local(year, 1, 1, hours, minutes)
- time = time + (day-1)*60*60*24
- return time
- end
- end
Add Comment
Please, Sign In to add comment