Guest User

Untitled

a guest
Feb 20th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. require 'time.rb'
  2. class Sample < ActiveRecord::Base
  3. validates_numericality_of :windsample
  4. validates_numericality_of :windaverage
  5. validates_numericality_of :windmax
  6. validates_numericality_of :wdirsample
  7. validates_numericality_of :wdiraverage
  8. validates_numericality_of :baromsample
  9. validates_numericality_of :tempsample
  10. validates_numericality_of :relhumidsample
  11. validates_numericality_of :radiationsample
  12. validates_numericality_of :radiationtotal
  13. validates_numericality_of :raintenmin
  14.  
  15. def initialize(fields)
  16. raise "Wrong field count #{fields.length} expected 15" unless fields.length == 15
  17.  
  18. (0..3).each do |v|
  19. fields[v] = fields[v].to_i
  20. end
  21. (4..14).each do |v|
  22. fields[v] = fields[v].to_f
  23. end
  24.  
  25. @sampletime = dateconv(fields[1..3])
  26. @windsample = fields[4]
  27. @windaverage = fields[5]
  28. @windmax = fields[6]
  29. @wdirsample = fields[7]
  30. @wdiraverage = fields[8]
  31. @baromsample = fields[9]
  32. @tempsample = fields[10]
  33. @relhumidsample = fields[11]
  34. @radiationsample = fields[12]
  35. @radiationtotal = fields[13]
  36. @raintenmin = fields[14]
  37. end
  38.  
  39. def to_s
  40. str = @sampletime.to_s + " sample"
  41. end
  42.  
  43. private
  44.  
  45. def dateconv(fields)
  46. year = fields[0]
  47. day = fields[1]
  48. hourmin = fields[2]
  49. minutes = hourmin %100
  50. hours = (hourmin/100) % 24
  51. #$stdout.puts "y #{year} h #{hours} m #{minutes}"
  52. time = Time.local(year, 1, 1, hours, minutes)
  53. time = time + (day-1)*60*60*24
  54.  
  55. return time
  56. end
  57. end
Add Comment
Please, Sign In to add comment