bin/cobench in cobench-0.0.10 vs bin/cobench in cobench-0.0.11

- old
+ new

@@ -49,10 +49,11 @@ o.bool '--dry', 'Make no real round trips to GitHub' o.integer '--days', 'How many days to measure', default: 7 o.string '--to', 'Directory where to save all files to', default: './cobench' o.string '--token', 'GitHub authentication token' o.array '--coder', 'GitHub nickname of a coder to track' + o.array '--metrics', 'Names of metrics to use (all by default)' o.array '--include', 'Mask of GitHub repo to include, e.g. yegor256/*' o.array '--exclude', 'Mask of GitHub repo to exclude' end if opts.help? @@ -89,33 +90,54 @@ api = Octokit::Client.new loog.warn("Connecting to GitHub without a token, this may lead to errors, use --token") end api.auto_paginate = true api = Obk.new(api, pause: 2000) + loog.info("Reading GitHub data for the last #{opts[:days]} days") titles = {} opts[:coder].each do |u| loog.info("Scanning #{u}...") data[u] = {} Dir[File.join(__dir__, '../lib/cobench/metrics/*.rb')].each do |f| name = File::basename(f).split('.')[0] + if !opts[:metrics].empty? && !opts[:metrics].include?(name) + loog.info("Ignoring #{u}/#{name} due to --metrics") + next + end type = "Cobench::#{name.capitalize}" loog.info("Reading #{u}/#{name}...") require_relative f m = type.split('::').reduce(Module, :const_get).new(api, u, opts) if opts.dry? measures = [ - { title: 'Test1', total: Random.new.rand(100), href: 'https://github.com/' }, - { title: 'Test2', total: Random.new.rand(100), href: 'https://github.com/' } + { title: 'Issues', total: Random.new.rand(100), href: 'https://github.com/' }, + { title: 'Pulls', total: Random.new.rand(100), href: 'https://github.com/' } ] else measures = m.take(loog) end measures.each do |d| data[u][d[:title]] = { total: d[:total], href: d[:href] } titles[d[:title]] = d[:title] loog.info("The value of #{u}/#{d[:title]} is #{d[:total]}") end end + end + data.each do |u, ms| + score = ms.map do |t, h| + h[:total] * if t == 'HoC' + 1 + elsif t == 'Pulls' + 100 + elsif t == 'Issues' + 50 + elsif t == 'Commits' + 5 + else + raise "Unknown title '#{t}'" + end + end.inject(0, :+) + data[u]['Score'] = { total: score, href: '' } end builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml| xml.cobench(time: Time.now, days: opts[:days]) do xml.titles do data.map { |_, ms| ms.keys }.flatten.each do |t|