diff --git a/app/controllers/overview_controller.rb b/app/controllers/overview_controller.rb
index 1bbf4d4e..3f9a0c34 100644
--- a/app/controllers/overview_controller.rb
+++ b/app/controllers/overview_controller.rb
@@ -15,5 +15,6 @@ class OverviewController < SqmApplicationController
@category_presenters = @page.category_presenters
@student_response_rate_presenter = @page.student_response_rate_presenter
@teacher_response_rate_presenter = @page.teacher_response_rate_presenter
+ @parent_response_rate_presenter = @page.parent_response_rate_presenter
end
end
diff --git a/app/models/parent.rb b/app/models/parent.rb
new file mode 100644
index 00000000..2d556d15
--- /dev/null
+++ b/app/models/parent.rb
@@ -0,0 +1,2 @@
+class Parent < ApplicationRecord
+end
diff --git a/app/models/survey_item_response.rb b/app/models/survey_item_response.rb
index acdc9407..c1d8d270 100644
--- a/app/models/survey_item_response.rb
+++ b/app/models/survey_item_response.rb
@@ -8,6 +8,7 @@ class SurveyItemResponse < ActiveRecord::Base
belongs_to :school
belongs_to :survey_item, counter_cache: true
belongs_to :student, foreign_key: :student_id, optional: true
+ belongs_to :parent, optional: true
belongs_to :gender, optional: true
belongs_to :income, optional: true
belongs_to :ell, optional: true
diff --git a/app/presenters/overview/overview_presenter.rb b/app/presenters/overview/overview_presenter.rb
index 94fae8b9..02e97361 100644
--- a/app/presenters/overview/overview_presenter.rb
+++ b/app/presenters/overview/overview_presenter.rb
@@ -27,7 +27,7 @@ class Overview::OverviewPresenter
"school-quality-frameworks"
end
- def show_response_rates
+ def show_student_response_rates
view == "student"
end
@@ -43,6 +43,10 @@ class Overview::OverviewPresenter
ResponseRatePresenter.new(focus: :teacher, school: @school, academic_year: @academic_year)
end
+ def parent_response_rate_presenter
+ ResponseRatePresenter.new(focus: :parent, school: @school, academic_year: @academic_year)
+ end
+
def presenter_for_measure(measure)
score = measure.score(school: @school, academic_year: @academic_year)
diff --git a/app/presenters/response_rate_presenter.rb b/app/presenters/response_rate_presenter.rb
index 947cce4d..c5ab79c3 100644
--- a/app/presenters/response_rate_presenter.rb
+++ b/app/presenters/response_rate_presenter.rb
@@ -11,6 +11,7 @@ class ResponseRatePresenter
end
end
@survey_items = SurveyItem.teacher_survey_items if focus == :teacher
+ @survey_items = SurveyItem.parent_survey_items if focus == :parent
end
def date
@@ -49,6 +50,12 @@ class ResponseRatePresenter
def actual_count
if focus == :teacher
response_count_for_survey_items(survey_items:)
+ elsif focus == :parent
+ SurveyItemResponse.includes(:parent).where(school:, academic_year:).where.not(parent_id: nil)
+ .select(:parent_id)
+ .distinct
+ .map { |response| response.parent&.number_of_children }
+ .compact.sum
else
non_early_ed_items = survey_items - SurveyItem.early_education_survey_items
non_early_ed_count = response_count_for_survey_items(survey_items: non_early_ed_items)
@@ -81,7 +88,7 @@ class ResponseRatePresenter
def respondents_count
return 0 if respondents.nil?
- count = enrollment if focus == :student
+ count = enrollment if focus == :student || focus == :parent
count = respondents.total_teachers if focus == :teacher
count
end
diff --git a/app/services/survey_item_values.rb b/app/services/survey_item_values.rb
index 60045764..17d3026d 100644
--- a/app/services/survey_item_values.rb
+++ b/app/services/survey_item_values.rb
@@ -67,11 +67,7 @@ class SurveyItemValues
end
def survey_item_response(survey_item:)
- @survey_item_response ||= Hash.new do |memo, survey_item|
- memo[survey_item] = survey_item_responses[[response_id, survey_item.id]]
- end
-
- @survey_item_response[survey_item]
+ survey_item_responses[[response_id, survey_item.id]]
end
def survey_item_responses
@@ -192,6 +188,10 @@ class SurveyItemValues
@sped ||= Sped.to_designation(raw_sped)
end
+ def number_of_children
+ @number_of_children ||= value_from(pattern: /Number\s*Of\s*Children/i).to_i
+ end
+
def value_from(pattern:)
output = nil
matches = headers.select do |header|
diff --git a/app/services/survey_responses_data_loader.rb b/app/services/survey_responses_data_loader.rb
index 1108e509..a80154f8 100644
--- a/app/services/survey_responses_data_loader.rb
+++ b/app/services/survey_responses_data_loader.rb
@@ -87,10 +87,20 @@ class SurveyResponsesDataLoader
end
def process_survey_items(row:)
- student = Student.find_or_create_by(response_id: row.response_id, lasid: row.lasid)
- student.races.delete_all
- tmp_races = row.races.map { |race| races[race] }
- student.races += tmp_races
+ student = nil
+ parent = nil
+ if row.respondent_type == :student
+ student = Student.find_or_create_by(response_id: row.response_id, lasid: row.lasid)
+ student.races.delete_all
+ tmp_races = row.races.map { |race| races[race] }
+ student.races += tmp_races
+ end
+
+ if row.respondent_type == :parent
+ parent = Parent.find_or_create_by(response_id: row.response_id)
+ parent.number_of_children = row.number_of_children
+ parent.save
+ end
row
.survey_items
@@ -103,12 +113,12 @@ class SurveyResponsesDataLoader
end
response = row.survey_item_response(survey_item:)
- create_or_update_response(survey_item_response: response, likert_score:, row:, survey_item:, student:)
+ create_or_update_response(survey_item_response: response, likert_score:, row:, survey_item:, student:, parent:)
end
.compact
end
- def create_or_update_response(survey_item_response:, likert_score:, row:, survey_item:, student:)
+ def create_or_update_response(survey_item_response:, likert_score:, row:, survey_item:, student:, parent:)
gender = genders[row.gender]
grade = row.grade
income = incomes[row.income.parameterize]
@@ -124,6 +134,8 @@ class SurveyResponsesDataLoader
survey_item_response.ell = ell
survey_item_response.sped = sped
survey_item_response.student = student
+ survey_item_response.parent = parent
+
survey_item_response
else
SurveyItemResponse.new(
@@ -138,7 +150,8 @@ class SurveyResponsesDataLoader
income:,
ell:,
sped:,
- student:
+ student:,
+ parent:
)
end
end
diff --git a/app/views/overview/index.html.erb b/app/views/overview/index.html.erb
index 5af0c143..f2f984ff 100644
--- a/app/views/overview/index.html.erb
+++ b/app/views/overview/index.html.erb
@@ -21,11 +21,15 @@
<%= render partial: "quality_framework_indicators", locals: { category_presenters: @category_presenters } %>
-<% if @page.show_response_rates %>
+<% if @page.show_student_response_rates %>
<%= render partial: "response_rate", locals: {response_rate_presenter: @student_response_rate_presenter} %>
<%= render partial: "response_rate", locals: {response_rate_presenter: @teacher_response_rate_presenter} %>
+ <% else %>
+
+ <%= render partial: "response_rate", locals: {response_rate_presenter: @parent_response_rate_presenter} %>
+
<% end %>
diff --git a/db/migrate/20241031190531_create_parents.rb b/db/migrate/20241031190531_create_parents.rb
new file mode 100644
index 00000000..fe8270ce
--- /dev/null
+++ b/db/migrate/20241031190531_create_parents.rb
@@ -0,0 +1,10 @@
+class CreateParents < ActiveRecord::Migration[7.1]
+ def change
+ create_table :parents do |t|
+ t.string :response_id
+ t.integer :number_of_children
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20241031205926_add_parent_to_survey_item_response.rb b/db/migrate/20241031205926_add_parent_to_survey_item_response.rb
new file mode 100644
index 00000000..c16d61be
--- /dev/null
+++ b/db/migrate/20241031205926_add_parent_to_survey_item_response.rb
@@ -0,0 +1,5 @@
+class AddParentToSurveyItemResponse < ActiveRecord::Migration[7.1]
+ def change
+ add_reference :survey_item_responses, :parent, foreign_key: true
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 2b076e46..bd2d707b 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema[7.1].define(version: 2024_09_24_173209) do
+ActiveRecord::Schema[7.1].define(version: 2024_10_31_205926) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -316,6 +316,13 @@ ActiveRecord::Schema[7.1].define(version: 2024_09_24_173209) do
t.index ["subcategory_id"], name: "index_measures_on_subcategory_id"
end
+ create_table "parents", force: :cascade do |t|
+ t.string "response_id"
+ t.integer "number_of_children"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
create_table "races", force: :cascade do |t|
t.string "designation"
t.integer "qualtrics_code"
@@ -461,10 +468,12 @@ ActiveRecord::Schema[7.1].define(version: 2024_09_24_173209) do
t.datetime "recorded_date"
t.bigint "ell_id"
t.bigint "sped_id"
+ t.bigint "parent_id"
t.index ["academic_year_id"], name: "index_survey_item_responses_on_academic_year_id"
t.index ["ell_id"], name: "index_survey_item_responses_on_ell_id"
t.index ["gender_id"], name: "index_survey_item_responses_on_gender_id"
t.index ["income_id"], name: "index_survey_item_responses_on_income_id"
+ t.index ["parent_id"], name: "index_survey_item_responses_on_parent_id"
t.index ["response_id"], name: "index_survey_item_responses_on_response_id"
t.index ["school_id", "academic_year_id", "survey_item_id"], name: "by_school_year_and_survey_item"
t.index ["school_id", "survey_item_id", "academic_year_id", "grade"], name: "index_survey_responses_on_grade"
@@ -516,6 +525,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_09_24_173209) do
add_foreign_key "survey_item_responses", "ells"
add_foreign_key "survey_item_responses", "genders"
add_foreign_key "survey_item_responses", "incomes"
+ add_foreign_key "survey_item_responses", "parents"
add_foreign_key "survey_item_responses", "schools"
add_foreign_key "survey_item_responses", "speds"
add_foreign_key "survey_item_responses", "students"
diff --git a/spec/factories.rb b/spec/factories.rb
index 7899d1c6..4d32450c 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -1,4 +1,9 @@
FactoryBot.define do
+ factory :parent do
+ response_id { "MyString" }
+ number_of_children { 1 }
+ end
+
factory :income do
designation { "DefaultIncome" }
end
diff --git a/spec/models/parent_spec.rb b/spec/models/parent_spec.rb
new file mode 100644
index 00000000..a37df499
--- /dev/null
+++ b/spec/models/parent_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe Parent, type: :model do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
diff --git a/spec/services/survey_responses_data_loader_spec.rb b/spec/services/survey_responses_data_loader_spec.rb
index 731875e4..199f7cc1 100644
--- a/spec/services/survey_responses_data_loader_spec.rb
+++ b/spec/services/survey_responses_data_loader_spec.rb
@@ -21,6 +21,27 @@ describe SurveyResponsesDataLoader do
district: lowell)
end
+ let(:student_survey_items) do
+ ids = %w[ s-emsa-q1 s-emsa-q2 s-emsa-q3
+ s-tint-q1 s-tint-q2 s-tint-q4 s-tint-q5
+ s-acpr-q1 s-acpr-q2 s-acpr-q3 s-acpr-q4
+ s-cure-q3 s-cure-q4 s-sten-q2 s-sten-q3
+ s-sper-q1 s-sper-q2 s-sper-q3 s-sper-q4
+ s-civp-q1 s-civp-q2 s-civp-q3 s-civp-q4 s-grmi-q1
+ s-grmi-q4 s-appa-q1
+ s-appa-q2 s-peff-q1
+ s-peff-q2 s-peff-q3 s-peff-q4 s-peff-q5 s-peff-q6
+ s-sbel-q1 s-sbel-q2 s-sbel-q3 s-sbel-q4 s-sbel-q5
+ s-phys-q1 s-phys-q2 s-phys-q3 s-phys-q4
+ s-vale-q1 s-vale-q2 s-vale-q3 s-vale-q4
+ s-acst-q1 s-acst-q2 s-acst-q3 s-acst-q4 s-acst-q5
+ s-grit-q1 s-grit-q2 s-grit-q3 s-grit-q4]
+
+ ids.each do |id|
+ create(:survey_item, survey_item_id: id)
+ end
+ end
+
let(:t_pcom_q3) { create(:survey_item, survey_item_id: "t-pcom-q3") }
let(:t_pcom_q2) { create(:survey_item, survey_item_id: "t-pcom-q2") }
let(:t_coll_q1) { create(:survey_item, survey_item_id: "t-coll-q1") }
@@ -30,22 +51,6 @@ describe SurveyResponsesDataLoader do
let(:t_sach_q2) { create(:survey_item, survey_item_id: "t-sach-q2") }
let(:t_sach_q3) { create(:survey_item, survey_item_id: "t-sach-q3") }
- let(:s_phys_q1) { create(:survey_item, survey_item_id: "s-phys-q1") }
- let(:s_phys_q2) { create(:survey_item, survey_item_id: "s-phys-q2") }
- let(:s_phys_q3) { create(:survey_item, survey_item_id: "s-phys-q3") }
- let(:s_phys_q4) { create(:survey_item, survey_item_id: "s-phys-q4") }
- let(:s_vale_q1) { create(:survey_item, survey_item_id: "s-phys-q1") }
- let(:s_vale_q2) { create(:survey_item, survey_item_id: "s-phys-q2") }
- let(:s_vale_q3) { create(:survey_item, survey_item_id: "s-phys-q3") }
- let(:s_vale_q4) { create(:survey_item, survey_item_id: "s-phys-q4") }
- let(:s_acst_q1) { create(:survey_item, survey_item_id: "s-acst-q1") }
- let(:s_acst_q2) { create(:survey_item, survey_item_id: "s-acst-q2") }
- let(:s_acst_q3) { create(:survey_item, survey_item_id: "s-acst-q3") }
- let(:s_acst_q4) { create(:survey_item, survey_item_id: "s-acst-q4") }
- let(:s_emsa_q1) { create(:survey_item, survey_item_id: "s-emsa-q1") }
- let(:s_emsa_q2) { create(:survey_item, survey_item_id: "s-emsa-q2") }
- let(:s_emsa_q3) { create(:survey_item, survey_item_id: "s-emsa-q3") }
-
let(:female) { create(:gender, qualtrics_code: 1) }
let(:male) { create(:gender, qualtrics_code: 2) }
let(:another_gender) { create(:gender, qualtrics_code: 3) }
@@ -83,21 +88,7 @@ describe SurveyResponsesDataLoader do
t_sach_q1
t_sach_q2
t_sach_q3
- s_phys_q1
- s_phys_q2
- s_phys_q3
- s_phys_q4
- s_vale_q1
- s_vale_q2
- s_vale_q3
- s_vale_q4
- s_acst_q1
- s_acst_q2
- s_acst_q3
- s_acst_q4
- s_emsa_q1
- s_emsa_q2
- s_emsa_q3
+ student_survey_items
female
male
@@ -170,6 +161,7 @@ describe SurveyResponsesDataLoader do
end
it "updates the likert score to the score on the new csv file" do
s_emsa_q1 = SurveyItem.find_by_survey_item_id "s-emsa-q1"
+ s_acst_q3 = SurveyItem.find_by_survey_item_id "s-acst-q3"
expect(SurveyItemResponse.where(response_id: "student_survey_response_3",
survey_item: s_emsa_q1).first.likert_score).to eq 1
expect(SurveyItemResponse.where(response_id: "student_survey_response_4",
@@ -241,17 +233,21 @@ end
def loads_student_survey_item_response_values
expect(SurveyItemResponse.where(response_id: "student_survey_response_1").count).to eq 3
expect(SurveyItemResponse.where(response_id: "student_survey_response_2").count).to eq 0
- expect(SurveyItemResponse.where(response_id: "student_survey_response_3").count).to eq 12
- expect(SurveyItemResponse.where(response_id: "student_survey_response_4").count).to eq 15
- expect(SurveyItemResponse.where(response_id: "student_survey_response_5").count).to eq 14
+ expect(SurveyItemResponse.where(response_id: "student_survey_response_3").count).to eq 30
+ expect(SurveyItemResponse.where(response_id: "student_survey_response_4").count).to eq 27
+ expect(SurveyItemResponse.where(response_id: "student_survey_response_5").count).to eq 30
end
def student_survey_item_response_count_matches_expected
+ s_phys_q1 = SurveyItem.where(survey_item_id: "s-phys-q1")
+ s_phys_q2 = SurveyItem.where(survey_item_id: "s-phys-q2")
expect(SurveyItemResponse.where(survey_item: s_phys_q1).count).to eq 6
expect(SurveyItemResponse.where(survey_item: s_phys_q2).count).to eq 5
end
def captures_likert_scores_for_student_survey_item_responses
+ s_phys_q1 = SurveyItem.where(survey_item_id: "s-phys-q1")
+ s_phys_q2 = SurveyItem.where(survey_item_id: "s-phys-q2")
expect(SurveyItemResponse.where(response_id: "student_survey_response_1").where(survey_item: s_phys_q1).first.likert_score).to eq 3
expect(SurveyItemResponse.where(response_id: "student_survey_response_1").where(survey_item: s_phys_q2)).to be_empty