<commit_before>namespace :db do
  namespace :seed do
    def load_all(path)
      data = fixture_data(path)
      pbar = ProgressBar.create title: path, total: data.size

      data.each do |resource|
        EnvelopeBuilder.new(
          params(resource, path),
          update_if_exists: true
        ).build
        pbar.increment
      end
      pbar.finish
    end

    def fixture_data(path)
      dir = File.expand_path('../../../db/seeds/', __FILE__)
      content = File.read File.join(dir, path)
      JSON.parse content
    end

    def params(resource, path)
      envlp_type = path.include?('paradata') ? 'paradata' : 'resource_data'
      {
        envelope_type: envlp_type,
        envelope_version: '1.0.0',
        envelope_community: path.split('/').first,
        resource: JWT.encode(resource, private_key, 'RS256'),
        resource_format: 'json',
        resource_encoding: 'jwt',
        resource_public_key: public_key
      }
    end

    def private_key
      OpenSSL::PKey::RSA.new get_fixture_key(:private)
    end

    def public_key
      get_fixture_key(:public)
    end

    def get_fixture_key(type)
      dir = File.expand_path('../../../spec/support/fixtures/', __FILE__)
      File.read File.join(dir, "#{type}_key.txt")
    end

    def load_ce_registry
      load_all 'ce_registry/organizations.json'
      load_all 'ce_registry/credentials.json'
      load_all 'ce_registry/competencies.json'
      load_all 'ce_registry/competency_frameworks.json'
    end

    def load_learning_registry
      load_all 'learning_registry/resources.json'
      load_all 'learning_registry/paradata.json'
    end

    desc 'Load samples data'
    task samples: [:environment] do
      load_ce_registry
      load_learning_registry
    end

    desc 'Load ce/registry samples data'
    task cer_samples: [:environment] do
      load_ce_registry
    end
  end
end<commit_msg>Add task for loading only competencies samples<commit_after>namespace :db do
  namespace :seed do
    def load_all(path)
      data = fixture_data(path)
      pbar = ProgressBar.create title: path, total: data.size

      data.each do |resource|
        EnvelopeBuilder.new(
          params(resource, path),
          update_if_exists: true
        ).build
        pbar.increment
      end
      pbar.finish
    end

    def fixture_data(path)
      dir = File.expand_path('../../../db/seeds/', __FILE__)
      content = File.read File.join(dir, path)
      JSON.parse content
    end

    def params(resource, path)
      envlp_type = path.include?('paradata') ? 'paradata' : 'resource_data'
      {
        envelope_type: envlp_type,
        envelope_version: '1.0.0',
        envelope_community: path.split('/').first,
        resource: JWT.encode(resource, private_key, 'RS256'),
        resource_format: 'json',
        resource_encoding: 'jwt',
        resource_public_key: public_key
      }
    end

    def private_key
      OpenSSL::PKey::RSA.new get_fixture_key(:private)
    end

    def public_key
      get_fixture_key(:public)
    end

    def get_fixture_key(type)
      dir = File.expand_path('../../../spec/support/fixtures/', __FILE__)
      File.read File.join(dir, "#{type}_key.txt")
    end

    def load_ce_registry
      load_all 'ce_registry/organizations.json'
      load_all 'ce_registry/credentials.json'
    end

    def load_cer_competencies
      load_all 'ce_registry/competencies.json'
      load_all 'ce_registry/competency_frameworks.json'
    end

    def load_learning_registry
      load_all 'learning_registry/resources.json'
      load_all 'learning_registry/paradata.json'
    end

    desc 'Load samples data'
    task samples: [:environment] do
      load_ce_registry
      load_cer_competencies
      load_learning_registry
    end

    desc 'Load ce/registry samples data'
    task cer_samples: [:environment] do
      load_ce_registry
      load_cer_competencies
    end

    desc 'Load ce/registry competencies sample data'
    task cer_competencies: [:environment] do
      load_cer_competencies
    end
  end
end
{'fraction_non_alphanumeric': 0.09529672494459493, 'fraction_numerical': 0.002954937207584339, 'mean_word_length': 2.5538057742782154, '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': '5244297', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1265, 'n_words': 272}