Skip to content

Instantly share code, notes, and snippets.

@ka8725
Created May 8, 2015 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ka8725/b4a988efb79414b39fd6 to your computer and use it in GitHub Desktop.
Save ka8725/b4a988efb79414b39fd6 to your computer and use it in GitHub Desktop.
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
@ka8725
Copy link
Author

ka8725 commented May 8, 2015

  1. Put it in the file ~/.rake/gitstats.rake.
  2. Go to a project under git
  3. rake -g gitst
  4. open gitstats/index.html

@dagolinuxoid
Copy link

mkdir ~/.rake/ && touch ~/.rake/gitstats.rake
execute 1. from the comment above
cd ~/.rake
git init
rake -g gitst
(chromium-browser gitstats/index.html &) && atom gitstats/index.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment