<commit_before>puts 'Generating longitudinal address data'

puts "  * Processing human events"
i = 0
HumanEvent.find_in_batches(:include => [ :interested_party => { :person_entity => :addresses } ], :conditions => "participations.id IS NOT NULL", :batch_size => 500 ) do |event_group|
  i += 1
  puts "    * Processing #{i.ordinalize} group of 500 human events"
  event_group.each do | event |
    unless event.try(:address)
      address = event.interested_party.person_entity.addresses.first
      if address
        address = address.clone if address.event
        address.event_id =  event.id
        address.save!
      end
    end
  end
end

i = 0
PlaceEvent.find_in_batches(:include => [ :interested_place => { :place_entity => :addresses } ], :conditions => "participations.id IS NOT NULL", :batch_size => 500 ) do |event_group|
  i += 1
  puts "    * Processing #{i.ordinalize} group of 500 place events"<commit_msg>Fixes address migration that was leaving contact addresses behind.<commit_after>puts 'Generating longitudinal address data'

puts "  * Processing human events"
i = 0
MorbidityEvent.find_in_batches(:include => [ :interested_party => { :person_entity => :addresses } ], :conditions => "participations.id IS NOT NULL", :batch_size => 500 ) do |event_group|
  i += 1
  puts "    * Processing #{i.ordinalize} group of 500 human events"
  event_group.each do | event |
    unless event.try(:address)
      address = event.interested_party.person_entity.addresses.first
      if address
        address = address.clone if address.event
        address.event_id =  event.id
        address.save!
      end
    end
  end
end

ContactEvent.find_in_batches(:include => [ :interested_party => { :person_entity => :addresses } ], :conditions => "participations.id IS NOT NULL", :batch_size => 500 ) do |event_group|
  i += 1
  puts "    * Processing #{i.ordinalize} group of 500 human events"
  event_group.each do | event |
    unless event.try(:address)
      address = event.interested_party.person_entity.addresses.first
      if address
        address = address.clone if address.event
        address.event_id =  event.id
        address.save!
      end
    end
  end
end


i = 0
PlaceEvent.find_in_batches(:include => [ :interested_place => { :place_entity => :addresses } ], :conditions => "participations.id IS NOT NULL", :batch_size => 500 ) do |event_group|
  i += 1
  puts "    * Processing #{i.ordinalize} group of 500 place events"
{'fraction_non_alphanumeric': 0.11233211233211234, 'fraction_numerical': 0.015873015873015872, 'mean_word_length': 3.4448462929475587, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 28, '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': '3099039', 'n_tokens_mistral': 797, 'n_tokens_neox': 736, 'n_words': 208}