Class: TDX::Base
- Inherits:
-
Object
- Object
- TDX::Base
- Defined in:
- lib/tdx/base.rb
Overview
Base class
Instance Method Summary collapse
-
#initialize(uri, opts) ⇒ Base
constructor
A new instance of Base.
- #svg ⇒ Object
Constructor Details
#initialize(uri, opts) ⇒ Base
Returns a new instance of Base.
38 39 40 41 |
# File 'lib/tdx/base.rb', line 38 def initialize(uri, opts) @uri = uri @opts = opts end |
Instance Method Details
#svg ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/tdx/base.rb', line 43 def svg version = Exec.new('git --version').stdout.split(/ /)[2] raise "git version #{version} is too old, upgrade it to 2.0+" unless Gem::Version.new(version) >= Gem::Version.new('2.0') path = checkout commits = Exec.new( 'git log "--pretty=format:%H %cI" ' + (@opts[:sha] ? @opts[:sha] : 'HEAD'), path ).stdout.split(/\n/).map { |c| c.split(' ') } issues = issues(commits) puts "Date\t\t\tTest\tHoC\tFiles\tLoC\tIssues\tSHA\tIdx" metrics = commits.each_with_index.map do |c, i| Exec.new("git checkout --quiet #{c[0]}", path).stdout m = { date: c[1], pure: pure(path), hoc: hoc(path), files: files(path), loc: loc(path), issues: issues[c[0]], sha: c[0] } puts "#{m[:date][0, 16]}\t#{m[:pure]}\t#{m[:hoc]}\t#{m[:files]}\t\ #{m[:loc]}\t#{m[:issues]}\t#{m[:sha][0, 7]}\t#{i}/#{commits.size}" m end max = { pure: 0, hoc: 0, files: 0, loc: 0, issues: 0 } max = metrics.inject(max) do |m, t| { pure: [m[:pure], t[:pure], 1].max, hoc: [m[:hoc], t[:hoc], 1].max, files: [m[:files], t[:files], 1].max, loc: [m[:loc], t[:loc], 1].max, issues: [m[:issues], t[:issues], 1].max } end dat = if @opts[:data] File.new(@opts[:data], 'w+') else Tempfile.new('tdx') end metrics.each do |m| dat << [ m[:date], 100.0 * m[:pure] / max[:pure], 100.0 * (m[:pure] - m[:hoc]) / (max[:pure] - max[:hoc]), 100.0 * m[:hoc] / max[:hoc], 100.0 * m[:files] / max[:files], 100.0 * m[:loc] / max[:loc], 100.0 * m[:issues] / max[:issues], m[:sha] ].join(' ') + "\n" end dat.close svg = Tempfile.new('tdx') gpi = [ "set output \"#{svg.path}\"", 'set terminal svg size 700, 260', 'set termoption font "monospace,10"', 'set xdata time', 'set timefmt "%Y-%m"', 'set ytics format "%.0f%%" textcolor rgb "black"', 'set grid linecolor rgb "gray"', 'set xtics format "%b/%y" font "monospace,8" textcolor rgb "black"', 'set autoscale', 'set style fill solid', 'set boxwidth 0.75 relative', [ "plot \"#{dat.path}\" using 1:3 with lines", 'title "Test HoC" linecolor rgb "#81b341"', ', "" using 1:4 with lines title "HoC" linecolor rgb "red"', ', "" using 1:7 with lines title "Issues" linecolor rgb "orange"' ].join(' ') ] Exec.new("gnuplot -e '#{gpi.join('; ')}'").stdout FileUtils.rm_rf(path) File.delete(dat) xml = File.read(svg) File.delete(svg) xml end |