<commit_before>require 'open-uri'

namespace :import do
  desc 'Import bookings from booking bug CSV (CSV=url TIMEOUT=60)'
  task booking_bug: :environment do
    csv_url = ENV.fetch('CSV')
    timeout = ENV.fetch('TIMEOUT') { 60 }.to_i

    data = open(csv_url, read_timeout: timeout).read
    CsvImporter.new(data).call
  end
end<commit_msg>Quick and dirty script to fix current records<commit_after>require 'open-uri'
require 'csv'

namespace :import do
  desc 'Import bookings from booking bug CSV (CSV=url TIMEOUT=60)'
  task booking_bug: :environment do
    csv_url = ENV.fetch('CSV')
    timeout = ENV.fetch('TIMEOUT') { 60 }.to_i

    data = open(csv_url, read_timeout: timeout).read
    CsvImporter.new(data).call
  end

  desc 'Fix IDs for incorrectly imported records (CSV=url TIMEOUT=60)'
  task fix_ids: :environment do
    csv_url = ENV.fetch('CSV')
    timeout = ENV.fetch('TIMEOUT') { 60 }.to_i

    data = open(csv_url, read_timeout: timeout).read

    CSV.new(data).each do |row|
      member_id = row[0]
      reference = row[1]

      next unless Appointment.exists?(member_id)

      ActiveRecord::Base.transaction do
        Appointment.find(member_id).update_attribute(:id, reference)
        Activity.where(appointment_id: member_id).update_all(appointment_id: reference)
        Audited::Audit.where(auditable_id: member_id).update_all(auditable_id: reference)
      end

      putc '.'
    end
  end
end
{'fraction_non_alphanumeric': 0.1112666200139958, 'fraction_numerical': 0.00979706088173548, 'mean_word_length': 3.750830564784053, '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': '2446924', 'n_tokens_mistral': 496, 'n_tokens_neox': 475, 'n_words': 117}