Skip to content

Commit

Permalink
Add rake task to truncate data to latest 24 hours
Browse files Browse the repository at this point in the history
  • Loading branch information
Prathan Thananart committed Oct 25, 2011
1 parent 2dc7d69 commit 15c9f2c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/models/zone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,13 @@ def metadata
def to_s
id
end


def update_statistics!
counts = reports.where{created_at > 1.day.ago}.group{flooded}.count
self.positive_count = counts[true] || 0
self.negative_count = counts[false] || 0
self.reports_count = positive_count + negative_count
save!
end
end
4 changes: 4 additions & 0 deletions lib/tasks/data.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
desc "Truncate recent report data"
task :truncate => :environment do
Zone.all.map &:update_statistics!
end

0 comments on commit 15c9f2c

Please sign in to comment.