Count from json data Rails -


i'm looking count json data it's outputting:

[0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] 

view

<%= @overall %> 

where 1's greater 40. instead of '2'.

json data formatted url:

{"status": "ok", "data": [{"2014-06-16": 32.1},{"2014-06-17": 30.2},{"2014-06-18": 42.9}]} etc 

controller

@data = json.parse(open(@temperature.url).read) @overall = []      @data['data'].each |data|       dates << data.keys       temps << data.values       @overall << data.values.count { |i| > 40 }     end 

since json data: array assuming multiple dates represented multiple hashes (one each day). correct?

{"status": "ok", "data": [{"2014-06-16": 42.1}, {"2014-06-17": 45.5}] 

if that's case, should work:

@data = json.parse(open(@temperature.url).read) dates = @data['data'].map {|data| data.keys.first} temps = @data['data'].map {|data| data.values.first} @overall = temps.count {|temp| temp > 40} 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -