mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-13 09:20:38 -07:00
Visualize survey responses even when a response rate cannot be
calculated. Set the response rate to N / A for data that has no total student and teacher data for a certain year and school
This commit is contained in:
parent
c0a8905fba
commit
91308b93e5
5 changed files with 47 additions and 11 deletions
|
|
@ -9,6 +9,8 @@ module ResponseRate
|
||||||
end
|
end
|
||||||
|
|
||||||
def rate
|
def rate
|
||||||
|
return 100 if Respondent.where(school: @school, academic_year: @academic_year).count.zero?
|
||||||
|
|
||||||
return 0 unless survey_item_count.positive?
|
return 0 unless survey_item_count.positive?
|
||||||
|
|
||||||
average_responses_per_survey_item = response_count / survey_item_count.to_f
|
average_responses_per_survey_item = response_count / survey_item_count.to_f
|
||||||
|
|
|
||||||
|
|
@ -30,11 +30,14 @@ class SubcategoryPresenter
|
||||||
end
|
end
|
||||||
|
|
||||||
def student_response_rate
|
def student_response_rate
|
||||||
@subcategory.student_response_rate(school: @school, academic_year: @academic_year).rate
|
return 'N / A' if Respondent.where(school: @school, academic_year: @academic_year).count.zero?
|
||||||
|
|
||||||
|
"#{@subcategory.student_response_rate(school: @school, academic_year: @academic_year).rate}%"
|
||||||
end
|
end
|
||||||
|
|
||||||
def teacher_response_rate
|
def teacher_response_rate
|
||||||
@subcategory.teacher_response_rate(school: @school, academic_year: @academic_year).rate
|
return 'N / A' if Respondent.where(school: @school, academic_year: @academic_year).count.zero?
|
||||||
|
"#{@subcategory.teacher_response_rate(school: @school, academic_year: @academic_year).rate}%"
|
||||||
end
|
end
|
||||||
|
|
||||||
def admin_collection_rate
|
def admin_collection_rate
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,11 @@
|
||||||
<p>school admin data sources</p>
|
<p>school admin data sources</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="body-large mx-3 text-center response-rate">
|
<div class="body-large mx-3 text-center response-rate">
|
||||||
<p class="response-rate-percentage"><%= subcategory.student_response_rate %>%</p>
|
<p class="response-rate-percentage"><%= subcategory.student_response_rate %></p>
|
||||||
<p>of students responded</p>
|
<p>of students responded</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="body-large text-center response-rate">
|
<div class="body-large text-center response-rate">
|
||||||
<p class="response-rate-percentage"><%= subcategory.teacher_response_rate %>%</p>
|
<p class="response-rate-percentage"><%= subcategory.teacher_response_rate %></p>
|
||||||
<p>of teachers responded</p>
|
<p>of teachers responded</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,6 @@ require 'rails_helper'
|
||||||
describe ResponseRate, type: :model do
|
describe ResponseRate, 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_respondents) do
|
|
||||||
create(:respondent, school:, academic_year:)
|
|
||||||
end
|
|
||||||
|
|
||||||
describe StudentResponseRate do
|
describe StudentResponseRate do
|
||||||
let(:subcategory) { create(:subcategory) }
|
let(:subcategory) { create(:subcategory) }
|
||||||
|
|
@ -18,7 +15,6 @@ describe ResponseRate, type: :model do
|
||||||
let(:sufficient_student_survey_item_2) { create(:student_survey_item, scale: sufficient_scale_2) }
|
let(:sufficient_student_survey_item_2) { create(:student_survey_item, scale: sufficient_scale_2) }
|
||||||
|
|
||||||
before :each do
|
before :each do
|
||||||
survey_respondents
|
|
||||||
create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: sufficient_teacher_survey_item,
|
create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: sufficient_teacher_survey_item,
|
||||||
academic_year:, school:, likert_score: 1)
|
academic_year:, school:, likert_score: 1)
|
||||||
create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, survey_item: sufficient_student_survey_item_1,
|
create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD, survey_item: sufficient_student_survey_item_1,
|
||||||
|
|
@ -28,6 +24,7 @@ describe ResponseRate, type: :model do
|
||||||
end
|
end
|
||||||
context 'when a students take a regular survey' do
|
context 'when a students take a regular survey' do
|
||||||
before :each do
|
before :each do
|
||||||
|
create(:respondent, school:, academic_year:)
|
||||||
create(:survey, school:, academic_year:)
|
create(:survey, school:, academic_year:)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -41,6 +38,7 @@ describe ResponseRate, type: :model do
|
||||||
|
|
||||||
context 'when students take the short form survey' do
|
context 'when students take the short form survey' do
|
||||||
before :each do
|
before :each do
|
||||||
|
create(:respondent, school:, academic_year:)
|
||||||
create(:survey, form: :short, school:, academic_year:)
|
create(:survey, form: :short, school:, academic_year:)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -67,6 +65,25 @@ describe ResponseRate, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when the average number of teacher responses is greater than the total possible responses' do
|
||||||
|
before do
|
||||||
|
create(:respondent, school:, academic_year:)
|
||||||
|
create(:survey, school:, academic_year:)
|
||||||
|
create_list(:survey_item_response, SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD * 11, survey_item: sufficient_student_survey_item_2,
|
||||||
|
academic_year:, school:, likert_score: 1)
|
||||||
|
end
|
||||||
|
it 'returns 100 percent' do
|
||||||
|
expect(StudentResponseRate.new(subcategory:, school:,
|
||||||
|
academic_year:).rate).to eq 100
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when no survey information exists for that school or year' do
|
||||||
|
it 'returns 100 percent' do
|
||||||
|
expect(StudentResponseRate.new(subcategory:, school:, academic_year:).rate).to eq 100
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe TeacherResponseRate do
|
describe TeacherResponseRate do
|
||||||
|
|
@ -81,7 +98,6 @@ describe ResponseRate, type: :model do
|
||||||
let(:sufficient_student_survey_item_1) { create(:student_survey_item, scale: sufficient_scale_1) }
|
let(:sufficient_student_survey_item_1) { create(:student_survey_item, scale: sufficient_scale_1) }
|
||||||
|
|
||||||
before :each do
|
before :each do
|
||||||
survey_respondents
|
|
||||||
create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: sufficient_teacher_survey_item_1,
|
create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: sufficient_teacher_survey_item_1,
|
||||||
academic_year:, school:, likert_score: 1)
|
academic_year:, school:, likert_score: 1)
|
||||||
create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: sufficient_teacher_survey_item_2,
|
create_list(:survey_item_response, SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD, survey_item: sufficient_teacher_survey_item_2,
|
||||||
|
|
@ -91,6 +107,10 @@ describe ResponseRate, type: :model do
|
||||||
end
|
end
|
||||||
|
|
||||||
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
|
||||||
|
create(:respondent, school:, academic_year:)
|
||||||
|
create(:survey, school:, academic_year:)
|
||||||
|
end
|
||||||
it 'returns 25 percent' do
|
it 'returns 25 percent' do
|
||||||
expect(TeacherResponseRate.new(subcategory:, school:,
|
expect(TeacherResponseRate.new(subcategory:, school:,
|
||||||
academic_year:).rate).to eq 25
|
academic_year:).rate).to eq 25
|
||||||
|
|
@ -99,6 +119,8 @@ describe ResponseRate, 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
|
||||||
|
create(:respondent, school:, academic_year:)
|
||||||
|
create(:survey, school:, academic_year:)
|
||||||
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
|
||||||
|
|
@ -110,6 +132,8 @@ describe ResponseRate, 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
|
||||||
|
create(:respondent, school:, academic_year:)
|
||||||
|
create(:survey, school:, academic_year:)
|
||||||
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
|
||||||
|
|
@ -118,5 +142,12 @@ describe ResponseRate, type: :model do
|
||||||
academic_year:).rate).to eq 100
|
academic_year:).rate).to eq 100
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when no survey information exists for that school and academic_year' do
|
||||||
|
it 'returns 100 percent' do
|
||||||
|
expect(TeacherResponseRate.new(subcategory:, school:,
|
||||||
|
academic_year:).rate).to eq 100
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -68,11 +68,11 @@ describe SubcategoryPresenter do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the student response rate' do
|
it 'returns the student response rate' do
|
||||||
expect(subcategory_presenter.student_response_rate).to eq 25
|
expect(subcategory_presenter.student_response_rate).to eq "25%"
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the teacher response rate' do
|
it 'returns the teacher response rate' do
|
||||||
expect(subcategory_presenter.teacher_response_rate).to eq 50
|
expect(subcategory_presenter.teacher_response_rate).to eq "50%"
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the admin collection rate' do
|
it 'returns the admin collection rate' do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue