Downsampler
This gem is for downsampling and "bucketing" time based data. Great for passing data to chartkick
<%= line_chart User.downsample_by(60, :created_at).counts %>
Implemented without any dependencies so you don't need activesupport or activerecord.
Installation
Add this line to your application's Gemfile:
gem 'downsampler'
And then execute:
$ bundle
Or install it yourself as:
$ gem install downsampler
Usage
DataPoint = Struct.new(:time, :value)
data_points = (1..9).map { |i| DataPoint.new(Time.now + i*20, i)}
downsampled = data_points.downsample_by(1.minute, &:time)
downsampled.sum &:value
downsampled.mean { |point| point.value }
downsampled.counts
Contributing
- Fork it ( https://github.com/omockler/downsampler/fork )
- Create your feature branch (
git checkout -b my-new-feature
)
- Commit your changes (
git commit -am 'Add some feature'
)
- Push to the branch (
git push origin my-new-feature
)
- Create a new Pull Request