feat: add 2023-24 academic year and make sure previous year enrollment

and staffing data get loaded when missing
mciea-main
Nelson Jovel 2 years ago
parent c6960c957d
commit e1fc5dbbaa

@ -19,17 +19,17 @@ class Seeder
dese_ids = []
schools = []
CSV.parse(File.read(csv_file), headers: true) do |row|
district_name = row['District'].strip
district_name = row["District"].strip
next if rules.any? do |rule|
rule.new(row:).skip_row?
end
district_code = row['District Code'].try(:strip)
dese_id = row['DESE School ID'].strip
district_code = row["District Code"].try(:strip)
dese_id = row["DESE School ID"].strip
dese_ids << dese_id
school_name = row['School Name'].strip
school_code = row['School Code'].try(:strip)
hs = row['HS?']
school_name = row["School Name"].strip
school_code = row["School Code"].try(:strip)
hs = row["HS?"]
district = District.find_or_create_by! name: district_name
district.slug = district_name.parameterize
@ -52,60 +52,60 @@ class Seeder
def seed_sqm_framework(csv_file)
admin_data_item_ids = []
CSV.parse(File.read(csv_file), headers: true) do |row|
category_id = row['Category ID'].strip
category_id = row["Category ID"].strip
category = Category.find_or_create_by!(category_id:)
category_slugs = {
'1' => 'teachers-and-leadership',
'2' => 'school-culture',
'3' => 'resources',
'4' => 'academic-learning',
'5' => 'community-and-wellbeing'
"1" => "teachers-and-leadership",
"2" => "school-culture",
"3" => "resources",
"4" => "academic-learning",
"5" => "community-and-wellbeing"
}
category.update! name: row['Category'].strip, description: row['Category Description'].strip,
short_description: row['Category Short Description'], slug: category_slugs[category_id], sort_index: category_slugs.keys.index(category_id)
category.update! name: row["Category"].strip, description: row["Category Description"].strip,
short_description: row["Category Short Description"], slug: category_slugs[category_id], sort_index: category_slugs.keys.index(category_id)
subcategory_id = row['Subcategory ID'].strip
subcategory_id = row["Subcategory ID"].strip
subcategory = Subcategory.find_or_create_by!(subcategory_id:, category:)
subcategory.update! name: row['Subcategory'].strip, description: row['Subcategory Description'].strip
subcategory.update! name: row["Subcategory"].strip, description: row["Subcategory Description"].strip
measure_id = row['Measure ID'].strip
measure_name = row['Measures'].try(:strip)
watch_low = row['Item Watch Low'].try(:strip)
growth_low = row['Item Growth Low'].try(:strip)
approval_low = row['Item Approval Low'].try(:strip)
ideal_low = row['Item Ideal Low'].try(:strip)
on_short_form = row['On Short Form?'].try(:strip)
measure_description = row['Measure Description'].try(:strip)
measure_id = row["Measure ID"].strip
measure_name = row["Measures"].try(:strip)
watch_low = row["Item Watch Low"].try(:strip)
growth_low = row["Item Growth Low"].try(:strip)
approval_low = row["Item Approval Low"].try(:strip)
ideal_low = row["Item Ideal Low"].try(:strip)
on_short_form = row["On Short Form?"].try(:strip)
measure_description = row["Measure Description"].try(:strip)
next if row['Source'] == 'No source'
next if row["Source"] == "No source"
measure = Measure.find_or_create_by!(measure_id:, subcategory:)
measure.name = measure_name
measure.description = measure_description
measure.save!
data_item_id = row['Survey Item ID'].strip
scale_id = data_item_id.split('-')[0..1].join('-')
data_item_id = row["Survey Item ID"].strip
scale_id = data_item_id.split("-")[0..1].join("-")
scale = Scale.find_or_create_by!(scale_id:, measure:)
if %w[Teachers Students].include? row['Source']
if %w[Teachers Students].include? row["Source"]
survey_item = SurveyItem.where(survey_item_id: data_item_id, scale:).first_or_create
survey_item.watch_low_benchmark = watch_low if watch_low
survey_item.growth_low_benchmark = growth_low if growth_low
survey_item.approval_low_benchmark = approval_low if approval_low
survey_item.ideal_low_benchmark = ideal_low if ideal_low
survey_item.on_short_form = marked? on_short_form
survey_item.update! prompt: row['Question/item (22-23)'].strip
survey_item.update! prompt: row["Question/item (22-23)"].strip
end
if row['Source'] == 'Admin Data' && row['Active admin & survey items'] == 'TRUE'
if row["Source"] == "Admin Data" && row["Active admin & survey items"] == "TRUE"
admin_data_item = AdminDataItem.where(admin_data_item_id: data_item_id, scale:).first_or_create
admin_data_item.watch_low_benchmark = watch_low if watch_low
admin_data_item.growth_low_benchmark = growth_low if growth_low
admin_data_item.approval_low_benchmark = approval_low if approval_low
admin_data_item.ideal_low_benchmark = ideal_low if ideal_low
admin_data_item.description = row['Question/item (22-23)'].strip
admin_data_item.hs_only_item = marked? row['HS only admin item?']
admin_data_item.description = row["Question/item (22-23)"].strip
admin_data_item.hs_only_item = marked? row["HS only admin item?"]
admin_data_item.save!
admin_data_item_ids << admin_data_item.id
end
@ -121,23 +121,29 @@ class Seeder
def seed_enrollment(csv_file)
EnrollmentLoader.load_data(filepath: csv_file)
missing_enrollment_for_current_year = Respondent.where(academic_year: AcademicYear.order(:range).last).none? do |respondent|
respondent&.total_students&.zero?
end
EnrollmentLoader.clone_previous_year_data if missing_enrollment_for_current_year
end
def seed_staffing(csv_file)
StaffingLoader.load_data(filepath: csv_file)
missing_staffing_for_current_year = Respondent.where(academic_year: AcademicYear.order(:range).last).none? do |respondent|
respondent.total_teachers.present?
respondent&.total_teachers&.zero?
end
StaffingLoader.clone_previous_year_data if missing_staffing_for_current_year
end
private
def marked?(mark)
mark.present? ? mark.upcase.strip == 'X' : false
mark.present? ? mark.upcase.strip == "X" : false
end
def remove_commas(target)
target.delete(',') if target.present?
target.delete(",") if target.present?
end
end

@ -45,6 +45,35 @@ class EnrollmentLoader
respondent
end
def self.clone_previous_year_data
years = AcademicYear.order(:range).last(2)
previous_year = years.first
current_year = years.last
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.pk = respondent.pk
current_respondent.k = respondent.k
current_respondent.one = respondent.one
current_respondent.two = respondent.two
current_respondent.three = respondent.three
current_respondent.four = respondent.four
current_respondent.five = respondent.five
current_respondent.six = respondent.six
current_respondent.seven = respondent.seven
current_respondent.eight = respondent.eight
current_respondent.nine = respondent.nine
current_respondent.ten = respondent.ten
current_respondent.eleven = respondent.eleven
current_respondent.twelve = respondent.twelve
current_respondent.total_students = respondent.total_students
respondents << current_respondent
end
end
Respondent.import respondents, batch_size: 1000, on_duplicate_key_update: [:total_teachers]
end
private_class_method :create_enrollment_entry
end

@ -1,6 +1,6 @@
# frozen_string_literal: true
require 'csv'
require "csv"
class StaffingLoader
def self.load_data(filepath:)
@ -54,19 +54,19 @@ class StaffingRowValues
def school
@school ||= begin
dese_id = row['DESE ID'].strip.to_i
dese_id = row["DESE ID"].strip.to_i
School.find_by_dese_id(dese_id)
end
end
def academic_year
@academic_year ||= begin
year = row['Academic Year']
year = row["Academic Year"]
AcademicYear.find_by_range(year)
end
end
def fte_count
row['FTE Count']
row["FTE Count"]
end
end

@ -2,7 +2,7 @@ require "#{Rails.root}/app/lib/seeder"
seeder = Seeder.new
seeder.seed_academic_years "2016-17", "2017-18", "2018-19", "2019-20", "2020-21", "2021-22", "2022-23"
seeder.seed_academic_years "2016-17", "2017-18", "2018-19", "2019-20", "2020-21", "2021-22", "2022-23", "2023-24"
seeder.seed_districts_and_schools Rails.root.join("data", "master_list_of_schools_and_districts.csv")
seeder.seed_sqm_framework Rails.root.join("data", "sqm_framework.csv")
seeder.seed_demographics Rails.root.join("data", "demographics.csv")

Loading…
Cancel
Save