lib/tasks/fix_maine_nil_counties.rake
def update_county
      puts("Beginning update counties")
      file_name = "#{Rails.root}/update_county.csv"
      CSV.open(file_name, 'w+', headers: true) do |csv|
        csv << ["person_hbx_id", "zip", "status"]
        output = people.no_timeout.each do |person|
          puts "Examining Person: #{person.hbx_id} #{person.full_name} - consumer: #{person.consumer_role.blank?.inspect}"
          counters = {}
          counters[:person] = { fixed: 0, no_county_found: 0, multiple_counties_found: 0, no_fix_needed: 0 }
          person.addresses.each do |address|
            if address_needs_fixing?(address)
              result = address_fixer(address)
              counters[:person][result] += 1
            else
              counters[:person][:no_fix_needed] += 1
            end
          end

          counters[:faa_apps] = { fixed: 0, no_county_found: 0, multiple_counties_found: 0, no_fix_needed: 0 }
          if person.primary_family.present?
            applications = FinancialAssistance::Application.where(family_id: person.primary_family.id, aasm_state: "draft")
            applications.each do |application|
              application.applicants.each do |applicant|
                applicant.addresses.each do |address|
                  if address_needs_fixing?(address)
                    result = address_fixer(address)
                    counters[:faa_apps][result] += 1
                  else
                    counters[:faa_apps][:no_fix_needed] += 1
                  end
                end
              end
              application.save if application.changed?
            end
          end

          person.save if person.changed?
          csv_comment = counters.to_s.gsub!(",", "")
          csv << [person.hbx_id, person.addresses.first.zip, csv_comment]
          #rescue StandardError => e
          #  csv << [person.hbx_id, person_address&.zip, "StandardError: #{e}"]
          #end
        end
      end
    end
#2 update people with nil county
2 update people with nil county
2 update people with nil county
def update_county
      puts("Beginning update counties")
      file_name = "#{Rails.root}/update_county.csv"
      CSV.open(file_name, 'w+', headers: true) do |csv|
        csv << ["person_hbx_id", "zip", "status"]
        output = people.no_timeout.each do |person|
          puts "Examining Person: #{person.hbx_id} #{person.full_name} - consumer: #{person.consumer_role.blank?.inspect}"
          counters = {}
          counters[:person] = { fixed: 0, no_county_found: 0, multiple_counties_found: 0, no_fix_needed: 0 }
          person.addresses.each do |address|
            if address_needs_fixing?(address)
              result = address_fixer(address)
              counters[:person][result] += 1
            else
              counters[:person][:no_fix_needed] += 1
            end
          end
          counters[:faa_apps] = { fixed: 0, no_county_found: 0, multiple_counties_found: 0, no_fix_needed: 0 }
          if person.primary_family.present?
            applications = FinancialAssistance::Application.where(family_id: person.primary_family.id, aasm_state: "draft")
            applications.each do |application|
              application.applicants.each do |applicant|
                applicant.addresses.each do |address|
                  if address_needs_fixing?(address)
                    result = address_fixer(address)
                    counters[:faa_apps][result] += 1
                  else
                    counters[:faa_apps][:no_fix_needed] += 1
                  end
                end
              end
              application.save if application.changed?
            end
          end
          person.save if person.changed?
          csv_comment = counters.to_s.gsub!(",", "")
          csv << [person.hbx_id, person.addresses.first.zip, csv_comment]
        end
      end
    end
def update_county puts ( "Beginning update counties" ) file_name = "#{Rails.root}/update_county.csv" CSV . open ( file_name , 'w+' , headers : true ) do | csv | csv << [ "person_hbx_id" , "zip" , "status" ] output = people . no_timeout . each do | person | puts "Examining Person: #{person.hbx_id} #{person.full_name} - consumer: #{person.consumer_role.blank?.inspect}" counters = { } counters [ :person ] = { fixed : 0 , no_county_found : 0 , multiple_counties_found : 0 , no_fix_needed : 0 } person . addresses . each do | address | if address_needs_fixing? ( address ) result = address_fixer ( address ) counters [ :person ] [ result ] += 1 else counters [ :person ] [ :no_fix_needed ] += 1 end end counters [ :faa_apps ] = { fixed : 0 , no_county_found : 0 , multiple_counties_found : 0 , no_fix_needed : 0 } if person . primary_family . present? applications = FinancialAssistance :: Application . where ( family_id : person . primary_family . id , aasm_state : "draft" ) applications . each do | application | application . applicants . each do | applicant | applicant . addresses . each do | address | if address_needs_fixing? ( address ) result = address_fixer ( address ) counters [ :faa_apps ] [ result ] += 1 else counters [ :faa_apps ] [ :no_fix_needed ] += 1 end end end application . save if application . changed? end end person . save if person . changed? csv_comment = counters . to_s . gsub! ( "," , "" ) csv << [ person . hbx_id , person . addresses . first . zip , csv_comment ] end end end
2 update people with nil county
2 update people with nil county
#rescue StandardError => e #  csv << [person.hbx_id, person_address&.zip, "StandardError: #{e}"] #end