Rails array exclude -
i have array feature date + time , temperature.
i looking count number of temperature below 25 degrees fall between specific time frame (16:00:00 - 20:00:00), unsure on how best tackle scenario.
data json file
{"status": "ok", "data": [{"2014-06-16 16:00:00": 24.2},{"2014-06-17 12:00:00": 30.2},{"2014-06-18 17:00:00": 42.9}]} etc
controller
@data = json.parse(open(@temperature.url).read) dates = [] temps = [] @data['data'].each |data| dates << data.keys temps << data.values end @nights25 = dates.flatten.count {|i| ["16:", "17:", "18:", "19:", "20:"].include?(i) if i.temps > 25 end }
maybe this:
temp = @data['data'].reduce({}, :merge) temp.count { |time, deg| (16..20).include?(time.parse(time).hour) && deg < 25 }
Comments
Post a Comment