<commit_before>module Radar
  module App
    class AnalyzerController
      attr_reader :sessions

      def initialize
        @sessions = {}
      end

      def analyzers
        @@analyzers.values.map { |analyzer_class| analyzer_class.new.config }
      end

      def self.register_analyzer(analyzer_id, analyzer_class)
        (@@analyzers ||= {})[analyzer_id] = analyzer_class
      end

      def on_each_day(session_id, portfolio)
        @sessions[session_id].on_each_day(portfolio)
      end

      def on_each_month(session_id, portfolio)
        @sessions[session_id].on_each_month(portfolio)
      end

      def on_finish(session_id, portfolio)
        @sessions[session_id].on_finish(portfolio)
      end

      def create_session(session_id, analyzer_id)
        analyzer = @@analyzers[analyzer_id].new
        @sessions[session_id] = analyzer
        analyzer.config
      end

      def dump(session_id)
        @sessions[session_id].dump
      end

      def resume(session_id, data)
        @sessions[session_id].resume(data)
      end

      def result(session_id)
        handle_error do
          @sessions[session_id].result
        end
      end

      def destroy_session(session_id)
        @sessions.delete(session_id)
      end

      protected

      def handle_error
        begin
          yield
        rescue => e
          puts "#{e.class}: #{e.message}"
          puts e.backtrace
        end
      end
    end
  end
end<commit_msg>handle_error<commit_after>module Radar
  module App
    class AnalyzerController
      attr_reader :sessions

      def initialize
        @sessions = {}
      end

      def analyzers
        handle_error do
          @@analyzers.values.map { |analyzer_class| analyzer_class.new.config }
        end
      end

      def self.register_analyzer(analyzer_id, analyzer_class)
        (@@analyzers ||= {})[analyzer_id] = analyzer_class
      end

      def on_each_day(session_id, portfolio)
        handle_error do
          @sessions[session_id].on_each_day(portfolio)
        end
      end

      def on_each_month(session_id, portfolio)
        handle_error do
          @sessions[session_id].on_each_month(portfolio)
        end
      end

      def on_finish(session_id, portfolio)
        handle_error do
          @sessions[session_id].on_finish(portfolio)
        end
      end

      def create_session(session_id, analyzer_id)
        handle_error do
          analyzer = @@analyzers[analyzer_id].new
          @sessions[session_id] = analyzer
          analyzer.config
        end
      end

      def dump(session_id)
        handle_error do
          @sessions[session_id].dump
        end
      end

      def resume(session_id, data)
        handle_error do
          @sessions[session_id].resume(data)
        end
      end

      def result(session_id)
        handle_error do
          @sessions[session_id].result
        end
      end

      def destroy_session(session_id)
        handle_error do
          @sessions.delete(session_id)
        end
      end

      protected

      def handle_error
        begin
          yield
        rescue => e
          puts "#{e.class}: #{e.message}"
          puts e.backtrace
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.07149460708782743, 'fraction_numerical': 0.0, 'mean_word_length': 1.926961226330027, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3189694', 'n_tokens_mistral': 1001, 'n_tokens_neox': 968, 'n_words': 195}