Remove surveys table from codebase since it's no longer needed after changing logic surrounding response rates and score calculations

rpp-main
rebuilt 3 years ago
parent 2e0d266434
commit 0bd70ca452

@ -46,34 +46,9 @@ class Seeder
School.import schools, on_duplicate_key_update: :all School.import schools, on_duplicate_key_update: :all
Respondent.joins(:school).where.not("school.dese_id": dese_ids).destroy_all Respondent.joins(:school).where.not("school.dese_id": dese_ids).destroy_all
Survey.joins(:school).where.not("school.dese_id": dese_ids).destroy_all
School.where.not(dese_id: dese_ids).destroy_all School.where.not(dese_id: dese_ids).destroy_all
end end
def seed_surveys(csv_file)
surveys = []
CSV.parse(File.read(csv_file), headers: true) do |row|
district_name = row['District'].strip
next if rules.any? do |rule|
rule.new(row:).skip_row?
end
district = District.find_or_create_by! name: district_name
dese_id = row['DESE School ID'].strip
school = School.find_or_initialize_by(dese_id:, district:)
academic_years = AcademicYear.all
academic_years.each do |academic_year|
short_form = row["Short Form Only (#{academic_year.range})"]
survey = Survey.find_or_initialize_by(school:, academic_year:)
is_short_form_school = marked?(short_form)
survey.form = is_short_form_school ? Survey.forms[:short] : Survey.forms[:normal]
surveys << survey
end
end
Survey.import surveys, on_duplicate_key_update: :all
end
def seed_sqm_framework(csv_file) def seed_sqm_framework(csv_file)
admin_data_item_ids = [] admin_data_item_ids = []
CSV.parse(File.read(csv_file), headers: true) do |row| CSV.parse(File.read(csv_file), headers: true) do |row|
@ -163,6 +138,6 @@ class Seeder
end end
def remove_commas(target) def remove_commas(target)
target.gsub(',', '') if target.present? target.delete(',') if target.present?
end end
end end

@ -10,7 +10,7 @@ class Scale < ApplicationRecord
@score ||= Hash.new do |memo, (school, academic_year)| @score ||= Hash.new do |memo, (school, academic_year)|
memo[[school, academic_year]] = begin memo[[school, academic_year]] = begin
items = [] items = []
items << collect_survey_item_average(student_survey_items(school:, academic_year:), school, academic_year) items << collect_survey_item_average(student_survey_items, school, academic_year)
items << collect_survey_item_average(teacher_survey_items, school, academic_year) items << collect_survey_item_average(teacher_survey_items, school, academic_year)
items.remove_blanks.average items.remove_blanks.average
@ -38,11 +38,7 @@ class Scale < ApplicationRecord
survey_items.teacher_survey_items survey_items.teacher_survey_items
end end
def student_survey_items(school:, academic_year:) def student_survey_items
survey = Survey.where(school:, academic_year:).first survey_items.student_survey_items
student_survey_items = survey_items.student_survey_items
return student_survey_items.short_form_items if survey.present? && survey.form == 'short'
student_survey_items
end end
end end

@ -1,9 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
class Survey < ApplicationRecord class Survey < ApplicationRecord
belongs_to :academic_year
belongs_to :school
enum form: { enum form: {
normal: 0, normal: 0,
short: 1 short: 1

@ -0,0 +1,11 @@
class DropSurveysTable < ActiveRecord::Migration[7.0]
def change
drop_table :surveys do |t|
t.integer :form
t.references :academic_year, null: false, foreign_key: true
t.references :school, null: false, foreign_key: true
t.timestamps
end
end
end

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_03_04_132801) do ActiveRecord::Schema[7.0].define(version: 2023_04_21_034505) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -470,16 +470,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_04_132801) do
t.index ["survey_item_id"], name: "index_survey_items_on_survey_item_id" t.index ["survey_item_id"], name: "index_survey_items_on_survey_item_id"
end end
create_table "surveys", force: :cascade do |t|
t.integer "form"
t.bigint "academic_year_id", null: false
t.bigint "school_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["academic_year_id"], name: "index_surveys_on_academic_year_id"
t.index ["school_id"], name: "index_surveys_on_school_id"
end
add_foreign_key "admin_data_items", "scales" add_foreign_key "admin_data_items", "scales"
add_foreign_key "admin_data_values", "academic_years" add_foreign_key "admin_data_values", "academic_years"
add_foreign_key "admin_data_values", "admin_data_items" add_foreign_key "admin_data_values", "admin_data_items"
@ -513,6 +503,4 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_04_132801) do
add_foreign_key "survey_item_responses", "students" add_foreign_key "survey_item_responses", "students"
add_foreign_key "survey_item_responses", "survey_items" add_foreign_key "survey_item_responses", "survey_items"
add_foreign_key "survey_items", "scales" add_foreign_key "survey_items", "scales"
add_foreign_key "surveys", "academic_years"
add_foreign_key "surveys", "schools"
end end

@ -4,7 +4,6 @@ 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'
seeder.seed_districts_and_schools Rails.root.join('data', 'master_list_of_schools_and_districts.csv') seeder.seed_districts_and_schools Rails.root.join('data', 'master_list_of_schools_and_districts.csv')
seeder.seed_surveys Rails.root.join('data', 'master_list_of_schools_and_districts.csv')
seeder.seed_sqm_framework Rails.root.join('data', 'sqm_framework.csv') seeder.seed_sqm_framework Rails.root.join('data', 'sqm_framework.csv')
seeder.seed_demographics Rails.root.join('data', 'demographics.csv') seeder.seed_demographics Rails.root.join('data', 'demographics.csv')
seeder.seed_enrollment Rails.root.join('data', 'enrollment', 'enrollment.csv') seeder.seed_enrollment Rails.root.join('data', 'enrollment', 'enrollment.csv')

@ -10,8 +10,6 @@ describe Seeder do
end end
context 'academic years' do context 'academic years' do
# before { AcademicYear.delete_all }
it 'seeds new academic years' do it 'seeds new academic years' do
expect do expect do
seeder.seed_academic_years '2020-21', '2021-22', '2022-23' seeder.seed_academic_years '2020-21', '2021-22', '2022-23'
@ -57,7 +55,6 @@ describe Seeder do
create(:school, name: 'John Oldest Academy', dese_id: 12_345, district: existing_district) create(:school, name: 'John Oldest Academy', dese_id: 12_345, district: existing_district)
end end
let!(:removed_survey_item_response) { create(:survey_item_response, school: removed_school) } let!(:removed_survey_item_response) { create(:survey_item_response, school: removed_school) }
let!(:removed_survey) { create(:survey, school: removed_school) }
let!(:existing_school) do let!(:existing_school) do
create(:school, name: 'Sam Adams Elementary School', dese_id: 350_302, slug: 'some-slug-for-sam-adams', create(:school, name: 'Sam Adams Elementary School', dese_id: 350_302, slug: 'some-slug-for-sam-adams',
district: existing_district) district: existing_district)
@ -99,7 +96,6 @@ describe Seeder do
expect(School.where(id: removed_school)).not_to exist expect(School.where(id: removed_school)).not_to exist
expect(SurveyItemResponse.where(id: removed_survey_item_response)).not_to exist expect(SurveyItemResponse.where(id: removed_survey_item_response)).not_to exist
expect(Survey.where(id: removed_survey)).not_to exist
end end
end end
@ -158,42 +154,6 @@ describe Seeder do
# end # end
# end # end
context 'surveys' do
before :each do
create(:academic_year, range: '2020-21')
seeder.seed_districts_and_schools sample_districts_and_schools_csv
seeder.seed_surveys sample_districts_and_schools_csv
end
it 'for one academic year, it seeds a count of surveys equal to the count of schools' do
expect(Survey.count).to eq School.count
end
it 'marks short form schools as short form schools' do
elementary_school = School.find_by_dese_id 160_001
academic_year = AcademicYear.find_by_range '2020-21'
survey = Survey.where(school: elementary_school, academic_year:).first
expect(survey.form).to eq 'short'
end
it 'does not mark long form schools as short form schools' do
elementary_school = School.find_by_dese_id 350_302
academic_year = AcademicYear.find_by_range '2020-21'
survey = Survey.where(school: elementary_school, academic_year:).first
expect(survey.form).to eq 'normal'
end
it 'seed idempotently' do
expect do
seeder.seed_surveys sample_districts_and_schools_csv
end.to change { Survey.count }.by 0
end
it 'seeds new surveys for every year in the database' do
expect do
create(:academic_year, range: '2019-20')
seeder.seed_surveys sample_districts_and_schools_csv
end.to change { Survey.count }.by School.count
end
end
context 'admin data items' do context 'admin data items' do
context 'when deprecated admin items exist in the database' do context 'when deprecated admin items exist in the database' do
before :each do before :each do

@ -27,9 +27,7 @@ RSpec.describe Measure, type: :model do
before do before do
create(:respondent, school:, academic_year:, one: 40) create(:respondent, school:, academic_year:, one: 40)
create(:survey, school:, academic_year:)
create(:respondent, school: short_form_school, academic_year:) create(:respondent, school: short_form_school, academic_year:)
create(:survey, school: short_form_school, academic_year:, form: 'short')
end end
describe 'benchmarks' do describe 'benchmarks' do

@ -20,7 +20,6 @@ RSpec.describe Report::Pillar, type: :model do
before :each do before :each do
create(:respondent, school:, academic_year: academic_year_1) create(:respondent, school:, academic_year: academic_year_1)
create(:survey, school:, academic_year: academic_year_1)
measures measures
end end

@ -3,7 +3,6 @@ require 'rails_helper'
describe ResponseRateCalculator, type: :model do describe ResponseRateCalculator, type: :model do
let(:school) { create(:school) } let(:school) { create(:school) }
let(:academic_year) { create(:academic_year) } let(:academic_year) { create(:academic_year) }
let(:survey) { create(:survey, school:, academic_year:) }
describe StudentResponseRateCalculator do describe StudentResponseRateCalculator do
let(:subcategory) { create(:subcategory) } let(:subcategory) { create(:subcategory) }
@ -215,7 +214,6 @@ describe ResponseRateCalculator, type: :model do
context 'when the average number of teacher responses per question in a subcategory is at the threshold' do context 'when the average number of teacher responses per question in a subcategory is at the threshold' do
before :each do before :each do
respondent respondent
survey
end end
it 'returns 25 percent' do it 'returns 25 percent' do
expect(TeacherResponseRateCalculator.new(subcategory:, school:, expect(TeacherResponseRateCalculator.new(subcategory:, school:,
@ -226,7 +224,6 @@ describe ResponseRateCalculator, type: :model do
context 'when the teacher response rate is not a whole number. eg 29.166%' do context 'when the teacher response rate is not a whole number. eg 29.166%' do
before do before do
respondent respondent
survey
create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD + 1, survey_item: sufficient_teacher_survey_item_3, create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD + 1, survey_item: sufficient_teacher_survey_item_3,
academic_year:, school:, likert_score: 1) academic_year:, school:, likert_score: 1)
end end
@ -239,7 +236,6 @@ describe ResponseRateCalculator, type: :model do
context 'when the average number of teacher responses is greater than the total possible responses' do context 'when the average number of teacher responses is greater than the total possible responses' do
before do before do
respondent respondent
survey
create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD * 11, survey_item: sufficient_teacher_survey_item_3, create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD * 11, survey_item: sufficient_teacher_survey_item_3,
academic_year:, school:, likert_score: 1) academic_year:, school:, likert_score: 1)
end end
@ -260,7 +256,6 @@ describe ResponseRateCalculator, type: :model do
context 'and one of the teacher items has no associated survey item responses' do context 'and one of the teacher items has no associated survey item responses' do
before do before do
respondent respondent
survey
insufficient_teacher_survey_item_4 insufficient_teacher_survey_item_4
end end
it 'ignores the empty survey item and returns only the average response rate of teacher survey items with responses' do it 'ignores the empty survey item and returns only the average response rate of teacher survey items with responses' do

@ -4,9 +4,6 @@ RSpec.describe Scale, type: :model do
let(:school) { create(:school) } let(:school) { create(:school) }
let(:academic_year) { create(:academic_year) } let(:academic_year) { create(:academic_year) }
let(:scale) { create(:scale) } let(:scale) { create(:scale) }
before do
create(:survey, school:, academic_year:)
end
describe '.score' do describe '.score' do
let(:teacher_survey_item_1) { create(:teacher_survey_item, scale:) } let(:teacher_survey_item_1) { create(:teacher_survey_item, scale:) }
@ -45,12 +42,12 @@ RSpec.describe Scale, type: :model do
context 'when both teacher and student survey items exist' do context 'when both teacher and student survey items exist' do
before :each do before :each do
create(:survey_item_response, create(:survey_item_response,
survey_item: teacher_survey_item_1, academic_year:, school:, likert_score: 3) survey_item: teacher_survey_item_1, academic_year:, school:, likert_score: 3)
create(:survey_item_response, create(:survey_item_response,
survey_item: teacher_survey_item_2, academic_year:, school:, likert_score: 4) survey_item: teacher_survey_item_2, academic_year:, school:, likert_score: 4)
create(:survey_item_response, create(:survey_item_response,
survey_item: teacher_survey_item_3, academic_year:, school:, likert_score: 5) survey_item: teacher_survey_item_3, academic_year:, school:, likert_score: 5)
end end
context 'but no survey item responses are linked to student survey items' do context 'but no survey item responses are linked to student survey items' do
before :each do before :each do

@ -10,7 +10,6 @@ RSpec.describe Subcategory, type: :model do
let(:student_scale) { create(:student_scale, measure: measure_2) } let(:student_scale) { create(:student_scale, measure: measure_2) }
before do before do
create(:respondent, school:, academic_year:) create(:respondent, school:, academic_year:)
create(:survey, school:, academic_year:)
end end
describe '.score' do describe '.score' do
@ -25,21 +24,21 @@ RSpec.describe Subcategory, type: :model do
before :each do before :each do
create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD,
survey_item: teacher_survey_item_1, academic_year:, school:, likert_score: 2) survey_item: teacher_survey_item_1, academic_year:, school:, likert_score: 2)
create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD,
survey_item: teacher_survey_item_2, academic_year:, school:, likert_score: 3) survey_item: teacher_survey_item_2, academic_year:, school:, likert_score: 3)
create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD,
survey_item: teacher_survey_item_3, academic_year:, school:, likert_score: 4) survey_item: teacher_survey_item_3, academic_year:, school:, likert_score: 4)
create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD,
survey_item: student_survey_item_1, academic_year:, school:, likert_score: 1) survey_item: student_survey_item_1, academic_year:, school:, likert_score: 1)
create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD,
survey_item: student_survey_item_2, academic_year:, school:, likert_score: 2) survey_item: student_survey_item_2, academic_year:, school:, likert_score: 2)
create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD,
survey_item: student_survey_item_3, academic_year:, school:, likert_score: 3) survey_item: student_survey_item_3, academic_year:, school:, likert_score: 3)
create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD,
survey_item: student_survey_item_4, academic_year:, school:, likert_score: 4) survey_item: student_survey_item_4, academic_year:, school:, likert_score: 4)
create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD,
survey_item: student_survey_item_5, academic_year:, school:, likert_score: 5) survey_item: student_survey_item_5, academic_year:, school:, likert_score: 5)
end end
it 'returns the average of the likert scores of the measures' do it 'returns the average of the likert scores of the measures' do

@ -3,9 +3,6 @@ RSpec.describe SurveyItem, type: :model do
let(:school) { create(:school) } let(:school) { create(:school) }
let(:academic_year) { create(:academic_year) } let(:academic_year) { create(:academic_year) }
let(:scale) { create(:scale) } let(:scale) { create(:scale) }
before :each do
create(:survey, school:, academic_year:)
end
describe '.score' do describe '.score' do
let(:teacher_survey_item) { create(:teacher_survey_item, scale:) } let(:teacher_survey_item) { create(:teacher_survey_item, scale:) }

@ -79,8 +79,6 @@ describe GroupedBarColumnPresenter do
before do before do
create(:respondent, school:, academic_year:, total_students: 1, total_teachers: 1) create(:respondent, school:, academic_year:, total_students: 1, total_teachers: 1)
create(:survey, form: :normal, school:, academic_year:)
create(:survey, form: :normal, school:, academic_year: another_academic_year)
end end
shared_examples_for 'measure_name' do shared_examples_for 'measure_name' do

@ -10,7 +10,6 @@ describe MeasurePresenter do
let(:measure_presenter) { MeasurePresenter.new(measure:, academic_year:, school:) } let(:measure_presenter) { MeasurePresenter.new(measure:, academic_year:, school:) }
before do before do
create(:respondent, school:, academic_year:) create(:respondent, school:, academic_year:)
create(:survey, school:, academic_year:)
end end
it "returns the id of the measure" do it "returns the id of the measure" do

@ -50,7 +50,6 @@ describe SubcategoryPresenter do
before do before do
create(:respondent, school:, academic_year:, one: 40) create(:respondent, school:, academic_year:, one: 40)
create(:survey, school:, academic_year:)
end end
it 'returns the name of the subcategory' do it 'returns the name of the subcategory' do

@ -13,7 +13,6 @@ describe 'SQM Application' do
driven_by :rack_test driven_by :rack_test
page.driver.browser.basic_authorize(username, password) page.driver.browser.basic_authorize(username, password)
create(:respondent, school:, academic_year:) create(:respondent, school:, academic_year:)
create(:survey, school:, academic_year:)
ResponseRate.create!(subcategory:, school:, academic_year:, ResponseRate.create!(subcategory:, school:, academic_year:,
student_response_rate: 0, teacher_response_rate: 0, meets_student_threshold: false, meets_teacher_threshold: false) student_response_rate: 0, teacher_response_rate: 0, meets_student_threshold: false, meets_teacher_threshold: false)
end end

@ -119,7 +119,6 @@ describe 'analyze/index' do
assign :genders, genders assign :genders, genders
assign :selected_genders, selected_genders assign :selected_genders, selected_genders
create(:respondent, school:, academic_year:) create(:respondent, school:, academic_year:)
create(:survey, school:, academic_year:)
end end
context 'when all the presenters have a nil score' do context 'when all the presenters have a nil score' do
before do before do

@ -76,7 +76,6 @@ describe 'categories/show' do
assign :academic_years, [academic_year] assign :academic_years, [academic_year]
create(:respondent, school:, academic_year:) create(:respondent, school:, academic_year:)
create(:survey, school:, academic_year:)
end end
context 'for each category' do context 'for each category' do

Loading…
Cancel
Save