I'm trying to return an array of counted values for consecutive date ranges (that will vary in distance), so that I have something like the following:
counted_values = [2,0,4,5,6,0,0,4,2]
So far I've written something that works but makes me shudder slightly, as I'm sure there's a more Rubyist/Rails way of doing it.
Current code:
startdate = @event.running_from
enddate = @event.running_to
totaltime = enddate - startdate
timesegment = totaltime / 20
segmentstart = startdate
segmentend = startdate + timesegment
@counted_values = []
20.times {
count = SignUp.count(:conditions => { :event_id => @event.id, :created_at => segmentstart..segmentend})
@counted_values << count
segmentstart = segmentend
segmentend = segmentend + timesegment
}
Can anyone help clean this up a bit?