Skip to content

Instantly share code, notes, and snippets.

@michaelfeathers
Created October 4, 2012 23:39
Show Gist options
  • Save michaelfeathers/3837149 to your computer and use it in GitHub Desktop.
Save michaelfeathers/3837149 to your computer and use it in GitHub Desktop.
Turbulence Light - generates a turbulence dataset for a Ruby git repository
def complexity filename
File.read(filename).lines.grep(/^([ \t]*)/) { $1 }.map(&:length).reduce(0, :+)
end
commit_filenames = `git log --name-only | grep \.rb$`.lines \
.map(&:strip) \
.reject { |fn| fn.include? "_spec" } \
.reject { |fn| fn.include? "vendor" }
filenames = commit_filenames.uniq
commits = Hash[filenames.zip([0] * filenames.count)]
commit_filenames.each { |fn| commits[fn] = commits[fn] + 1 }
csv_filename = "results.csv"
text = filenames.select {|fn| File.exist?(fn) }.map { |fn| "#{fn}, #{commits[fn]}, #{complexity(fn)}" }.join($/)
File.open(csv_filename,'w') { |f| f.write(text) }
`open #{csv_filename}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment