Permalink
Browse files

refactor + a few fixes

  • Loading branch information...
1 parent 980fba9 commit 716b9d8095f3ec92189051988ce2f5eb34fa37dd @igrigorik igrigorik committed Dec 15, 2011
Showing with 27 additions and 11 deletions.
  1. +18 −1 bin/bugspots
  2. +9 −10 lib/bugspots/scanner.rb
View
@@ -13,4 +13,21 @@ OptionParser.new do |opts|
opts.banner = "Usage: bugspots /path/to/git/repo"
end.parse!
-Bugspots.scan(ARGV[0])
+puts "Scanning #{ARGV[0]} repo".foreground(:green)
+
+fixes, spots = Bugspots.scan(ARGV[0])
+
+puts "\tFound #{fixes.size} bugfix commits, with #{spots.size} hotspots:".foreground(:yellow)
+puts
+
+puts "\tFixes:".foreground(:green).underline
+fixes.each do |fix|
+ puts "\t\t- #{fix.message}".foreground(:yellow)
+end
+
+puts "\n"
+puts "\tHotspots:".foreground(:green).underline
+spots.each do |spot|
+ puts "\t\t#{spot.score}".foreground(:red) + " - #{spot.file}".foreground(:yellow)
+end
+
View
@@ -3,32 +3,31 @@
module Bugspots
Fix = Struct.new(:message, :date, :files)
+ Spot = Struct.new(:file, :score)
- def self.scan(repo)
- puts "Scanning #{repo} repo".foreground(:green)
+ def self.scan(repo, depth = 500)
repo = Grit::Repo.new(repo)
fixes = []
- repo.commits('master', 500).each do |commit|
+ repo.commits('master', depth).each do |commit|
if commit.message =~ /fix(es|ed)|close(s|d)/
files = commit.stats.files.map {|s| s.first}
- fixes << Fix.new(commit.message, commit.date, files)
+ fixes << Fix.new(commit.short_message, commit.date, files)
end
end
hotspots = Hash.new(0)
fixes.each do |fix|
fix.files.each do |file|
t = 1 - ((Time.now - fix.date).to_f / (Time.now - fixes.last.date))
- hotspots[file] += (1/(1+Math.exp(-12*t)+12))
+ hotspots[file] += 1/(1+Math.exp((-12*t)+12))
end
end
- puts "\tFound #{fixes.size} bugfix commits, with #{hotspots.size} hotspots:".foreground(:yellow)
- puts
-
- hotspots.sort_by {|k,v| v}.reverse.each do |spot|
- puts "\t#{spot.last.round(2)}".foreground(:red) + " - #{spot.first}".foreground(:yellow)
+ spots = hotspots.sort_by {|k,v| v}.reverse.collect do |spot|
+ Spot.new(spot.first, spot.last.round(4))
end
+
+ return fixes, spots
end
end

0 comments on commit 716b9d8

Please sign in to comment.