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_item.rb

26 lines
655 B

class SurveyItem < ActiveRecord::Base
belongs_to :scale
has_one :measure, through: :scale
has_one :subcategory, through: :measure
has_many :survey_item_responses
def score(school:, academic_year:)
@score ||= Hash.new do |memo|
memo[[school, academic_year]] = survey_item_responses.where(school:, academic_year:).average(:likert_score).to_f
end
@score[[school, academic_year]]
end
scope :student_survey_items, lambda {
where("survey_item_id LIKE 's-%'")
}
scope :teacher_survey_items, lambda {
where("survey_item_id LIKE 't-%'")
}
scope :short_form_items, lambda {
where(on_short_form: true)
}
end