mirror of
https://github.com/edcommonwealth/Dashboard.git
synced 2026-03-07 21:38:14 -08:00
chore: fixed seeder.
This commit is contained in:
parent
0af7d42e52
commit
1b0af124f7
4 changed files with 17 additions and 33 deletions
|
|
@ -5,15 +5,12 @@ require "csv"
|
|||
module Dashboard
|
||||
class EnrollmentLoader
|
||||
def load_data(filepath:)
|
||||
schools = []
|
||||
enrollments = []
|
||||
CSV.parse(File.read(filepath), headers: true) do |row|
|
||||
row = EnrollmentRowValues.new(row:, schools: school_hash, academic_years: academic_year_hash)
|
||||
|
||||
next unless row.school.present? && row.academic_year.present?
|
||||
|
||||
schools << row.school
|
||||
|
||||
enrollments << create_enrollment_entry(row:)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -13,11 +13,11 @@ module Dashboard
|
|||
|
||||
schools << row.school
|
||||
|
||||
respondents << create_staffing_entry(row:)
|
||||
respondents << { dashboard_school_id: row.school.id, dashboard_academic_year_id: row.academic_year.id,
|
||||
total_teachers: row.fte_count }
|
||||
end
|
||||
|
||||
Respondent.import respondents, batch_size: 1000, on_duplicate_key_update: [:total_teachers]
|
||||
Respondent.where.not(school: schools).destroy_all
|
||||
Respondent.upsert_all(respondents, unique_by: %i[dashboard_school_id dashboard_academic_year_id])
|
||||
end
|
||||
|
||||
def self.clone_previous_year_data
|
||||
|
|
@ -27,23 +27,12 @@ module Dashboard
|
|||
respondents = []
|
||||
School.all.each do |school|
|
||||
Respondent.where(school:, academic_year: previous_year).each do |respondent|
|
||||
current_respondent = Respondent.find_or_initialize_by(school:, academic_year: current_year)
|
||||
current_respondent.total_teachers = respondent.total_teachers
|
||||
respondents << current_respondent
|
||||
respondents << { dashboard_school_id: respondent.school.id, dashboard_academic_year_id: current_year.id,
|
||||
total_teachers: respondent.total_teachers }
|
||||
end
|
||||
end
|
||||
Respondent.import respondents, batch_size: 1000, on_duplicate_key_update: [:total_teachers]
|
||||
Respondent.upsert_all(respondents, unique_by: %i[dashboard_school_id dashboard_academic_year_id])
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.create_staffing_entry(row:)
|
||||
respondent = Respondent.find_or_initialize_by(school: row.school, academic_year: row.academic_year)
|
||||
respondent.total_teachers = row.fte_count
|
||||
respondent
|
||||
end
|
||||
|
||||
private_class_method :create_staffing_entry
|
||||
end
|
||||
|
||||
class StaffingRowValues
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue