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? Thanks, Chirag --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
What''s a scalar in this context ? Did I miss something ? If you''re looking for raw performance, write a stored procedure. On 8/3/07, chirag <patelc75-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> > 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? > > Thanks, > Chirag > > > > >-- Cheers! - Pratik http://m.onkey.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---