diff --git a/app/services/student_loader.rb b/app/services/student_loader.rb index 052623e6..5caec7ec 100644 --- a/app/services/student_loader.rb +++ b/app/services/student_loader.rb @@ -6,9 +6,7 @@ require 'csv' class StudentLoader - def self.load_data(filepath:, reinitialize: true) - destroy_students if reinitialize - + def self.load_data(filepath:) File.open(filepath) do |file| headers = file.first @@ -20,12 +18,6 @@ class StudentLoader end end - def self.destroy_students - SurveyItemResponse.update_all(student_id: nil) - StudentRace.delete_all - Student.delete_all - end - def self.process_row(row:) races = process_races(codes: race_codes(row:)) response_id = row['ResponseId'] || row['Responseid'] || row['ResponseID'] || diff --git a/lib/tasks/data.rake b/lib/tasks/data.rake index 61245ab5..e11bfffd 100644 --- a/lib/tasks/data.rake +++ b/lib/tasks/data.rake @@ -75,11 +75,14 @@ namespace :data do end desc 'load students' task load_students: :environment do + SurveyItemResponse.update_all(student_id: nil) + StudentRace.delete_all + Student.delete_all Dir.glob(Rails.root.join('data', 'survey_responses', '*student*.csv')).each do |file| puts "=====================> Loading student data from csv at path: #{file}" StudentLoader.load_data filepath: file end - puts "=====================> Completed loading #{Student.count} survey responses" + puts "=====================> Completed loading #{Student.count} students" end desc 'reset all cache counters'