Created
August 13, 2011 23:36
-
-
Save joshellington/1144369 to your computer and use it in GitHub Desktop.
MongoMapper counting loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
date_started = Date.parse("2011-08-09") | |
date_now = Date.today | |
@by_day = [] | |
@days_passed = date_now.mjd - date_started.mjd | |
(1..@days_passed).each do |day| | |
date = Kit.where(:created_at.gte => day.days.ago, :created_at.lte => (day-1).days.ago).fields(:created_at).first | |
count = Kit.count(:created_at.gte => day.days.ago, :created_at.lte => (day-1).days.ago) | |
@by_day.push("date" => date.created_at.strftime("%m/%d"), "count" => count) | |
end | |
@data = @by_day.reverse.to_json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment