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:
Nelson Jovel 2022-03-04 15:17:43 +01:00
parent c0a8905fba
commit 91308b93e5
5 changed files with 47 additions and 11 deletions

View file

@ -9,6 +9,8 @@ module ResponseRate
end
def rate
return 100 if Respondent.where(school: @school, academic_year: @academic_year).count.zero?
return 0 unless survey_item_count.positive?
average_responses_per_survey_item = response_count / survey_item_count.to_f

View file

@ -30,11 +30,14 @@ class SubcategoryPresenter
end
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
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
def admin_collection_rate

View file

@ -16,11 +16,11 @@
<p>school admin data sources</p>
</div>
<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>
</div>
<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>
</div>
</div>