<commit_before>require 'ruby-progressbar'
require 'thwait'

module GasLoadTester
  class Test
    attr_accessor :client, :time, :results

    DEFAULT = {
      client: 1000,
      time: 300
    }

    def initialize(args = {})
      args ||= {}
      args[:client] ||= args['client']
      args[:time] ||= args['time']
      args.reject!{|key, value| value.nil? }
      args = DEFAULT.merge(args)

      self.client = args[:client]
      self.time = args[:time]
      self.results = {}
      @run = false
    end

    def run(args = {}, &block)
      args ||= {}
      args[:output] ||= args['output']
      args[:file_name] ||= args['file_name']
      args[:header] ||= args['header']
      args[:description] ||= args['description']
      puts "Running test (client: #{self.client}, time: #{self.time})"
      @progressbar = ProgressBar.create(
        :title => "Load test",
        :starting_at => 0,
        :total => self.time+10,
        :format => "%a %b\u{15E7}%i %p%% %t",
        :progress_mark  => ' ',
        :remainder_mark => "\u{FF65}"
      )
      load_test(block)
      if args[:output]
        export_file({file_name: args[:file_name], header: args[:header], description: args[:description]})
      end
    ensure
      @run = true
    end

    def is_run?
      @run
    end

    def request_per_second
      self.client/self.time.to_f
    end

    def export_file(args = {})
      args ||= {}
      file = args[:file_name] || ''
      chart_builder = GasLoadTester::ChartBuilder.new(file_name: file, header: args[:header], description: args[:description])
      chart_builder.build_body(self)
      chart_builder.save
    end

    def summary_min_time
      all_result_time.sort.first*1000
    end

    def summary_max_time
      all_result_time.sort.last*1000
    end

    def summary_avg_time
      all_result_time.sum.fdiv(all_result_time.size)*1000
    end

    def summary_success
      self.results.collect{|key, values| values.select{|val| val.pass }.count }.flatten.sum
    end

    def summary_error
      self.results.collect{|key, values| values.select{|val| !val.pass }.count }.flatten.sum
    end

    private

    def all_result_time
      self.results.collect{|key, values| values.collect(&:time) }.flatten
    end
<commit_msg>fix: undefined method 'sum' for #<Array><commit_after>require 'ruby-progressbar'
require 'thwait'

module GasLoadTester
  class Test
    attr_accessor :client, :time, :results

    DEFAULT = {
      client: 1000,
      time: 300
    }

    def initialize(args = {})
      args ||= {}
      args[:client] ||= args['client']
      args[:time] ||= args['time']
      args.reject!{|key, value| value.nil? }
      args = DEFAULT.merge(args)

      self.client = args[:client]
      self.time = args[:time]
      self.results = {}
      @run = false
    end

    def run(args = {}, &block)
      args ||= {}
      args[:output] ||= args['output']
      args[:file_name] ||= args['file_name']
      args[:header] ||= args['header']
      args[:description] ||= args['description']
      puts "Running test (client: #{self.client}, time: #{self.time})"
      @progressbar = ProgressBar.create(
        :title => "Load test",
        :starting_at => 0,
        :total => self.time+10,
        :format => "%a %b\u{15E7}%i %p%% %t",
        :progress_mark  => ' ',
        :remainder_mark => "\u{FF65}"
      )
      load_test(block)
      if args[:output]
        export_file({file_name: args[:file_name], header: args[:header], description: args[:description]})
      end
    ensure
      @run = true
    end

    def is_run?
      @run
    end

    def request_per_second
      self.client/self.time.to_f
    end

    def export_file(args = {})
      args ||= {}
      file = args[:file_name] || ''
      chart_builder = GasLoadTester::ChartBuilder.new(file_name: file, header: args[:header], description: args[:description])
      chart_builder.build_body(self)
      chart_builder.save
    end

    def summary_min_time
      all_result_time.sort.first*1000
    end

    def summary_max_time
      all_result_time.sort.last*1000
    end

    def summary_avg_time
      all_result_time.inject(0, :+).fdiv(all_result_time.size)*1000
    end

    def summary_success
      self.results.collect{|key, values| values.select{|val| val.pass }.count }.flatten.inject(0, :+)
    end

    def summary_error
      self.results.collect{|key, values| values.select{|val| !val.pass }.count }.flatten.inject(0, :+)
    end

    private

    def all_result_time
      self.results.collect{|key, values| values.collect(&:time) }.flatten
    end

{'fraction_non_alphanumeric': 0.1458469587965991, 'fraction_numerical': 0.012426422498364944, 'mean_word_length': 2.5927956147220046, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2199497', 'n_tokens_mistral': 1566, 'n_tokens_neox': 1483, 'n_words': 302}