<commit_before>desc 'Covert in_business to a string'
task in_business_data_migration: :environment do
  Organization.where(in_business: 'false').update_all(in_business: Organization::CLOSED)
  Organization.where(in_business: 'true').update_all(in_business: Organization::UNKNOWN)

  source = Source.find_by name: 'HumanOutsourcer'

  PaperTrail.track_changes_with('data migration') do
    for raw_input in source.imports.flat_map(&:raw_inputs)
      next unless raw_input.output_type == 'Organization'
      organization = Organization.find_by id: raw_input.output_id
      organization.update_attributes in_business: Organization::OPEN
    end
  end<commit_msg>Improve task to migration in_business<commit_after>desc 'Convert in_business to a string'
task in_business_data_migration: :environment do
  PaperTrail.track_changes_with('data migration') do
    Organization.where(in_business: 'false').update_all(in_business: Organization::CLOSED)
    Organization.where(in_business: 'true').update_all(in_business: Organization::UNKNOWN)

    source = Source.find_by name: 'HumanOutsourcer'
    raw_inputs = source.imports.flat_map(&:raw_inputs)

    in_business_raw_inputs = raw_inputs.select do |raw_input|
      raw_input.output_id && !raw_input.data['in_business'].nil?
    end

    organization_ids = in_business_raw_inputs.map(&:output_id)
    Organization.where.not(in_business: Organization::CLOSED).where(id: organization_ids).update_all(in_business: Organization::OPEN)
  end
{'fraction_non_alphanumeric': 0.09844908968307485, 'fraction_numerical': 0.0, 'mean_word_length': 6.346534653465347, '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': '670866', 'n_tokens_mistral': 455, 'n_tokens_neox': 455, 'n_words': 82}