I have a database table of timestamped scalars with each row (scalar)
added every 15 seconds. I want to process a day’s worth of data so
that an average scalar of every 30 minutes is returned. I would like
to return the averaged data in an array. What is the most effecient
way to do this with performance in mind? Could the ‘group’ option in
the ‘average’ method for a model be used?
I have a database table of timestamped scalars with each row
(scalar) added every 15 seconds. I want to process a day’s
worth of data so that an average scalar of every 30 minutes
is returned. I would like to return the averaged data in an
array. What is the most effecient way to do this with
performance in mind? Could the ‘group’ option in the
‘average’ method for a model be used?
ActiveRecord doesn’t really have much to offer you in this regard, this
is largely a pure SQL question. What you need to do is add a column to
the resultset with the time rounded to the nearest half an hour - either
by decorating the data with a view or, probably more efficiently, doing
it on insert. Given that, you can easily average and group the data
either in raw SQL or using ActiveRecord’s aggregation methods. The
latter might look like:
Timestamps.average(:scalar, :group=>‘half_hour’)
donald
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.