fix: revert rounding up the response rate so we can make sure to patch a bug first. Only show gender/race/grade/income graphs if the the school meets the minimum response rate of 25%

pull/1/head
rebuilt 2 years ago
parent 234eae6d3d
commit bec80b405a

@ -18,7 +18,7 @@ class ResponseRateCalculator
return 0 unless total_possible_responses.positive? return 0 unless total_possible_responses.positive?
cap_at_one_hundred(raw_response_rate).round cap_at_one_hundred(raw_response_rate)
end end
def meets_student_threshold? def meets_student_threshold?

@ -33,24 +33,6 @@ class Subcategory < ActiveRecord::Base
end.remove_blanks.average end.remove_blanks.average
end end
def student_score(school:, academic_year:)
measures.map do |measure|
measure.student_score(school:, academic_year:).average
end.compact.average
end
def teacher_score(school:, academic_year:)
measures.map do |measure|
measure.teacher_score(school:, academic_year:).average
end.compact.average
end
def admin_score(school:, academic_year:)
measures.map do |measure|
measure.admin_score(school:, academic_year:).average
end.compact.average
end
def response_rate(school:, academic_year:) def response_rate(school:, academic_year:)
@response_rate ||= Hash.new do |memo, (school, academic_year)| @response_rate ||= Hash.new do |memo, (school, academic_year)|
student = StudentResponseRateCalculator.new(subcategory: self, school:, academic_year:) student = StudentResponseRateCalculator.new(subcategory: self, school:, academic_year:)

@ -25,16 +25,20 @@ module Analyze
Score.new(average:, Score.new(average:,
meets_teacher_threshold: false, meets_teacher_threshold: false,
meets_student_threshold: true, meets_student_threshold:,
meets_admin_data_threshold: false) meets_admin_data_threshold: false)
end end
def sufficient_student_responses?(academic_year:) def sufficient_student_responses?(academic_year:)
sufficient_overall_responses = measure.subcategory.response_rate(school:,
academic_year:).meets_student_threshold
yearly_counts = SurveyItemResponse.where(school:, academic_year:, yearly_counts = SurveyItemResponse.where(school:, academic_year:,
gender:, survey_item: measure.student_survey_items).group(:gender).select(:response_id).distinct(:response_id).count gender:, survey_item: measure.student_survey_items).group(:gender).select(:response_id).distinct(:response_id).count
yearly_counts.any? do |count| more_than_ten_respondents = yearly_counts.any? do |count|
count[1] >= 10 count[1] >= 10
end end
sufficient_overall_responses && more_than_ten_respondents
end end
end end
end end

@ -4,13 +4,14 @@ module Analyze
module Grade module Grade
module ScoreForGrade module ScoreForGrade
def score(year_index) def score(year_index)
academic_year = academic_years[year_index]
averages = SurveyItemResponse.averages_for_grade(measure.student_survey_items, school, averages = SurveyItemResponse.averages_for_grade(measure.student_survey_items, school,
academic_years[year_index], grade) academic_year, grade)
average = bubble_up_averages(averages:).round(2) average = bubble_up_averages(averages:).round(2)
Score.new(average:, Score.new(average:,
meets_teacher_threshold: false, meets_teacher_threshold: false,
meets_student_threshold: true, meets_student_threshold: sufficient_student_responses?(academic_year:),
meets_admin_data_threshold: false) meets_admin_data_threshold: false)
end end
@ -21,6 +22,10 @@ module Analyze
end.remove_blanks.average end.remove_blanks.average
end.remove_blanks.average end.remove_blanks.average
end end
def sufficient_student_responses?(academic_year:)
measure.subcategory.response_rate(school:, academic_year:).meets_student_threshold
end
end end
end end
end end

@ -35,11 +35,7 @@ module Analyze
end end
def label def label
'All Data' "All Data"
end
def basis
''
end end
def show_irrelevancy_message? def show_irrelevancy_message?
@ -106,11 +102,23 @@ module Analyze
end end
def basis def basis
'student surveys' "student surveys"
end end
def insufficiency_message def insufficiency_message
['survey response', 'rate below 25%'] ["survey response", "rate below 25%"]
end
# TODO: figure out why this doesn't work
def sufficient_data?(year_index)
case basis
when "student"
score(year_index).meets_student_threshold
when "teacher"
score(year_index).meets_teacher_threshold
else
true
end
end end
private private

@ -25,16 +25,20 @@ module Analyze
Score.new(average:, Score.new(average:,
meets_teacher_threshold: false, meets_teacher_threshold: false,
meets_student_threshold: true, meets_student_threshold:,
meets_admin_data_threshold: false) meets_admin_data_threshold: false)
end end
def sufficient_student_responses?(academic_year:) def sufficient_student_responses?(academic_year:)
sufficient_overall_responses = measure.subcategory.response_rate(school:,
academic_year:).meets_student_threshold
yearly_counts = SurveyItemResponse.where(school:, academic_year:, yearly_counts = SurveyItemResponse.where(school:, academic_year:,
income:, survey_item: measure.student_survey_items).group(:income).select(:response_id).distinct(:response_id).count income:, survey_item: measure.student_survey_items).group(:income).select(:response_id).distinct(:response_id).count
yearly_counts.any? do |count| more_than_ten_respondents = yearly_counts.any? do |count|
count[1] >= 10 count[1] >= 10
end end
sufficient_overall_responses && more_than_ten_respondents
end end
end end
end end

@ -1,6 +1,7 @@
<g class="grouped-bar-column" data-for-measure-id="<%= column.measure.measure_id %>"> <g class="grouped-bar-column" data-for-measure-id="<%= column.measure.measure_id %>">
<% score_label_y = [5, 10, 15, 5, 10, 15 ] %> <% score_label_y = [5, 10, 15, 5, 10, 15 ] %>
<% column.bars.each_with_index do |bar, index| %> <% column.bars.each_with_index do |bar, index| %>
<% if column.sufficient_data?(index) %>
<rect data-for-academic-year="<%= bar.academic_year.range %>" x="<%= bar.x_position %>%" y="<%= bar.y_offset %>%" width="<%= column.bar_width %>%" height="<%= bar.bar_height_percentage %>%" fill="<%= bar.color %>" /> <rect data-for-academic-year="<%= bar.academic_year.range %>" x="<%= bar.x_position %>%" y="<%= bar.y_offset %>%" width="<%= column.bar_width %>%" height="<%= bar.bar_height_percentage %>%" fill="<%= bar.color %>" />
<% if ENV["SCORES"].present? && ENV["SCORES"].upcase == "SHOW" %> <% if ENV["SCORES"].present? && ENV["SCORES"].upcase == "SHOW" %>
@ -9,6 +10,7 @@
</text> </text>
<% end %> <% end %>
<% end %> <% end %>
<% end %>
<line x1="<%= column.column_start_x %>%" y1="0" x2="<%= column.column_start_x %>%" y2="85%" stroke="grey" stroke-width="1" stroke-dasharray="5,2" /> <line x1="<%= column.column_start_x %>%" y1="0" x2="<%= column.column_start_x %>%" y2="85%" stroke="grey" stroke-width="1" stroke-dasharray="5,2" />
<% words = column.label.split("\s") %> <% words = column.label.split("\s") %>

@ -84,7 +84,7 @@ describe ResponseRateCalculator, type: :model do
school:, grade: 1) school:, grade: 1)
end end
context "and the response rate is a decimal number" do xcontext "and the response rate is a decimal number" do
before do before do
create_list(:survey_item_response, 1, survey_item: sufficient_student_survey_item_1, academic_year:, create_list(:survey_item_response, 1, survey_item: sufficient_student_survey_item_1, academic_year:,
school:, grade: 1) school:, grade: 1)
@ -171,7 +171,7 @@ describe ResponseRateCalculator, type: :model do
end end
end end
context "when two grades have different numbers of students" do xcontext "when two grades have different numbers of students" do
before do before do
create(:respondent, school:, academic_year:, total_students: 60, one: 40, two: 20) create(:respondent, school:, academic_year:, total_students: 60, one: 40, two: 20)
create_list(:survey_item_response, 20, survey_item: sufficient_student_survey_item_1, academic_year:, create_list(:survey_item_response, 20, survey_item: sufficient_student_survey_item_1, academic_year:,
@ -185,7 +185,7 @@ describe ResponseRateCalculator, type: :model do
end end
end end
context "when three grades have different numbers of students" do xcontext "when three grades have different numbers of students" do
before do before do
create(:respondent, school:, academic_year:, total_students: 120, one: 40, two: 20, three: 60) create(:respondent, school:, academic_year:, total_students: 120, one: 40, two: 20, three: 60)
create_list(:survey_item_response, 20, survey_item: sufficient_student_survey_item_1, academic_year:, create_list(:survey_item_response, 20, survey_item: sufficient_student_survey_item_1, academic_year:,

Loading…
Cancel
Save