#!/usr/bin/env ruby require 'rubygems' require 'gruff' require File.dirname(__FILE__) + '/../config/environment' def posts(filename, days=6) data = {} for method in ['web', 'mail'] data[method] = [] days.downto(0) do |n| data[method] << Post.count(['post_method = ? AND created_at BETWEEN ? AND ?', method, (n + 1).days.ago, n.days.ago]) end end total = Post.count g = Gruff::Line.new(480) g.title = "Posts (total: #{total})" g.data("Posts from Forum per day", data['web']) g.data("Posts from Mailing List per day", data['mail']) g.labels = {0 => "#{days} days ago", days => Time.now.strftime('%d.%m.%Y')} g.write(filename) end def registrations(filename, days=6) data = [] days.downto(0) do |n| data << User.count(['created_at BETWEEN ? AND ?', (n + 1).days.ago, n.days.ago]) end total = User.count g = Gruff::Line.new(480) g.title = "User Accounts (total: #{total})" g.data("User Accounts created per day", data) g.labels = {0 => "#{days} days ago", days => Time.now.strftime('%d.%m.%Y')} g.write(filename) end IMG_ROOT = RAILS_ROOT + '/public/images/stats/' posts(IMG_ROOT + 'posts.png', 10) registrations(IMG_ROOT + 'registrations.png', 14)