#!/usr/bin/env ruby
# SPDX-License-Identifier: GPL-2.0-only

# frozen_string_literal: true

CCI_SRC = File.dirname(__dir__)

require 'optparse'
require "#{CCI_SRC}/lib/matrix2"
require_relative '../lib/stats.rb'

File.umask 0o002

opt_parser = OptionParser.new do |opts|
  opts.banner = 'Usage: result2stats result_root'
  opts.separator 'eg: result2stats /srv/result/iperf/vm-1p1g/2020-09-30/crystal.91198'
  opts.separator ''
  opts.separator 'options:'

  opts.on_tail('-h', '--help', 'show this message') do
    puts opts
    exit
  end
end

argv = if ARGV == []
         ['-h']
       else
         ARGV
       end

opt_parser.parse!(argv)
RESULT_ROOT = argv[0] || ENV['RESULT_ROOT']
ENV['RESULT_ROOT'] = RESULT_ROOT

stats = Stats.new(RESULT_ROOT)
stats.extract_stats
create_stats RESULT_ROOT
