Topic: Aggregating statistical data the Rails way
I am trying to calculate some API traffic data for statistic purposes and wondering about the best way to structure this in Rails.
I have a model that tracks the 'received_at' date of a 'Hit'. Hits are create when calls are made to the API in my system.
The SQL for the query I want to run looks like this
SELECT count(*) total, date(received_at)
GROUP BY received_at
ORDER total DESC
Basically counts the hits for each day and returns. BUT this query doesn't return Hit models.
Should I amend the hit model to have a virtual 'Total' attribute?
Should I create a seperate model to aggregate this information? Something like a HitTotal model with a total and date?
What's the Rails way?
FiniteStateMachine - Software Development for Social Networks