<commit_before>module Cb
  module Responses

    class Timing
      attr_reader :response_sent, :elapsed

      def initialize(response, raise_on_parse_fail = true)
        @response = response
        @should_raise_on_parse_fail = raise_on_parse_fail
        post_initialize
      end

      private
      attr_reader :response, :should_raise_on_parse_fail

      def post_initialize
        raise_on_empty_timing_info
        @response_sent = parsed_response_sent
        @elapsed       = parsed_time_elapsed
      end

      def raise_on_empty_timing_info
        should_raise = (response.nil? || !response.respond_to?(:[])) && should_raise_on_parse_fail
        raise ExpectedResponseFieldMissing.new('Missing/malformed timing info!') if should_raise
      end

      def parsed_response_sent
        DateTime.parse(response['TimeResponseSent']) rescue nil
      end

      def parsed_time_elapsed
        elapsed_parsable? ? response[elapsed_node].to_f : nil
      end

      def elapsed_parsable?
        response.include?(elapsed_node) &&
        response[elapsed_node].respond_to?(:to_f) &&
        timing_parses_to_nonzero?
      end

      def timing_parses_to_nonzero?
        response[elapsed_node].to_f != 0.0
      end
      
      def elapsed_node
        'TimeElapsed'
      end
    end<commit_msg>clearer naming<commit_after>module Cb
  module Responses

    class Timing
      attr_reader :response_sent, :elapsed

      def initialize(response, raise_on_parse_fail = true)
        @response = response
        @should_raise_on_parse_fail = raise_on_parse_fail
        post_initialize
      end

      private
      attr_reader :response, :should_raise_on_parse_fail

      def post_initialize
        raise_on_empty_timing_info
        @response_sent = parsed_response_sent
        @elapsed       = parsed_time_elapsed
      end

      def raise_on_empty_timing_info
        should_raise = (response.nil? || !response.respond_to?(:[])) && should_raise_on_parse_fail
        raise ExpectedResponseFieldMissing.new('Missing/malformed timing info!') if should_raise
      end

      def parsed_response_sent
        DateTime.parse(response['TimeResponseSent']) rescue nil
      end

      def parsed_time_elapsed
        elapsed_node_parsable? ? response[elapsed_node].to_f : nil
      end

      def elapsed_node_parsable?
        response.include?(elapsed_node) &&
        response[elapsed_node].respond_to?(:to_f) &&
        timing_parses_to_nonzero?
      end

      def timing_parses_to_nonzero?
        response[elapsed_node].to_f != 0.0
      end
      
      def elapsed_node
        'TimeElapsed'
      end
    end
{'fraction_non_alphanumeric': 0.0636604774535809, 'fraction_numerical': 0.0015157256536566881, 'mean_word_length': 2.656509695290859, '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': '328108', 'n_tokens_mistral': 810, 'n_tokens_neox': 786, 'n_words': 144}