Compiling counts of records by month and user
I have a dashboard I'm working on that basically lists all the users of the system and the number of activities they have in each month. I'm curious on what others thi开发者_C百科nk would be an efficient way to compile this data. I'm thinking I should eventually attempt to get it in this format:
{ user1 => { :jan => 13, :feb => 21, :mar => 4, ... }, user2 => { :jan => 16, :feb => 18.... }, .... }
Though I'm by no means married to that idea. Here is screenshot of what I'm working towards to help give you a better idea:
http://i.stack.imgur.com/HbSln.png
If you're using an activity log to track activity (one record per activity), then it should be pretty simple. Basically, COUNT(*) your activity records per user, and GROUP them by the month in which they occurred.
Alternatively, and depending on your requirements, you could also just have a single record per user, per month (instead of a log), with an incrementing count of the number of activities.
精彩评论