<commit_before>module Wiresnark module Runner

  def self.run file, env = Object.new.extend(DSL::WiresnarkDSL)
    env.instance_eval File.read file

    env.generator_blocks.each do |block|
      gen = Object.new.extend DSL::GeneratorDSL
      gen.instance_eval &block

      case
      when gen.count
        Interface.new(gen.interface).inject Generator.generate(gen), (gen.verbose ? $stdout : nil)
      when gen.phase_usecs
        iface = Interface.new gen.interface
        phase_times = Hash[gen.phase_types.zip gen.phase_usecs]
        phase_pckts = Hash[gen.phase_types.map { |type| [gen.type(type), Generator.generate(gen, phase_times[type])] }]
        phase_times.cycle(gen.cycles) do |type, time|
          stop = Time.now + (time / 1_000_000.0)
          catch :next_type do
            phase_pckts[type].cycle do |packet|
              iface.inject [packet], (gen.verbose ? $stdout : nil)
              throw :next_type if Time.now > stop
            end
          end
        end
      end
    end

    env.monitor_blocks.each do |block|
      mon = Object.new.extend DSL::MonitorDSL
      mon.instance_eval &block
      Interface.new(mon.interface).stream.each do |bin|
        puts "#{mon.interface} ->\t#{Packet.new bin}" if mon.verbose?
      end
    end
  end

end end<commit_msg>refactor Runner.run<commit_after>module Wiresnark module Runner

  def self.run file, env = Object.new.extend(DSL::WiresnarkDSL)
    env.instance_eval File.read file

    env.generator_blocks.each do |block|
      gen = Object.new.extend DSL::GeneratorDSL
      gen.instance_eval &block

      iface  = Interface.new gen.interface
      output = gen.verbose ? $stdout : nil

      case
      when gen.count
        iface.inject Generator.generate(gen), output
      when gen.phase_usecs
        phase_times = Hash[gen.phase_types.zip gen.phase_usecs]
        phase_pckts = Hash[gen.phase_types.map { |type| [gen.type(type), Generator.generate(gen, phase_times[type])] }]
        phase_times.cycle(gen.cycles) do |type, time|
          stop = Time.now + (time / 1_000_000.0)
          catch :next_type do
            phase_pckts[type].cycle do |packet|
              iface.inject [packet], output
              throw :next_type if Time.now > stop
            end
          end
        end
      end
    end

    env.monitor_blocks.each do |block|
      mon = Object.new.extend DSL::MonitorDSL
      mon.instance_eval &block
      Interface.new(mon.interface).stream.each do |bin|
        puts "#{mon.interface} ->\t#{Packet.new bin}" if mon.verbose?
      end
    end
  end

end end
{'fraction_non_alphanumeric': 0.10379550735863671, 'fraction_numerical': 0.006196746707978312, 'mean_word_length': 2.3415265200517466, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2191059', 'n_tokens_mistral': 842, 'n_tokens_neox': 819, 'n_words': 186}