<commit_before>require File.expand_path("../../config/boot.rb", __FILE__)
require File.expand_path("../../app/helpers/states.rb", __FILE__)
require File.expand_path("../../app/helpers/colorize.rb", __FILE__)

namespace :'congress-forms' do
  namespace :'delayed_job' do
    desc "perform all fills on the Delayed::Job error_or_failure queue, captchad fills first, optionally provide bioguide regex"
    task :perform_fills, :regex, :overrides do |t, args|
      regex = args[:regex].blank? ? nil : Regexp.compile(args[:regex])
      overrides = args[:overrides].blank? ? {} : eval(args[:overrides])

      jobs = Delayed::Job.where(queue: "error_or_failure")
      captcha_jobs = []
      noncaptcha_jobs = []

      master_hash = {}
      cm_hash = {}

      jobs.each do |job|
        cm_id, = congress_member_id_and_args_from_handler(job.handler)
        cm = retrieve_congress_member_cached(cm_hash, cm_id)
        if regex.nil? or regex.match(cm.bioguide_id)
          if set_or_retrieve_val(master_hash, cm, "has_captcha?")
            captcha_jobs.push job
          else
            noncaptcha_jobs.push job
          end
        end
      end
      captcha_jobs.each do |job|
	begin
          cm_id, cm_args = congress_member_id_and_args_from_handler(job.handler)
          cm = retrieve_congress_member_cached(cm_hash, cm_id)
          puts red("Job #" + job.id.to_s + ", bioguide " + cm.bioguide_id)
	  result = cm.fill_out_form cm_args[0].merge(overrides) do |img|
	    puts img
	    STDIN.gets.strip
	  end
	rescue
	end
	job.destroy
      end
      noncaptcha_jobs.each do |job|
	begin
          cm_id, cm_args = congress_member_id_and_args_from_handler(job.handler)
          cm = retrieve_congress_member_cached(cm_hash, cm_id)
          puts red("Job #" + job.id.to_s + ", bioguide " + handler.object.bioguide_id)
	  result = handler.object.fill_out_form cm_args[0].merge(overrides)
	rescue
	end
	job.destroy
      end
    end
    desc "calculate # of jobs per congressperson on the Delayed::Job error_or_failure queue"
    task :jobs_per_congressperson do |t, args|
      jobs = Delayed::Job.where(queue: "error_or_failure")<commit_msg>Replacing tab indent with spaces<commit_after>require File.expand_path("../../config/boot.rb", __FILE__)
require File.expand_path("../../app/helpers/states.rb", __FILE__)
require File.expand_path("../../app/helpers/colorize.rb", __FILE__)

namespace :'congress-forms' do
  namespace :'delayed_job' do
    desc "perform all fills on the Delayed::Job error_or_failure queue, captchad fills first, optionally provide bioguide regex"
    task :perform_fills, :regex, :overrides do |t, args|
      regex = args[:regex].blank? ? nil : Regexp.compile(args[:regex])
      overrides = args[:overrides].blank? ? {} : eval(args[:overrides])

      jobs = Delayed::Job.where(queue: "error_or_failure")
      captcha_jobs = []
      noncaptcha_jobs = []

      master_hash = {}
      cm_hash = {}

      jobs.each do |job|
        cm_id, = congress_member_id_and_args_from_handler(job.handler)
        cm = retrieve_congress_member_cached(cm_hash, cm_id)
        if regex.nil? or regex.match(cm.bioguide_id)
          if set_or_retrieve_val(master_hash, cm, "has_captcha?")
            captcha_jobs.push job
          else
            noncaptcha_jobs.push job
          end
        end
      end
      captcha_jobs.each do |job|
        begin
          cm_id, cm_args = congress_member_id_and_args_from_handler(job.handler)
          cm = retrieve_congress_member_cached(cm_hash, cm_id)
          puts red("Job #" + job.id.to_s + ", bioguide " + cm.bioguide_id)
          result = cm.fill_out_form cm_args[0].merge(overrides) do |img|
            puts img
            STDIN.gets.strip
          end
        rescue
        end
        job.destroy
      end
      noncaptcha_jobs.each do |job|
        begin
          cm_id, cm_args = congress_member_id_and_args_from_handler(job.handler)
          cm = retrieve_congress_member_cached(cm_hash, cm_id)
          puts red("Job #" + job.id.to_s + ", bioguide " + handler.object.bioguide_id)
          result = handler.object.fill_out_form cm_args[0].merge(overrides)
        rescue
        end
        job.destroy
      end
    end
    desc "calculate # of jobs per congressperson on the Delayed::Job error_or_failure queue"
    task :jobs_per_congressperson do |t, args|
      jobs = Delayed::Job.where(queue: "error_or_failure")
{'fraction_non_alphanumeric': 0.10733695652173914, 'fraction_numerical': 0.0009057971014492754, 'mean_word_length': 2.834201388888889, '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': '5799922', 'n_tokens_mistral': 1510, 'n_tokens_neox': 1477, 'n_words': 295}