Skip to content

Commit

Permalink
add repos stats script
Browse files Browse the repository at this point in the history
  • Loading branch information
svenfuchs committed Oct 7, 2014
1 parent bda2797 commit c3f93b7
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions script/repos_stats.rb
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit c3f93b7

Please sign in to comment.