From e78d4ee00531a8a3c723fd8dec13cab0be67b95d Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Wed, 3 Oct 2012 13:39:02 +0200 Subject: [PATCH] preserve the stats script --- script/stats.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 script/stats.rb diff --git a/script/stats.rb b/script/stats.rb new file mode 100644 index 00000000..9d4ef771 --- /dev/null +++ b/script/stats.rb @@ -0,0 +1,30 @@ +require_relative '../config/environment' +require 'statistics' + +data = Statistics.daily_repository_counts +exit if data.empty? + +next_thousand = 1000 +last_time = data.first.first + +growth = data.inject([[data.shift.last, 0]]) do |growth, (time, num)| + growth << [num, num - growth.last.first] +end +two_weeks = growth.slice(-14, 14) +average = (two_weeks.inject(0) { |sum, (total, growth)| sum + growth }.to_f / two_weeks.length).round(0) + +data.each do |(time, num)| + if num >= next_thousand + thousand = num - (num % 1000) + days = (time - last_time) / (1000 * 60 * 60 * 24) + puts "#{thousand} reached on #{Time.at(time / 1000).strftime('%Y-%m-%d')} after #{days} days" + next_thousand = thousand + 1000 + last_time = time + end +end +remaining = next_thousand - data.last.last + +puts +puts "Average growth within last 14 days: #{average} repositories.\n" +puts "Will reach #{next_thousand} repositories in #{(remaining.to_f / average).round(2)} days." +