mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-13 01:10:39 -07:00
working on aggregating results
This commit is contained in:
parent
5d36ab0a62
commit
8c389742ee
7 changed files with 44 additions and 15 deletions
|
|
@ -33,7 +33,7 @@ class Attempt < ApplicationRecord
|
|||
if school_category.nil?
|
||||
school_category = SchoolCategory.create(school: recipient.school, category: question.category)
|
||||
end
|
||||
# school_category.aggregate_responses
|
||||
school_category.sync_aggregated_responses
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ class SchoolCategory < ApplicationRecord
|
|||
belongs_to :school
|
||||
belongs_to :category
|
||||
|
||||
validates_associated :school
|
||||
validates_associated :category
|
||||
|
||||
scope :for, -> (school, category) { where(school: school).where(category: category) }
|
||||
|
||||
def aggregated_responses
|
||||
|
|
@ -14,9 +17,9 @@ class SchoolCategory < ApplicationRecord
|
|||
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
|
||||
attempt_count: attempt_data.attempt_count || 0,
|
||||
response_count: attempt_data.response_count || 0,
|
||||
answer_index_total: attempt_data.answer_index_total || 0
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue