Class: MSG_Chumby::LastMinuteHandler
- Inherits:
-
Mongrel::HttpHandler
- Object
- Mongrel::HttpHandler
- MSG_Chumby::LastMinuteHandler
- Defined in:
- lib/msg-chumby-daemon/http-xml-server.rb
Instance Method Summary collapse
-
#initialize(reading_cache) ⇒ LastMinuteHandler
constructor
A new instance of LastMinuteHandler.
- #process(request, response) ⇒ Object
Constructor Details
#initialize(reading_cache) ⇒ LastMinuteHandler
Returns a new instance of LastMinuteHandler.
53 54 55 |
# File 'lib/msg-chumby-daemon/http-xml-server.rb', line 53 def initialize(reading_cache) @reading_cache=reading_cache; end |
Instance Method Details
#process(request, response) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/msg-chumby-daemon/http-xml-server.rb', line 56 def process(request, response) response.start(200) do |head,out| head["Content-Type"] = "text/xml" readings=(@reading_cache.last_minute()) # Even if there are currently no readings we need to provide # them. if readings==nil readings = Array.new(); (0..59).each {|i| = Time.now.to_i - i readings << Flukso::UTCReading.new(, 0.0) } end flat_data=Array.new; readings.each{|reading| if not reading.nan? #(reading.value*1.0).nan? # Skip NaN values. #else time=Time.at(reading.); current_reading= {'time' => [ time.strftime("%H:%M:%S")], 'value' => [reading.value]}; flat_data << current_reading end } #pp flat_data out.write(XmlSimple.xml_out( { 'reading' => flat_data} ,{'RootName' => "last_minute"})); end end |