jimeh / redistat Goto Github PK
View Code? Open in Web Editor NEWA Redis-backed statistics storage and querying library written in Ruby.
License: MIT License
A Redis-backed statistics storage and querying library written in Ruby.
License: MIT License
I noticed that there is both an interval
and a depth
option for the finder. What's unclear to me is how those options are meant to be used.
The goal is to be able to find stats and return them aggregated as one number or return them broken out into multiple numbers depending on the size of the time interval used (hourly, daily, yearly). What's the best way to accomplish that?
Intuitively, I'd think that interval
would specify the size of the interval returned by the finder. This seems to be the case:
require 'redistat'
class ViewStats
include Redistat::Model
depth :hour
end
ViewStats.store('hello', {:world => 4}, 1.hour.ago)
ViewStats.store('hello', {:world => 2}, 3.hours.ago)
ViewStats.find('hello', 1.hour.ago, 1.hour.from_now, :interval => :hour).all
=> [{"world"=>"4"}, {}, {}]
And I'd think that omitting interval would cause the finder to return only one interval. This also seems to be the case:
ViewStats.find('hello', 3.hours.ago, 1.hour.from_now).all
=> [{"world"=>6}]
I would expect that using a year
interval would also cause the finder to return only one interval (assuming there had been stats collected in only one year). But this is not the case. The finder behaves as though I used the hour interval:
ViewStats.find('hello', 1.hour.ago, 1.hour.from_now, :interval => :year).all
=> [{"world"=>"4"}, {}, {}]
I see that the default depth
option is :hour
, so I thought maybe this was interfering with interval working as expected. Setting depth
to :year
causes the time range to be ignored:
ViewStats.find('hello', 1.hour.ago, 1.hour.from_now, :interval => :year, :depth => :year).all
=> [{"world"=>"6"}]
So it's unclear to me how these options are meant to be used. Any additional clarity you can provide would be immensely appreciated.
Being able to remove statistics for certain labels and/or timeframes, and also setting them to a fixed value rather than only supporting incrementation could be useful for testing purposes.
Since Redis' atomic increment operations only support integers, any float-based statistics you want to store first need to be converted to an integer, and then back to floats again when you read the stored stats.
The idea is to have Redistat do this conversion for you by telling it which specific stat keys are floats, and with what precision they should be handled. The end result will be that weither you feed Redistat integers or floats, it'll just work.
I've noticed some issues fetching in the last hour of a day, or the last day of a month. There is a query from 23:00 to the following day at 0:00; or from the beginning of the last day of the month to the beginning of the first day of the next month -- in either case, the query returns the following hour (or day) incorrectly. I also noticed that a query from x.beginning_of_day to x.end_of_day will always return nothing (when depth is set to day). Here are the tests I added to finder_spec.rb:
https://gist.github.com/604a6fd34580e472e129
(with corresponding failures)
At the moment it uses the class name in the key name (which is a good default) but there is no easy way to override this. It becomes a problem when you rename your classes. It would be nice to be able to specify a key name in the model.
Currently if the Redis server is old and doesn't support hashes, the redis gem will throw an exception when Redistat tries to do a hgetall
or hincrby
call. This can be handled in a nicer manner.
I decided to give Redistat a shot today. Unfortunately, I couldn't make it past the example in the readme. I'm on Redis 2.0.4.
ruby-1.9.2-p136 :015 > class VisitorStats
ruby-1.9.2-p136 :016?> include Redistat::Model
ruby-1.9.2-p136 :017?> end
=> VisitorStats
ruby-1.9.2-p136 :018 > VisitorStats.store('/about', {:views => 1})
=> #<Redistat::Event:0x00000101a14008 @raw_options={}, @options={:depth=>:hour, :store_event=>false, :connection_ref=>nil, :enable_grouping=>true, :label_indexing=>true}, @key=VisitorStats//about:2011031511, @stats={:views=>1}, @meta={}, @new=false>
ruby-1.9.2-p136 :019 > stats = VisitorStats.fetch('/about', 2.hour.ago, Time.now)
=> [{}]
ruby-1.9.2-p136 :020 > stats.total
=> {}
Currently all statistics stored with Redistat are assumed to be time-based. Meaning the time of when the event occurs is import and stored.
However for simpler, pure-counter based statistics where when something happened doesn't matter currently is not possible in a simple manner without causing a lot of overhead in the library and Redis.
Let Redistat handle the average/mean calculations for specific values. This should be easy to implement by simply having Redistat count the number of times a specific value has been updated.
Caused by Redis#smembers returning nil
rather than an empty Array on some older versions of Redis.
Fixed in v0.2.6.
Add an option to specify a custom Redis configuration on a per-model basis, so you're not locked into using a single server and database across all your Redistat usage.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.