<commit_before>namespace :fromthepage do
  desc "update last_editor_user_id for pages in collections [first_id,last_id]"
  task :update_last_editor, [:first_id,:last_id] => :environment do |t,args|
    Collection.where('id between ? and ?', args[:first_id].to_i, args[:last_id].to_i).each do |collection|
      print "#{collection.slug}\n"
      collection.pages.all.each do |page|
        unless page.last_editor_user_id
          version = page.current_version
          if version
            user = version.user
            if user
              page.update_column(:last_editor_user_id, user.id)
            end
          end
        end
      end
    end
  end #end task
end #end namespace<commit_msg>Calculate approval delta in migration<commit_after>namespace :fromthepage do
  desc "update last_editor_user_id for pages in collections [first_id,last_id]"
  task :update_last_editor, [:first_id,:last_id] => :environment do |t,args|
    Collection.where('id between ? and ?', args[:first_id].to_i, args[:last_id].to_i).each do |collection|
      print "#{collection.slug}\n"
      collection.pages.all.each do |page|
        unless page.last_editor_user_id
          version = page.current_version
          if version
            user = version.user
            if user
              page.update_column(:last_editor_user_id, user.id)
            end
          end
        end

        unless page.approval_delta 
          if Page::COMPLETED_STATUSES.include? (page.status)
            most_recent_not_approver_version = page.page_versions.where(user_id: page.last_editor_user_id).first
            if most_recent_not_approver_version
              old_transcription = most_recent_not_approver_version.transcription
            else
              old_transcription = ''
            end
            new_transcription = page.source_text

            unless old_transcription.blank?
              approval_delta = 
                Text::Levenshtein.distance(old_transcription, new_transcription).to_f / (old_transcription.size + new_transcription.size).to_f
              page.update_column(:approval_delta, approval_delta)
            end
          end
        end
      end
    end
  end #end task
end #end namespace
{'fraction_non_alphanumeric': 0.08052181736392262, 'fraction_numerical': 0.0, 'mean_word_length': 2.4162826420890937, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2955857', 'n_tokens_mistral': 651, 'n_tokens_neox': 640, 'n_words': 136}