On 10 August 2011 13:49, Robert Walker <[email protected]> wrote: > Owain wrote in post #1015933: >> My application is gradually being refined and it is becoming necessary >> to provide some statistics. I don't really want to add all of these >> into the main application logic since it is not critical. I would >> like to "observe" a bunch of models and classes and increment and >> decrement counters. So rather than have a bit of hideous AR finds to >> show me the number of orders by month I can observe the AR callbacks >> on event and increment "August 2011 Orders". I would also need to be >> able to reset via a Rake task or something similar. >> >> Has someone come across a Gem that provides this sort of functionality >> before I go and write it? > > [snipped lots of good stuff from Robert]
+1 to what Robert suggested, *but* first I would define methods of the models to provide the stats you are looking for (or define a new statistics class that provides the methods) then initially just do them as AR queries. You have said these will be 'hideous' but they should not be difficult to code. This may apparently be an inefficient way to achieve the answers but it will be simple and will get you functioning (and testable) code quickly and easily. Then, in the fullness of time, if it becomes clear that they take too long to run, you can worry about optimising the execution by running data mining techniques as Robert has suggested. As these will involve refactoring of the methods you started with it will have minimal (if any) effect on the rest of the app. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

