mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-08 23:18:18 -07:00
working on displaying data
This commit is contained in:
parent
8c389742ee
commit
74ff33d74e
11 changed files with 204 additions and 9 deletions
|
|
@ -3,7 +3,28 @@ class Category < ApplicationRecord
|
|||
has_many :questions
|
||||
belongs_to :parent_category, class_name: 'Category', foreign_key: :parent_category_id
|
||||
has_many :child_categories, class_name: 'Category', foreign_key: :parent_category_id
|
||||
has_many :school_categories
|
||||
|
||||
validates :name, presence: true
|
||||
|
||||
scope :for_parent, -> (category=nil) { where(parent_category_id: category.try(:id)) }
|
||||
|
||||
def root_identifier
|
||||
p = self
|
||||
while p.parent_category.present?
|
||||
p = p.parent_category
|
||||
end
|
||||
p.name.downcase.gsub(/\s/, '-')
|
||||
end
|
||||
|
||||
def root_index
|
||||
[
|
||||
"teachers-and-the-teaching-environment",
|
||||
"school-culture",
|
||||
"resources",
|
||||
"indicators-of-academic-learning",
|
||||
"character-and-wellbeing-outcomes"
|
||||
].index(root_identifier)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ class School < ApplicationRecord
|
|||
has_many :recipient_lists
|
||||
belongs_to :district
|
||||
has_many :recipients
|
||||
has_many :school_categories
|
||||
|
||||
validates :name, presence: true
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,11 @@ class SchoolCategory < ApplicationRecord
|
|||
validates_associated :category
|
||||
|
||||
scope :for, -> (school, category) { where(school: school).where(category: category) }
|
||||
scope :for_parent_category, -> (category=nil) { joins(:category).merge(Category.for_parent(category)) }
|
||||
|
||||
def answer_index_average
|
||||
answer_index_total.to_f / response_count.to_f
|
||||
end
|
||||
|
||||
def aggregated_responses
|
||||
attempt_data = Attempt.
|
||||
|
|
@ -47,7 +52,11 @@ class SchoolCategory < ApplicationRecord
|
|||
return if ENV['BULK_PROCESS']
|
||||
update_attributes(chained_aggregated_responses)
|
||||
if category.parent_category.present?
|
||||
SchoolCategory.for(school, category.parent_category).each { |sc| sc.sync_aggregated_responses }
|
||||
parent_school_category = SchoolCategory.for(school, category.parent_category).first
|
||||
if parent_school_category.nil?
|
||||
parent_school_category = SchoolCategory.create(school: school, category: category.parent_category)
|
||||
end
|
||||
parent_school_category.sync_aggregated_responses
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue