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/school_category.rb

28 lines
728 B

class SchoolCategory < ApplicationRecord
belongs_to :school
belongs_to :category
scope :for, -> (school, category) { where(school: school).where(category: category) }
def aggregated_responses
attempt_data = Attempt.
for_category(category).
for_school(school).
select('count(attempts.id) as attempt_count').
select('count(attempts.answer_index) as response_count').
select('sum(attempts.answer_index) as answer_index_total')[0]
return {
attempt_count: attempt_data.attempt_count,
response_count: attempt_data.response_count,
answer_index_total: attempt_data.answer_index_total
}
end
def aggregate_responses
return if ENV['BULK_PROCESS']
end
end