Show parent response rate

This commit is contained in:
Nelson Jovel 2024-10-31 20:05:26 -07:00
parent 7d4db37ee7
commit 0c661930e9
14 changed files with 113 additions and 50 deletions

View file

@ -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

2
app/models/parent.rb Normal file
View file

@ -0,0 +1,2 @@
class Parent < ApplicationRecord
end

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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|

View file

@ -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

View file

@ -21,11 +21,15 @@
</div>
<%= render partial: "quality_framework_indicators", locals: { category_presenters: @category_presenters } %>
<% if @page.show_response_rates %>
<% if @page.show_student_response_rates %>
<div class="overall-response-rate-row">
<%= render partial: "response_rate", locals: {response_rate_presenter: @student_response_rate_presenter} %>
<%= render partial: "response_rate", locals: {response_rate_presenter: @teacher_response_rate_presenter} %>
</div>
<% else %>
<div class="overall-response-rate-row">
<%= render partial: "response_rate", locals: {response_rate_presenter: @parent_response_rate_presenter} %>
</div>
<% end %>
</div>