mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 21:48:16 -08:00
Do not erase all students when loading each file
This commit is contained in:
parent
3f493727b3
commit
3fcab58557
2 changed files with 5 additions and 10 deletions
|
|
@ -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'] ||
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue