Ruby on Rails Sunday, May 29, 2011

I'm working on a community app that allows the residents of a village to log and
monitor the traffic going past their houses.

There are multiple locations which have many log entries with a traffic count and a
time block.

I want to let users view a location and see the average vehicles per day, as well as
the average for a given month.

I'm thinking it won't be very efficient to run though every log entry and calculate a
running average every time a user views the statistics page. I've never dealt with
data in this manner before so I'm not sure the best practice. I suppose I could
maintain a table with a record for each location. On creation or modification of a log
entry I could calculate the average and store it there for viewing. Again, not sure if
I'm heading the right direction.

The second part is calculating average for a give month, or indeed a year. I could
present the appropriate year/month select box but how can I pull records that only
relate to the given options?

I could probably pull every single record and compare the entry date to the given
parameters, then act on it if it fits the time period. Once more I'm thinking this
isn't the most efficient way to proceed.

Grateful for insight on this topic.

Thanks

Matt

No comments:

Post a Comment