<commit_before>active_pols = Policy.where(Policy.active_as_of_expression(Date.new(2014, 12, 31)).merge({"employer_id" => nil}))

active_pols.map do |pol|
  subscriber_person = pol.subscriber.person.id
  ags = ApplicationGroup.where(
    :people_ids => { "$in" => [subscriber_person] }
  )
  if ags.count == 1
    pol.application_group = ags.first
    pol.save!
  end
end<commit_msg>Working on error counting.<commit_after>Policy.collection.where.update_all({"$set" => {"application_group_id" => nil}})
active_pols = Policy.where(Policy.active_as_of_expression(Date.new(2014, 12, 31)).merge({"employer_id" => nil}))

no_match = 0
too_many_matched = 0
active_pols.map do |pol|
  subscriber_person = pol.subscriber.person.id
  ags = ApplicationGroup.where(
    :person_ids => { "$in" => [subscriber_person] }
  )
  case ags.count
  when 1
    pol.application_group = ags.first
    pol.save!
  when 0
    no_match = no_match + 1
  else
    too_many_matched = too_many_matched + 1
  end
end

puts "No match: #{no_match}"
puts "Too many matched: #{too_many_matched}"
{'fraction_non_alphanumeric': 0.13679245283018868, 'fraction_numerical': 0.02169811320754717, 'mean_word_length': 4.469072164948454, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4998806', 'n_tokens_mistral': 409, 'n_tokens_neox': 382, 'n_words': 74}