bin/cobench in cobench-0.0.7 vs bin/cobench in cobench-0.0.8

- old
+ new

@@ -89,43 +89,52 @@ 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) + 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] 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? - v, t = [Random.new.rand(100), 'https://github.com/'] + measures = [{ title: 'Mock', total: Random.new.rand(100), href: 'https://github.com/' }] else - v, t = m.take(loog) + measures = m.take(loog) end - data[u][name] = [v, t] - loog.info("The value of #{u}/#{name} is #{v}") + 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 builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml| - xml.cobench(time: Time.now, days: opts[:days]) { - xml.coders { + xml.cobench(time: Time.now, days: opts[:days]) do + xml.titles do + data.map { |_, ms| ms.keys }.flatten.each do |t| + xml.title t + end + end + xml.coders do data.each do |u, ms| - xml.coder(id: u) { - xml.metrics { + xml.coder(id: u) do + xml.metrics do ms.each do |k, v| - xml.m(id: k, href: v[1]) { - xml.text v[0] - } + xml.m(id: k, href: v[:href]) do + xml.text v[:total] + end end - } - } + end + end end - } - } + end + end end index = File.join(home, 'index.xml') xml = builder.to_xml loog.debug(xml) File.write(index, xml)