mirror of
https://github.com/edcommonwealth/Dashboard.git
synced 2026-03-16 17:45:53 -07:00
dirty commit: can't get references to work correctly between any tables
This commit is contained in:
parent
e1f0b78236
commit
a4fddbeced
183 changed files with 5461 additions and 5 deletions
51
app/models/dashboard/response_rate_calculator.rb
Normal file
51
app/models/dashboard/response_rate_calculator.rb
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Dashboard
|
||||
class ResponseRateCalculator
|
||||
TEACHER_RATE_THRESHOLD = 25
|
||||
STUDENT_RATE_THRESHOLD = 25
|
||||
attr_reader :subcategory, :school, :academic_year
|
||||
|
||||
def initialize(subcategory:, school:, academic_year:)
|
||||
@subcategory = subcategory
|
||||
@school = school
|
||||
@academic_year = academic_year
|
||||
end
|
||||
|
||||
def rate
|
||||
return 100 if population_data_unavailable?
|
||||
|
||||
return 0 unless survey_items_have_sufficient_responses?
|
||||
|
||||
return 0 unless total_possible_responses.positive?
|
||||
|
||||
cap_at_one_hundred(raw_response_rate).round
|
||||
end
|
||||
|
||||
def meets_student_threshold?
|
||||
rate >= STUDENT_RATE_THRESHOLD
|
||||
end
|
||||
|
||||
def meets_teacher_threshold?
|
||||
rate >= TEACHER_RATE_THRESHOLD
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def cap_at_one_hundred(response_rate)
|
||||
response_rate > 100 ? 100 : response_rate
|
||||
end
|
||||
|
||||
def average_responses_per_survey_item
|
||||
response_count / survey_item_count.to_f
|
||||
end
|
||||
|
||||
def respondents
|
||||
@respondents ||= Respondent.by_school_and_year(school:, academic_year:)
|
||||
end
|
||||
|
||||
def population_data_unavailable?
|
||||
@population_data_unavailable ||= respondents.nil?
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue