Class: MSG_Chumby::LastDayHandler
- Inherits:
-
Mongrel::HttpHandler
- Object
- Mongrel::HttpHandler
- MSG_Chumby::LastDayHandler
- Defined in:
- lib/msg-chumby-daemon/http-xml-server.rb
Instance Method Summary collapse
-
#initialize(reading_cache) ⇒ LastDayHandler
constructor
A new instance of LastDayHandler.
- #process(request, response) ⇒ Object
Constructor Details
#initialize(reading_cache) ⇒ LastDayHandler
Returns a new instance of LastDayHandler.
120 121 122 |
# File 'lib/msg-chumby-daemon/http-xml-server.rb', line 120 def initialize(reading_cache) @reading_cache=reading_cache; end |
Instance Method Details
#process(request, response) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/msg-chumby-daemon/http-xml-server.rb', line 123 def process(request, response) response.start(200) do |head,out| head["Content-Type"] = "text/xml" readings=(@reading_cache.last_day()) # Even if there are currently no readings we need to provide # them. if readings==nil readings = Array.new(); (0..95).each {|i| = Time.now.to_i - (i * 60 * 15) 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. time=Time.at(reading.); current_reading= { 'dayofyear' => [ time.strftime("%j")], '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_day"})); end end |