From c3f93b789b4959322d67bcb341f8074a96ba9a71 Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Tue, 22 Oct 2013 01:48:33 +0200 Subject: [PATCH] add repos stats script --- script/repos_stats.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 script/repos_stats.rb diff --git a/script/repos_stats.rb b/script/repos_stats.rb new file mode 100644 index 00000000..0a1bead3 --- /dev/null +++ b/script/repos_stats.rb @@ -0,0 +1,26 @@ +$stdout.sync = true + +Repository.where('last_build_finished_at is not null').count(group: :github_language) + +rates = Repository.where('last_build_finished_at is not null').count(group: [:last_build_state, :github_language]) +groups = rates.group_by { |k, v| k[1] } +stats = groups.map do |lang, values| + values.inject({ "language" => lang || 'unknown' }) do |result, (state, count)| + result.merge(state[0] => count) + end +end + +keys = %w(language total passed failed errored cancelled) +puts keys.join(',') + +rows = stats.map do |stat| + values = stat.values + row = [values.shift] + row << stat.values[1..-1].inject(&:+) + keys[1..-1].each { |key| row << (stat[key] || 0) } + row +end + +rows = rows.sort_by { |row| row[1] }.reverse +csv = rows.map { |row| row.join(',') } +puts csv.join("\n")