bin/cobench in cobench-0.0.24 vs bin/cobench in cobench-0.0.25

- old
+ new

@@ -72,10 +72,15 @@ end Encoding.default_external = Encoding::UTF_8 Encoding.default_internal = Encoding::UTF_8 +def div(a, b) + return 0 if b == 0 + a / b +end + def build_xml(opts, loog) if opts.token? api = Octokit::Client.new(:access_token => opts[:token]) else api = Octokit::Client.new @@ -148,15 +153,15 @@ end.inject(0, :+) data[u]['Score'] = { total: score } end averages = { 'HpP': { - f: lambda { |ms| ms['HoC'][:total] / ms['Pulls'][:total] }, + f: lambda { |ms| div(ms['HoC'][:total], ms['Pulls'][:total]) }, title: 'HoC per Pull' }, 'HpC': { - f: lambda { |ms| ms['HoC'][:total] / ms['Commits'][:total] }, + f: lambda { |ms| div(ms['HoC'][:total], ms['Commits'][:total]) }, title: 'HoC per Commit' } } data.each do |u, ms| averages.each do |k, a| @@ -192,10 +197,10 @@ xml.averages do data.map { |_, ms| ms.keys }.flatten.uniq.each do |t| next if t == 'Score' xml.w(id: t) do vals = data.values.map { |ms| ms[t][:total] }.select { |v| v > 0 } - xml.text(vals.inject(&:+) / vals.count) + xml.text(div(vals.inject(&:+), vals.count)) end end end xml.coders do data.each do |u, ms|