mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 21:48:16 -08:00
updating school_questions
This commit is contained in:
parent
db525ed2d3
commit
2a29b20804
1 changed files with 19 additions and 0 deletions
|
|
@ -10,4 +10,23 @@ class SchoolQuestion < ApplicationRecord
|
|||
|
||||
scope :for, -> (school, question) { where(school_id: school.id, question_id: question.id) }
|
||||
|
||||
def sync_attempts
|
||||
attempt_data = Attempt.
|
||||
joins(:question).
|
||||
created_in(school_category.year).
|
||||
for_question(question).
|
||||
for_school(school).
|
||||
select('count(attempts.answer_index) as response_count').
|
||||
select('sum(case when questions.reverse then 6 - attempts.answer_index else attempts.answer_index end) as answer_index_total')[0]
|
||||
|
||||
available_responders = school.available_responders_for(question)
|
||||
|
||||
update(
|
||||
attempt_count: available_responders,
|
||||
response_count: attempt_data.response_count,
|
||||
response_rate: attempt_data.response_count.to_f / available_responders.to_f,
|
||||
response_total: attempt_data.answer_index_total
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue