mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 21:48:16 -08:00
Add counter caches
This commit is contained in:
parent
c03615cb43
commit
a6ad132c81
21 changed files with 141 additions and 34 deletions
|
|
@ -1,5 +1,5 @@
|
|||
class Measure < ActiveRecord::Base
|
||||
belongs_to :subcategory
|
||||
belongs_to :subcategory, counter_cache: true
|
||||
has_one :category, through: :subcategory
|
||||
has_many :scales
|
||||
has_many :admin_data_items, through: :scales
|
||||
|
|
@ -203,14 +203,23 @@ class Measure < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def sufficient_student_data?(school:, academic_year:)
|
||||
return false unless includes_student_survey_items?
|
||||
return @sufficient_student_data ||= false unless includes_student_survey_items?
|
||||
return @sufficient_student_data ||= false if student_survey_items_by_survey_type(school:,
|
||||
academic_year:).all? do |survey_item|
|
||||
survey_item.survey_item_responses.where(school:,
|
||||
academic_year:).none?
|
||||
end
|
||||
|
||||
@sufficient_student_data ||= subcategory.response_rate(school:, academic_year:).meets_student_threshold
|
||||
@sufficient_student_data ||= subcategory.response_rate(school:, academic_year:).meets_student_threshold?
|
||||
end
|
||||
|
||||
def sufficient_teacher_data?(school:, academic_year:)
|
||||
return false unless includes_teacher_survey_items?
|
||||
return @sufficient_teacher_data ||= false unless includes_teacher_survey_items?
|
||||
return @sufficient_teacher_data ||= false if teacher_survey_items.all? do |survey_item|
|
||||
survey_item.survey_item_responses.where(school:,
|
||||
academic_year:).none?
|
||||
end
|
||||
|
||||
@sufficient_teacher_data ||= subcategory.response_rate(school:, academic_year:).meets_teacher_threshold
|
||||
@sufficient_teacher_data ||= subcategory.response_rate(school:, academic_year:).meets_teacher_threshold?
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
class Scale < ApplicationRecord
|
||||
belongs_to :measure
|
||||
belongs_to :measure, counter_cache: true
|
||||
has_many :survey_items
|
||||
has_many :survey_item_responses, through: :survey_items
|
||||
has_many :admin_data_items
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
class Subcategory < ActiveRecord::Base
|
||||
belongs_to :category
|
||||
belongs_to :category, counter_cache: true
|
||||
|
||||
has_many :measures
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
class SurveyItem < ActiveRecord::Base
|
||||
belongs_to :scale
|
||||
belongs_to :scale, counter_cache: true
|
||||
has_one :measure, through: :scale
|
||||
has_one :subcategory, through: :measure
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ class SurveyItemResponse < ActiveRecord::Base
|
|||
|
||||
belongs_to :academic_year
|
||||
belongs_to :school
|
||||
belongs_to :survey_item
|
||||
belongs_to :survey_item, counter_cache: true
|
||||
has_one :measure, through: :survey_item
|
||||
|
||||
scope :exclude_boston, lambda {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue