<commit_before>require 'yaml'

module OodAppkit
  # An object that describes a given cluster of nodes used by an HPC center
  class Cluster
    # YAML configuration version
    VERSION = :v1

    # Title of the cluster
    # @return [String] title of cluster
    attr_reader :title

    # Hash of validators this cluster validates against
    # @return [Hash<#valid?>] hash of validators
    attr_reader :validators

    # Hash of servers this cluster supports
    # @return [Hash<Server>] hash of servers
    attr_reader :servers

    # A list of accessible clusters for the currently running user
    # @param file [String] yaml file with cluster configurations
    # @param force [Boolean] whether we force invalid clusters to be included as well
    # @return [Hash<Cluster>] list of clusters user has access to
    def self.all(file: File.expand_path('../../../config/clusters.yml', __FILE__), force: false)
      parse_config(file).each_with_object({}) do |(k, v), h|
        c = Cluster.new v
        h[k] = c if c.valid? || force
      end
    end

    # @param title [String] title of cluster
    # @param validators [Hash] hash of validations that describe the validators
    # @param servers [Hash] hash of servers with corresponding server info
    # @param hpc_cluster [Boolean] whether this is an hpc-style cluster
    def initialize(title:, validators: {}, servers: {}, hpc_cluster: true)
      # Set title of cluster
      @title = title

      # Generate hash of validations
      @validators = validators.each_with_object({}) do |(k, v), h|
        h[k] = v[:type].constantize.new(v)
      end

      # Generate hash of servers
      @servers = servers.each_with_object({}) do |(k, v), h|
        h[k] = v[:type].constantize.new(v)
      end

      # Is this an hpc-style cluster?
      @hpc_cluster = hpc_cluster
    end

    # Whether this is a valid cluster
    # @example Whether I have access to this cluster
    #   my_cluster.valid?
    #   #=> true
    # @return [Boolean] whether user has access to this cluster
    def valid?
      !@validators.any? {|name, validator| !validator.valid?}<commit_msg>add id to cluster object<commit_after>require 'yaml'

module OodAppkit
  # An object that describes a given cluster of nodes used by an HPC center
  class Cluster
    # YAML configuration version
    VERSION = :v1

    # Unique ID of the cluster
    # @return [Symbol] id of cluster
    attr_reader :id

    # Title of the cluster
    # @return [String] title of cluster
    attr_reader :title

    # Hash of validators this cluster validates against
    # @return [Hash<#valid?>] hash of validators
    attr_reader :validators

    # Hash of servers this cluster supports
    # @return [Hash<Server>] hash of servers
    attr_reader :servers

    # A list of accessible clusters for the currently running user
    # @param file [String] yaml file with cluster configurations
    # @param force [Boolean] whether we force invalid clusters to be included as well
    # @return [Hash<Cluster>] list of clusters user has access to
    def self.all(file: File.expand_path('../../../config/clusters.yml', __FILE__), force: false)
      parse_config(file).each_with_object({}) do |(k, v), h|
        c = Cluster.new v.merge(id: k)
        h[k] = c if c.valid? || force
      end
    end

    # @param id [Symbol] id of cluster
    # @param title [String] title of cluster
    # @param validators [Hash] hash of validations that describe the validators
    # @param servers [Hash] hash of servers with corresponding server info
    # @param hpc_cluster [Boolean] whether this is an hpc-style cluster
    def initialize(id:, title:, validators: {}, servers: {}, hpc_cluster: true)
      # Set id & title of cluster
      @id = id
      @title = title

      # Generate hash of validations
      @validators = validators.each_with_object({}) do |(k, v), h|
        h[k] = v[:type].constantize.new(v)
      end

      # Generate hash of servers
      @servers = servers.each_with_object({}) do |(k, v), h|
        h[k] = v[:type].constantize.new(v)
      end

      # Is this an hpc-style cluster?
      @hpc_cluster = hpc_cluster
    end

    # Whether this is a valid cluster
    # @example Whether I have access to this cluster
    #   my_cluster.valid?
    #   #=> true
    # @return [Boolean] whether user has access to this cluster
    def valid?
      !@validators.any? {|name, validator| !validator.valid?}
{'fraction_non_alphanumeric': 0.09726923944933423, 'fraction_numerical': 0.0004513653802753329, 'mean_word_length': 2.8707423580786027, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '7287848', 'n_tokens_mistral': 1313, 'n_tokens_neox': 1281, 'n_words': 498}