Class: MSG_Chumby::LastMinuteImporter
- Inherits:
-
Object
- Object
- MSG_Chumby::LastMinuteImporter
- Defined in:
- lib/msg-chumby-daemon/reading-importer.rb
Instance Method Summary collapse
- #doWork ⇒ Object
-
#initialize(reading_cache, location, local_id) ⇒ LastMinuteImporter
constructor
A new instance of LastMinuteImporter.
Constructor Details
#initialize(reading_cache, location, local_id) ⇒ LastMinuteImporter
Returns a new instance of LastMinuteImporter.
23 24 25 26 27 |
# File 'lib/msg-chumby-daemon/reading-importer.rb', line 23 def initialize(reading_cache, location, local_id) @reading_cache=reading_cache @query=FluksoLocal::Query.new(location) @local_id=local_id end |
Instance Method Details
#doWork ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/msg-chumby-daemon/reading-importer.rb', line 28 def doWork begin values=@query.getReadings(@local_id); # handle last value last_value=values.max #puts "Last reading: timestamp = #{last_value[0]}, value=#{last_value[1]}" reading=Flukso::UTCReading.new(last_value[0], last_value[1]) @reading_cache.update_last_reading(reading); # now handle last minute last_minute=Array.new(); values.each{|current| currentreading=Flukso::UTCReading.new(current[0], current[1]) last_minute << currentreading } last_minute.sort! {|a, b| a. <=> b. } @reading_cache.update_last_minute(last_minute); rescue StandardError => bam puts "Cannot retrieve last minute: #{bam}" end end |