I’m looking to build an analytics dashboard for my data in a rails application.
Let’s say I have a list of request types “Fizz”, “Buzz”, “Bang”, “Bar”.
I want to display a count for each day based on type.
How should I do this?
Here is what I plan on doing:
- Add get_bazz_by_day, get_fizz_by_day, etc to the appropriate models.
- In each model get all records of type Fizz, then create an array that stores date and count.
- format in view so a JS library can format it into a pretty graph.
Does this sound reasonable?
Depending on number of records, your dashboard can soon get performance problems.
Step 1 is misleading. Don’t get the data for each day individually, try to get them all at once.
In Step 2 you can have the database do the the aggregation over days, with the group method.
See http://guides.rubyonrails.org/active_record_querying.html#group
In Step 3 you need to take care that days without any fizzbuzz are still displayed, as they are not returned in the query.