Skip to content

Commit

Permalink
CPDNPQ-1216 Update list of independent schools offering govt.-funded …
Browse files Browse the repository at this point in the history
…EY provision
  • Loading branch information
javier-npq committed Jul 30, 2023
1 parent 1eda61a commit fcbd434
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions lib/tasks/update_eyl_funding_eligible_schools_list.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require "csv"

namespace :update_eyl_funding_eligible_schools_list do
desc "Make schools funding eligible for NPQEYL courses"
task :update, %i[file_name] => :environment do |_t, args|
file_name = args.file_name
previous_file = "lib/eyl_funding_eligible_schools/2022-11-30/eligible-schools.csv"

raise "File not found: #{file_name}" unless File.exist?(file_name)
raise "File not found: #{previous_file}" unless File.exist?(previous_file)

Rails.logger.info("Fetching previous schools from CSV file: #{previous_file}")

previous_school_urns = CSV.parse(File.read(previous_file), headers: true).map { |row| row["gias_urn"] }

Rails.logger.info("Fetched Records: #{previous_school_urns.count}")

Rails.logger.info("Updating schools from CSV file: #{file_name}")

updated_current_records = []

CSV.foreach(file_name, headers: true) do |row|
gias_urn = row["gias_urn"]
school = School.find_by(urn: gias_urn)

if school.nil?
# need to put logic to create new school
else
school&.update!(eyl_funding_eligible: true, establishment_status_code: 1, establishment_status_name: "Open")
updated_current_records << school.urn
end
end

Rails.logger.info("Update finished")

Rails.logger.info("Updated Records: #{updated_current_records.count}")

closed_school_urns = previous_school_urns - updated_current_records

School.transaction do
School.where(urn: closed_school_urns).update_all(establishment_status_code: 2, establishment_status_name: "Closed")
end
end
end

0 comments on commit fcbd434

Please sign in to comment.