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 42 43 44 45 46 |
# File 'lib/tdx/base.rb', line 38 def initialize(uri, opts) @uri = uri @opts = opts @issues = nil @pure = nil @hoc = nil @logopts = '--ignore-space-change --no-color --find-copies-harder \ --ignore-all-space --ignore-submodules -M --diff-filter=ACDM' end |
Instance Method Details
#svg ⇒ Object
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 125 126 127 128 129 |
# File 'lib/tdx/base.rb', line 48 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' #{@logopts} " + (@opts[:sha] ? @opts[:sha] : 'HEAD'), path ).stdout.split(/\n/).map { |c| c.split(' ') } puts "Date\t\t\tCode\tTests\tIssues\tSHA\tIdx" metrics = commits.each_with_index.map do |c, i| Exec.new("git checkout --quiet --force #{c[0]}", path).stdout pure = pure(path, c[0]) m = { date: c[1], code: pure, tests: hoc(path, c[0]) - pure, issues: issues(commits)[c[0]], sha: c[0] } puts "#{m[:date][0, 16]}\t#{m[:code]}\t#{m[:tests]}\t\ #{m[:issues]}\t#{m[:sha][0, 7]}\t#{i}/#{commits.size}" m end dat = if @opts[:data] File.new(@opts[:data], 'w+') else Tempfile.new('tdx') end metrics.select { |m| m[:code] > 0 }.each do |m| dat << [ m[:date], m[:code], m[:tests], m[:issues], m[:sha] ].join(' ') + "\n" end dat.close svg = Tempfile.new('tdx') gpi = [ "set output \"#{svg.path}\"", 'set terminal svg size 720, 360', 'set lmargin 7', 'set rmargin 5', 'set termoption font "monospace,10"', 'set xdata time', 'set border lc rgb "gray"', 'set style fill solid', 'set timefmt "%Y-%m"', 'set grid linecolor rgb "gray"', 'set autoscale y', 'set multiplot layout 2,1', 'set ytics format "%.0fK" textcolor rgb "black"', 'set y2tics format "%.0f" textcolor rgb "#DA6D1A"', 'set autoscale y2', 'set xtics format ""', [ "plot \"#{dat.path}\"", ' u 1:($2/1000) w l t "Code" lw 2 lc rgb "#2B7947"', ', "" u 1:($3/1000) w l t "Tests" lw 2 lc rgb "#C80604"', ', "" u 1:4 w l t "Issues" lc rgb "#DA6D1A" axes x1y2' ].join(' '), 'unset y2tics', 'unset title', 'set tmargin 0', 'set xtics format "%b/%y" font "monospace,8" textcolor rgb "gray"', 'set ytics format "%.0f%%" textcolor rgb "#C80604"', [ "plot \"#{dat.path}\"", 'u 1:(100*$3/($2+$3)) pt 7 ps 1 lc rgb "#C80604" notitle' ].join(' '), 'unset multiplot' ] Exec.new("gnuplot -e '#{gpi.join('; ')}'").stdout FileUtils.rm_rf(path) File.delete(dat) xml = File.read(svg) File.delete(svg) xml end |