Rails Console Graphing Lib
Now that I'm working on a site with actual real users, I've become quite "stats hungry." I find myself constantly checking the database to see how many new users there are, how many new items of this or that type have been created, how many users have uninstalled my app, etc. Up till now I've been querying the DB directly with SQL. However, it is difficult to get a good sense of what the trends are when just looking at long lists of records, or counts of records.Thus with a little research and some glue code, I was able to put together this library (to be required in environment.rb), which will let you generate histograms of counts of Rails models. Following is an example.Let's say I want to see how many comments there have been in the past several hours:
>> puts histogram(:comments, :maxlen => 30, :showval => true)
2007-08-23 20:00:00 :***** (3)
2007-08-23 19:00:00 :** (2)
2007-08-23 18:00:00 :************ (6)
2007-08-23 17:00:00 :********* (5)
2007-08-23 16:00:00 :***** (3)
2007-08-23 15:00:00 :********************* (10)
2007-08-23 14:00:00 :**************************** (13)
2007-08-23 13:00:00 :** (2)
2007-08-23 12:00:00 :***** (3)
2007-08-23 11:00:00 :******* (4)
2007-08-23 10:00:00 :******* (4)
2007-08-23 09:00:00 :** (2)
2007-08-23 08:00:00 :******* (4)
2007-08-23 07:00:00 :********* (5)
2007-08-23 06:00:00 :************ (6)
2007-08-23 05:00:00 :***** (3)
2007-08-23 04:00:00 :********* (5)
2007-08-23 03:00:00 :****************** (9)
2007-08-23 02:00:00 :******* (4)
2007-08-23 01:00:00 :************** (7)
2007-08-23 00:00:00 :** (2)
2007-08-22 23:00:00 : (1)
2007-08-22 22:00:00 : (1)
2007-08-22 21:00:00 :****************** (9)
=> nil
>>