<commit_before>require 'observed/observer'
require 'observed/reporter'

module Observed
  class System

    def initialize(args={})
      @config = args[:config] if args[:config]
      @logger = args[:logger] if args[:logger]


    end

    def config=(config)
      @config = config
    end

    def config
      @config
    end

    def report(tag, time, data=nil)
      if data.nil?
        data = time
        time = self.now
      end
      reporters.each do |reporter|
        if reporter.match(tag)
          reporter.report(tag, time, data)
        end
      end
    end

    def run(observation_name=nil, data=nil)

      if observation_name
        observers_to_run = observers.reject { |o| o.tag != observation_name }
        fail "No configuration found for observation name '#{observation_name}'" if observers_to_run.empty?
      else
        observers_to_run = observers
      end

      observers_to_run.map do |input|
        input.observe data
      end

    end

    def now
      Time.now
    end

    def logger
      @logger || fail("BUG? No logger configured")
    end

    private

    def observers
      config.observers
    end

    def reporters
      config.reporters
    end

  end

  class YAML
    def observers
      config.observers
      @observers ||= begin

        observer_configs = config.observers

        observers = {}

        observer_configs.each do |tag, input_config|
          plugin_name = input_config[:plugin] || fail(RuntimeError, %Q|Missing plugin name for the tag "#{tag}" in "#{input_config}" in "#{config}".|)
          plugin = observer_plugins[plugin_name] || fail(RuntimeError, %Q|The plugin named "#{plugin_name}" is not found in plugins list "#{observer_plugins}".|)
          updated_config = input_config.merge(tag: tag)
          observer = plugin.new(updated_config)
          observer.configure(system: self, logger: logger)
          observers[tag] = observer
        end

        observers
      end
    end

    def reporters
      @reporters ||= begin

        reporter_configs = config.reporters

        reporters = {}

        reporter_configs.each do |tag_pattern, output_config|
          plugin_name = output_config[:plugin] || fail(RuntimeError, %Q|Missing plugin name for the output for "#{tag_pattern}" in "#{output_config}" in #{config}.|)
          plugin = reporter_plugins[plugin_name] || fail(RuntimeError, %Q|The plugin named "#{plugin_name}" is not found in plugins list "#{reporter_plugins}".|)
          updated_config = output_config.merge(tag_pattern: Regexp.new(tag_pattern))
          reporter = plugin.new(updated_config)
          reporter.configure(system: self, logger: logger)
          reporters[tag_pattern] = reporter
        end

        reporters
      end
    end
  end
end<commit_msg>Remove the unused class Observed::YAML<commit_after>require 'observed/observer'
require 'observed/reporter'

module Observed
  class System

    def initialize(args={})
      @config = args[:config] if args[:config]
      @logger = args[:logger] if args[:logger]


    end

    def config=(config)
      @config = config
    end

    def config
      @config
    end

    def report(tag, time, data=nil)
      if data.nil?
        data = time
        time = self.now
      end
      reporters.each do |reporter|
        if reporter.match(tag)
          reporter.report(tag, time, data)
        end
      end
    end

    def run(observation_name=nil, data=nil)

      if observation_name
        observers_to_run = observers.reject { |o| o.tag != observation_name }
        fail "No configuration found for observation name '#{observation_name}'" if observers_to_run.empty?
      else
        observers_to_run = observers
      end

      observers_to_run.map do |input|
        input.observe data
      end

    end

    def now
      Time.now
    end

    def logger
      @logger || fail("BUG? No logger configured")
    end

    private

    def observers
      config.observers
    end

    def reporters
      config.reporters
    end

  end

end
{'fraction_non_alphanumeric': 0.08859193268992824, 'fraction_numerical': 0.0, 'mean_word_length': 2.3104013104013106, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7449612', 'n_tokens_mistral': 1209, 'n_tokens_neox': 1169, 'n_words': 324}