<commit_before>module Sim

  class Level
    include Celluloid
    include Celluloid::Logger

    trap_exit :actor_died
    finalizer :stop_subactors


    def self.attach
      level = new
      level.listen_to_parent_process
    end

    def build config_file
      config = Buildable.load_config(config_file)
      Sim::TimeUnit.new config[:time_unit]
      @queue = Sim::Queue.new_link
      create(config)
    end

    def listen_to_parent_process
      Celluloid.logger = ::Logger.new($stderr) # TODO log to a file
      @process = Popen::SubProcess.new
      @process.listen(self)
    end

    # process a message and returns an answer
    def process_message message
      if message.key? :player
        player = find_player message[:player]
        player.process_message message
      else
        case message[:action]
        when 'build'
          build message[:params][:config_file]<commit_msg>check for player before sending a message<commit_after>module Sim

  class Level
    include Celluloid
    include Celluloid::Logger

    trap_exit :actor_died
    finalizer :stop_subactors


    def self.attach
      level = new
      level.listen_to_parent_process
    end

    def build config_file
      config = Buildable.load_config(config_file)
      Sim::TimeUnit.new config[:time_unit]
      @queue = Sim::Queue.new_link
      create(config)
    end

    def listen_to_parent_process
      Celluloid.logger = ::Logger.new($stderr) # TODO log to a file
      @process = Popen::SubProcess.new
      @process.listen(self)
    end

    # process a message and returns an answer
    def process_message message
      if message.key? :player
        if player = find_player(message[:player])
          player.process_message message
        else
          raise ArgumentError, "no player[#{message[:player]} found in this level"
        end
      else
        case message[:action]
        when 'build'
          build message[:params][:config_file]
{'fraction_non_alphanumeric': 0.07237512742099898, 'fraction_numerical': 0.0, 'mean_word_length': 2.601834862385321, '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': '4285787', 'n_tokens_mistral': 564, 'n_tokens_neox': 548, 'n_words': 149}