You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sqm-dashboards/app/models/survey_response_aggregator.rb

17 lines
415 B

class Array
def average
self.sum.to_f / self.size
end
end
class SurveyResponseAggregator
def self.score(academic_year:, school:, measure:)
SurveyItemResponse
.where(academic_year: academic_year)
.where(school: school)
.filter { |survey_response| survey_response.survey_item.measure == measure }
.map { |survey_response| survey_response.likert_score }
.average
end
end