mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 21:48:16 -08:00
fix: correctly memoize student_survey_items_with_sufficient_responses so that on the analyze page, when the first year has insufficient responses, it doesn't affect all subsequent years
This commit is contained in:
parent
3b3bb52523
commit
3f2aa63bfd
4 changed files with 32 additions and 20 deletions
|
|
@ -25,7 +25,8 @@ class Measure < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def student_survey_items_with_sufficient_responses(school:, academic_year:)
|
def student_survey_items_with_sufficient_responses(school:, academic_year:)
|
||||||
@student_survey_items_with_sufficient_responses ||= SurveyItem.where(id: SurveyItem.joins("inner join survey_item_responses on survey_item_responses.survey_item_id = survey_items.id")
|
@student_survey_items_with_sufficient_responses ||= Hash.new do |memo, (school, academic_year)|
|
||||||
|
memo[[school, academic_year]] = SurveyItem.where(id: SurveyItem.joins("inner join survey_item_responses on survey_item_responses.survey_item_id = survey_items.id")
|
||||||
.student_survey_items
|
.student_survey_items
|
||||||
.where("survey_item_responses.school": school,
|
.where("survey_item_responses.school": school,
|
||||||
"survey_item_responses.academic_year": academic_year,
|
"survey_item_responses.academic_year": academic_year,
|
||||||
|
|
@ -34,6 +35,8 @@ class Measure < ActiveRecord::Base
|
||||||
.group("survey_items.id")
|
.group("survey_items.id")
|
||||||
.having("count(*) >= 10")
|
.having("count(*) >= 10")
|
||||||
.count.keys)
|
.count.keys)
|
||||||
|
end
|
||||||
|
@student_survey_items_with_sufficient_responses[[school, academic_year]]
|
||||||
end
|
end
|
||||||
|
|
||||||
def teacher_scales
|
def teacher_scales
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,11 @@ module Analyze
|
||||||
def basis
|
def basis
|
||||||
"student surveys"
|
"student surveys"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def n_size(academic_year)
|
||||||
|
SurveyItemResponse.where(survey_item: measure.student_survey_items, school:, grade: grades,
|
||||||
|
academic_year:).select(:response_id).distinct.count
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,8 @@ module Analyze
|
||||||
end
|
end
|
||||||
|
|
||||||
def show_insufficient_data_message?
|
def show_insufficient_data_message?
|
||||||
scores = academic_years.map do |year|
|
scores = academic_years.map do |academic_year|
|
||||||
measure.score(school:, academic_year: year)
|
measure.student_score(school:, academic_year:)
|
||||||
end
|
end
|
||||||
|
|
||||||
scores.none? { |score| score.meets_student_threshold? }
|
scores.none? { |score| score.meets_student_threshold? }
|
||||||
|
|
@ -27,6 +27,11 @@ module Analyze
|
||||||
def type
|
def type
|
||||||
:student
|
:student
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def n_size(academic_year)
|
||||||
|
SurveyItemResponse.where(survey_item: measure.student_survey_items, school:, grade: grades,
|
||||||
|
academic_year:).select(:response_id).distinct.count
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -21,13 +21,13 @@ module Analyze
|
||||||
end
|
end
|
||||||
|
|
||||||
def bars
|
def bars
|
||||||
@bars ||= yearly_scores.map.each_with_index do |yearly_score, index|
|
@bars ||= academic_years.map.with_index do |academic_year, index|
|
||||||
year = yearly_score.year
|
Analyze::BarPresenter.new(measure:, academic_year:,
|
||||||
Analyze::BarPresenter.new(measure:, academic_year: year,
|
score: score(academic_year),
|
||||||
score: yearly_score.score,
|
|
||||||
x_position: bar_x(index),
|
x_position: bar_x(index),
|
||||||
color: bar_color(year))
|
color: bar_color(academic_year))
|
||||||
end.reject(&:blank?).select { |bar| bar.score.average&.positive? }
|
end.reject(&:blank?).select { |bar| bar.score.average&.positive? }
|
||||||
|
@bars
|
||||||
end
|
end
|
||||||
|
|
||||||
def label
|
def label
|
||||||
|
|
@ -46,6 +46,10 @@ module Analyze
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def n_size(academic_year)
|
||||||
|
raise NotImplementedError
|
||||||
|
end
|
||||||
|
|
||||||
def basis
|
def basis
|
||||||
"student surveys"
|
"student surveys"
|
||||||
end
|
end
|
||||||
|
|
@ -107,11 +111,6 @@ module Analyze
|
||||||
%i[student teacher].include? type
|
%i[student teacher].include? type
|
||||||
end
|
end
|
||||||
|
|
||||||
def n_size(academic_year)
|
|
||||||
SurveyItemResponse.where(survey_item: measure.student_survey_items, school:, grade: grades,
|
|
||||||
academic_year:).select(:response_id).distinct.count
|
|
||||||
end
|
|
||||||
|
|
||||||
def popover_content(academic_year)
|
def popover_content(academic_year)
|
||||||
"#{n_size(academic_year)} #{type.to_s.capitalize}s"
|
"#{n_size(academic_year)} #{type.to_s.capitalize}s"
|
||||||
end
|
end
|
||||||
|
|
@ -126,12 +125,12 @@ module Analyze
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
YearlyScore = Struct.new(:year, :score)
|
# YearlyScore = Struct.new(:year, :score)
|
||||||
def yearly_scores
|
# def yearly_scores
|
||||||
yearly_scores = academic_years.each.map do |year|
|
# @yearly_scores ||= academic_years.each.map do |year|
|
||||||
YearlyScore.new(year, score(year))
|
# YearlyScore.new(year, score(year))
|
||||||
end.reject { |year| year.score.nil? || year.score.blank? }
|
# end.reject { |year| year.score.nil? || year.score.blank? }
|
||||||
end
|
# end
|
||||||
|
|
||||||
def bar_color(year)
|
def bar_color(year)
|
||||||
@available_academic_years ||= AcademicYear.order(:range).all
|
@available_academic_years ||= AcademicYear.order(:range).all
|
||||||
|
|
@ -140,7 +139,7 @@ module Analyze
|
||||||
|
|
||||||
def bar_x(index)
|
def bar_x(index)
|
||||||
column_start_x + (index * bar_width * 1.2) +
|
column_start_x + (index * bar_width * 1.2) +
|
||||||
((column_end_x - column_start_x) - (yearly_scores.size * bar_width * 1.2)) / 2
|
((column_end_x - column_start_x) - (academic_years.size * bar_width * 1.2)) / 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue