Created
May 8, 2015 20:09
-
-
Save ka8725/b4a988efb79414b39fd6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
directory 'gitstats' | |
EXCLUDE_FILES = /(^vendor\/)|(^public\/)|(\.(jpg|png|gif|bmp|yaml|yml|jar|zip|gz|rar)$)/.freeze | |
Member = Struct.new(:email, :lines) do | |
include Comparable | |
def <=>(other) | |
self.lines <=> other.lines | |
end | |
end | |
desc 'Grows statistic of git for the project in current folder and saves it to gitstats/index.html' | |
task :gitst => 'gitstats' do | |
filelist = `git ls-files --exclude-standard`.split.reject do |x| | |
x =~ EXCLUDE_FILES | |
end | |
res = {} | |
filelist.map do |file| | |
puts "Processing: #{file}" | |
blamelist = `git blame -e #{file} | cut -d' ' -f 2`.split.map do |line| | |
line.gsub!(/[()<>]/, '') | |
end.compact.sort.group_by(&:to_s).map do |email, group| | |
res[email] ||= 0 | |
res[email] += group.size | |
end | |
end | |
res = res.reduce([]) do |memo, (email, lines_number)| | |
memo << Member.new(email, lines_number) | |
memo | |
end | |
res = res.sort.reverse | |
res = res.map { |el| [el.email, el.lines] } | |
File.open('gitstats/index.html', 'w+') do |f| | |
f << %Q{ | |
<html> | |
<head> | |
<!--Load the AJAX API--> | |
<script type="text/javascript" src="https://www.google.com/jsapi"></script> | |
<script type="text/javascript"> | |
// Load the Visualization API and the piechart package. | |
google.load('visualization', '1.0', {'packages':['corechart', 'table']}); | |
// Set a callback to run when the Google Visualization API is loaded. | |
google.setOnLoadCallback(drawChart); | |
// Callback that creates and populates a data table, | |
// instantiates the pie chart, passes in the data and | |
// draws it. | |
function drawChart() { | |
// Create the data table. | |
data = new google.visualization.DataTable(); | |
data.addColumn('string', 'Developer'); | |
data.addColumn('number', 'Count strings'); | |
items = #{res}; | |
data.addRows(items); | |
// Set chart options | |
var options = {'title':'Git stats', | |
'width':700, | |
'height':600}; | |
// Instantiate and draw our chart, passing in some options. | |
var chart = new google.visualization.PieChart(document.getElementById('chart_div')); | |
chart.draw(data, options); | |
var table = new google.visualization.Table(document.getElementById('table_div')); | |
table.draw(data, {showRowNumber: true}); | |
google.visualization.events.addListener(table, 'select', function() { | |
var row = table.getSelection()[0].row; | |
alert('You selected ' + data.getValue(row, 0)); | |
}); | |
} | |
</script> | |
</head> | |
<body> | |
<h2>Filtered out files: #{EXCLUDE_FILES}</h2> | |
<!--Div that will hold the pie chart--> | |
<div id="table_div"></div> | |
<br /> | |
<div id="chart_div" styles="margin:auto"></div> | |
</body> | |
</html> | |
} | |
end | |
end |
dagolinuxoid
commented
Mar 4, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment