<commit_before>require 'json'
require 'set'


module Algohub
  module IntermediateType
    BOOL = 'bool'.freeze
    CHAR = 'char'.freeze
    STRING = 'string'.freeze
    DOUBLE = 'double'.freeze
    INT = 'int'.freeze
    LONG = 'long'.freeze
    ARRAY = 'array'.freeze
    LIST = 'list'.freeze
    SET = 'set'.freeze
    MAP = 'map'.freeze
    LINKED_LIST_NODE = 'LinkedListNode'.freeze
    BINARY_TREE_NODE = 'BinaryTreeNode'.freeze
  end

  module StatusCode
    ACCEPTED = 4
    WRONG_ANSWER = 5
    RUNTIME_ERROR = 6
    TIME_LIMIT_EXCEEDED = 7
    MEMORY_LIMIT_EXCEEDED = 8
    OUTPUT_LIMIT_EXCEEDED = 9
    RESTRICTED_CALL = 10
  end


  class TypeNode
    attr_reader :value
    attr_reader :element_type
    attr_reader :key_type

    def initialize(value, element_type = nil, key_type = nil)
      @value = value
      @element_type = element_type
      @key_type = key_type
    end

    def self.to_json(type_node)
      json_str = '{"value":"' + type_node.value.to_s + '"'
      json_str += ',"element_type":' + TypeNode.to_json(type_node.element_type) unless type_node.element_type.nil?
      json_str += ',"key_type":' + TypeNode.to_json(type_node.key_type) unless type_node.key_type.nil?
      json_str + '}'
    end

    def self.from_json(json_str)
      obj = JSON.load(json_str)
      TypeNode.from_json_internal(obj)
    end

    def self.from_json_internal(obj)
      element_type = obj['element_type'].nil? ? nil : TypeNode.from_json_internal(obj['element_type'])
      key_type = obj['key_type'].nil? ? nil : TypeNode.from_json_internal(obj['key_type'])
      TypeNode.new(obj['value'], element_type, key_type)
    end

    def self.has_customized_type(type_node)
      cur = type_node
      until cur.nil?
        if cur.value == IntermediateType::LINKED_LIST_NODE ||
           cur.value == IntermediateType::BINARY_TREE_NODE ||
           cur.value == IntermediateType::SET ||
           cur.value == IntermediateType::MAP
          return true
        end
        cur = cur.element_type
      end
      cur = type_node
      until cur.nil?
        if cur.value == IntermediateType::LINKED_LIST_NODE ||
           cur.value == IntermediateType::BINARY_TREE_NODE ||
           cur.value == IntermediateType::SET ||
           cur.value == IntermediateType::MAP
          return true
        end
        cur = cur.key_type
      end
      false
    end
  end

  class JudgeResult
    def initialize(status_code, error_message=nil, input=nil,
                   output=nil, expected_output=nil, testcase_passed_count=0,
                   testcase_total_count=0, elapsed_time=0, consumed_memory=0)
      @status_code = status_code
      @error_message = error_message
      @input = input
      @output = output
      @expected_output = expected_output
      @testcase_passed_count = testcase_passed_count
      @testcase_total_count = testcase_total_count<commit_msg>Added attributes accessors for JudgeResult<commit_after>require 'json'
require 'set'


module Algohub
  module IntermediateType
    BOOL = 'bool'.freeze
    CHAR = 'char'.freeze
    STRING = 'string'.freeze
    DOUBLE = 'double'.freeze
    INT = 'int'.freeze
    LONG = 'long'.freeze
    ARRAY = 'array'.freeze
    LIST = 'list'.freeze
    SET = 'set'.freeze
    MAP = 'map'.freeze
    LINKED_LIST_NODE = 'LinkedListNode'.freeze
    BINARY_TREE_NODE = 'BinaryTreeNode'.freeze
  end

  module StatusCode
    ACCEPTED = 4
    WRONG_ANSWER = 5
    RUNTIME_ERROR = 6
    TIME_LIMIT_EXCEEDED = 7
    MEMORY_LIMIT_EXCEEDED = 8
    OUTPUT_LIMIT_EXCEEDED = 9
    RESTRICTED_CALL = 10
  end


  class TypeNode
    attr_reader :value
    attr_reader :element_type
    attr_reader :key_type

    def initialize(value, element_type = nil, key_type = nil)
      @value = value
      @element_type = element_type
      @key_type = key_type
    end

    def self.to_json(type_node)
      json_str = '{"value":"' + type_node.value.to_s + '"'
      json_str += ',"element_type":' + TypeNode.to_json(type_node.element_type) unless type_node.element_type.nil?
      json_str += ',"key_type":' + TypeNode.to_json(type_node.key_type) unless type_node.key_type.nil?
      json_str + '}'
    end

    def self.from_json(json_str)
      obj = JSON.load(json_str)
      TypeNode.from_json_internal(obj)
    end

    def self.from_json_internal(obj)
      element_type = obj['element_type'].nil? ? nil : TypeNode.from_json_internal(obj['element_type'])
      key_type = obj['key_type'].nil? ? nil : TypeNode.from_json_internal(obj['key_type'])
      TypeNode.new(obj['value'], element_type, key_type)
    end

    def self.has_customized_type(type_node)
      cur = type_node
      until cur.nil?
        if cur.value == IntermediateType::LINKED_LIST_NODE ||
           cur.value == IntermediateType::BINARY_TREE_NODE ||
           cur.value == IntermediateType::SET ||
           cur.value == IntermediateType::MAP
          return true
        end
        cur = cur.element_type
      end
      cur = type_node
      until cur.nil?
        if cur.value == IntermediateType::LINKED_LIST_NODE ||
           cur.value == IntermediateType::BINARY_TREE_NODE ||
           cur.value == IntermediateType::SET ||
           cur.value == IntermediateType::MAP
          return true
        end
        cur = cur.key_type
      end
      false
    end
  end

  class JudgeResult
    attr_accessor :status_code
    attr_accessor :error_message
    attr_accessor :input
    attr_accessor :output
    attr_accessor :expected_output
    attr_accessor :testcase_passed_count
    attr_accessor :testcase_total_count
    attr_accessor :elapsed_time
    attr_accessor :consumed_memory

    def initialize(status_code, error_message=nil, input=nil,
                   output=nil, expected_output=nil, testcase_passed_count=0,
                   testcase_total_count=0, elapsed_time=0, consumed_memory=0)
      @status_code = status_code
      @error_message = error_message
      @input = input
      @output = output
      @expected_output = expected_output
      @testcase_passed_count = testcase_passed_count
      @testcase_total_count = testcase_total_count
{'fraction_non_alphanumeric': 0.09378068739770867, 'fraction_numerical': 0.003927986906710311, 'mean_word_length': 2.8098503740648377, 'pattern_counts': {'":': 6, '<': 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': '5062964', 'n_tokens_mistral': 2037, 'n_tokens_neox': 1972, 'n_words': 375}