Created
August 18, 2011 10:59
-
-
Save damphyr/1153835 to your computer and use it in GitHub Desktop.
Plot the LOC history for a bunch of svn revisions
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
#manually add the revisions or grep them out of svn log | |
revisions=[] | |
require 'psych' | |
require 'yaml' | |
require 'rubygems' | |
require 'fileutils' | |
require 'patir/command' | |
require 'json' | |
include FileUtils | |
#what to check out | |
repo = "svn://foo.bar/repo/code" | |
#directory to check out in | |
target = "builder_loc_history" | |
#clean previous runs | |
rm_rf(target,:verbose=>false) if File.exists?(target) | |
mkdir_p(target,:verbose=>false) | |
locs_ruby=[] | |
locs_comments=[] | |
file_numbers=[] | |
entries=0 | |
revisions.reverse.each do |revision| | |
puts revision | |
svn_cmd_line="svn co #{repo} #{target} --revision #{revision}" | |
cloc_cmd_line = "cloc-1.53.exe builder_loc_history --yaml -q" | |
svn_cmd=Patir::ShellCommand.new(:cmd=>svn_cmd_line) | |
cloc_cmd=Patir::ShellCommand.new(:cmd=>cloc_cmd_line) | |
#TODO: some error handling here would be sane | |
svn_cmd.run | |
cloc_cmd.run | |
loc=YAML.load(cloc_cmd.output) | |
locs_ruby<<[entries,loc["Ruby"]["code"]] | |
locs_comments<<[entries,loc["Ruby"]["comment"]] | |
file_numbers<<[entries,loc["Ruby"]["nFiles"]] | |
entries+=1 | |
end | |
#fastest way to generate some HTML | |
#you still need the .js files in the same directory as the .html | |
#for this to work | |
results_page=<<-EOT | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
<title>LOCs & files</title> | |
<link href="layout.css" rel="stylesheet" type="text/css"> | |
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="excanvas.min.js"></script><![endif]--> | |
<script language="javascript" type="text/javascript" src="jquery.js"></script> | |
<script language="javascript" type="text/javascript" src="jquery.flot.js"></script> | |
</head> | |
<body> | |
<div id="placeholder" style="width:600px;height:300px"></div> | |
<script type="text/javascript"> | |
$(function () { | |
var r = #{locs_ruby.to_json}; | |
var c = #{locs_comments.to_json}; | |
var f = #{file_numbers.to_json}; | |
data = [{data:r,label:'code'},{data:c,label:'comments'} ] | |
var plot=$.plot($("#placeholder"), data,{ | |
series: { | |
lines: { show: true } | |
}, | |
crosshair: { mode: "x"}, | |
grid: { hoverable: true, autoHighlight: false } | |
}); | |
var legends = $("#placeholder .legendLabel"); | |
legends.each(function () { | |
// fix the widths so they don't jump around | |
$(this).css('width', $(this).width()); | |
}); | |
var updateLegendTimeout = null; | |
function updateLegend(latestPosition) { | |
updateLegendTimeout = null; | |
var axes = plot.getAxes(); | |
if (latestPosition.x < axes.xaxis.min || latestPosition.x > axes.xaxis.max || | |
latestPosition.y < axes.yaxis.min || latestPosition.y > axes.yaxis.max) | |
return; | |
var i, j, dataset = plot.getData(); | |
for (i = 0; i < dataset.length; ++i) { | |
var series = dataset[i]; | |
// find the nearest points, x-wise | |
for (j = 0; j < series.data.length; ++j) | |
if (series.data[j][0] > latestPosition.x) | |
break; | |
// now interpolate | |
var y, p1 = series.data[j - 1], p2 = series.data[j]; | |
if (p1 == null) | |
y = p2[1]; | |
else if (p2 == null) | |
y = p1[1]; | |
else | |
y = p1[1] + (p2[1] - p1[1]) * (latestPosition.x - p1[0]) / (p2[0] - p1[0]); | |
legends.eq(i).text(series.label.replace(/=.*/, "= " + y.toFixed(0))); | |
} | |
} | |
$("#placeholder").bind("plothover", function (event, pos, item) { | |
latestPosition = pos; | |
if (!updateLegendTimeout) | |
updateLegendTimeout = setTimeout(updateLegend(latestPosition), 50); | |
}); | |
}); | |
</script> | |
</body> | |
</html> | |
EOT | |
File.open("loc_history.html",'wb'){|f| f.write(results_page)} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment