diff --git a/app/controllers/dashboard/categories_controller.rb b/app/controllers/dashboard/categories_controller.rb index ba9d5da..a87e8cd 100644 --- a/app/controllers/dashboard/categories_controller.rb +++ b/app/controllers/dashboard/categories_controller.rb @@ -7,7 +7,6 @@ module Dashboard def show @categories = Category.sorted.map { |category| CategoryPresenter.new(category:) } - puts params @category = CategoryPresenter.new(category: Category.find_by_slug(params[:id])) end end diff --git a/app/helpers/dashboard/analyze_helper.rb b/app/helpers/dashboard/analyze_helper.rb index 17f8e50..5aff130 100644 --- a/app/helpers/dashboard/analyze_helper.rb +++ b/app/helpers/dashboard/analyze_helper.rb @@ -45,7 +45,7 @@ module Dashboard @empty_dataset ||= Hash.new do |memo, (school, academic_year)| memo[[school, academic_year]] = measures.none? do |measure| response_rate = measure.subcategory.response_rate(school:, academic_year:) - response_rate.meets_student_threshold || response_rate.meets_teacher_threshold || measure.sufficient_admin_data?(school:, academic_year:) + response_rate.meets_student_threshold? || response_rate.meets_teacher_threshold? || measure.sufficient_admin_data?(school:, academic_year:) end end @@ -56,7 +56,7 @@ module Dashboard @empty_survey_dataset ||= Hash.new do |memo, (school, academic_year)| memo[[school, academic_year]] = measures.none? do |measure| response_rate = measure.subcategory.response_rate(school:, academic_year:) - response_rate.meets_student_threshold || response_rate.meets_teacher_threshold + response_rate.meets_student_threshold? || response_rate.meets_teacher_threshold? end end @empty_survey_dataset[[school, academic_year]] diff --git a/app/helpers/dashboard/header_helper.rb b/app/helpers/dashboard/header_helper.rb index 324ff58..d9f7834 100644 --- a/app/helpers/dashboard/header_helper.rb +++ b/app/helpers/dashboard/header_helper.rb @@ -3,16 +3,16 @@ module Dashboard module HeaderHelper def link_to_overview(district:, school:, academic_year:) - "/districts/#{district.slug}/schools/#{school.slug}/overview?year=#{academic_year.range}" + district_school_overview_index_path(district, school, year: academic_year.range) end def link_to_browse(district:, school:, academic_year:) - "/districts/#{district.slug}/schools/#{school.slug}/browse/teachers-leadership?year=#{academic_year.range}" + district_school_category_path(district, school, { year: academic_year.range, id: "teachers-leadership" }) end def link_to_analyze(district:, school:, academic_year:) year = academic_year.range - "/districts/#{district.slug}/schools/#{school.slug}/analyze?year=#{year}&category=1&academic_years=#{year}" + district_school_analyze_index_path(district, school, { year:, category: 1, academic_years: year }) end def district_url_for(district:, academic_year:) diff --git a/app/presenters/dashboard/analyze/bar_presenter.rb b/app/presenters/dashboard/analyze/bar_presenter.rb index 7dc9bdc..60d93ee 100644 --- a/app/presenters/dashboard/analyze/bar_presenter.rb +++ b/app/presenters/dashboard/analyze/bar_presenter.rb @@ -1,85 +1,87 @@ # frozen_string_literal: true -module Analyze - class BarPresenter - include AnalyzeHelper - attr_reader :score, :x_position, :academic_year, :measure_id, :measure, :color +module Dashboard + module Analyze + class BarPresenter + include AnalyzeHelper + attr_reader :score, :x_position, :academic_year, :measure_id, :measure, :color - MINIMUM_BAR_HEIGHT = 2 + MINIMUM_BAR_HEIGHT = 2 - def initialize(measure:, academic_year:, score:, x_position:, color:) - @score = score - @x_position = x_position - @academic_year = academic_year - @measure = measure - @measure_id = measure.measure_id - @color = color - end - - def y_offset - benchmark_height = analyze_zone_height * 2 - case zone.type - when :ideal, :approval - benchmark_height - bar_height_percentage - else - benchmark_height + def initialize(measure:, academic_year:, score:, x_position:, color:) + @score = score + @x_position = x_position + @academic_year = academic_year + @measure = measure + @measure_id = measure.measure_id + @color = color end - end - def bar_color - "fill-#{zone.type}" - end + def y_offset + benchmark_height = analyze_zone_height * 2 + case zone.type + when :ideal, :approval + benchmark_height - bar_height_percentage + else + benchmark_height + end + end - def bar_height_percentage - bar_height = send("#{zone.type}_bar_height_percentage") || 0 - enforce_minimum_height(bar_height:) - end + def bar_color + "fill-#{zone.type}" + end - def percentage - low_benchmark = zone.low_benchmark - (score.average - low_benchmark) / (zone.high_benchmark - low_benchmark) - end + def bar_height_percentage + bar_height = send("#{zone.type}_bar_height_percentage") || 0 + enforce_minimum_height(bar_height:) + end - def zone - zones = Zones.new( - watch_low_benchmark: measure.watch_low_benchmark, - growth_low_benchmark: measure.growth_low_benchmark, - approval_low_benchmark: measure.approval_low_benchmark, - ideal_low_benchmark: measure.ideal_low_benchmark - ) - zones.zone_for_score(score.average) - end + def percentage + low_benchmark = zone.low_benchmark + (score.average - low_benchmark) / (zone.high_benchmark - low_benchmark) + end - def average - average = score.average || 0 + def zone + zones = Zones.new( + watch_low_benchmark: measure.watch_low_benchmark, + growth_low_benchmark: measure.growth_low_benchmark, + approval_low_benchmark: measure.approval_low_benchmark, + ideal_low_benchmark: measure.ideal_low_benchmark + ) + zones.zone_for_score(score.average) + end - average.round(6) - end + def average + average = score.average || 0 - private + average.round(6) + end - def enforce_minimum_height(bar_height:) - bar_height < MINIMUM_BAR_HEIGHT ? MINIMUM_BAR_HEIGHT : bar_height - end + private - def ideal_bar_height_percentage - (percentage * zone_height_percentage + zone_height_percentage) * 100 - end + def enforce_minimum_height(bar_height:) + bar_height < MINIMUM_BAR_HEIGHT ? MINIMUM_BAR_HEIGHT : bar_height + end - def approval_bar_height_percentage - (percentage * zone_height_percentage) * 100 - end + def ideal_bar_height_percentage + (percentage * zone_height_percentage + zone_height_percentage) * 100 + end - def growth_bar_height_percentage - ((1 - percentage) * zone_height_percentage) * 100 - end + def approval_bar_height_percentage + (percentage * zone_height_percentage) * 100 + end - def watch_bar_height_percentage - ((1 - percentage) * zone_height_percentage + zone_height_percentage) * 100 - end + def growth_bar_height_percentage + ((1 - percentage) * zone_height_percentage) * 100 + end - def warning_bar_height_percentage - ((1 - percentage) * zone_height_percentage + zone_height_percentage + zone_height_percentage) * 100 + def watch_bar_height_percentage + ((1 - percentage) * zone_height_percentage + zone_height_percentage) * 100 + end + + def warning_bar_height_percentage + ((1 - percentage) * zone_height_percentage + zone_height_percentage + zone_height_percentage) * 100 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/all_data.rb b/app/presenters/dashboard/analyze/graph/all_data.rb index 3d6e738..cf66f3e 100644 --- a/app/presenters/dashboard/analyze/graph/all_data.rb +++ b/app/presenters/dashboard/analyze/graph/all_data.rb @@ -1,19 +1,21 @@ # frozen_string_literal: true -module Analyze - module Graph - class AllData - include Analyze::Graph::Column - def to_s - "All Data" - end +module Dashboard + module Analyze + module Graph + class AllData + include Analyze::Graph::Column + def to_s + "All Data" + end - def slug - "all-data" - end + def slug + "all-data" + end - def columns - [AllStudent, AllTeacher, AllAdmin, GroupedBarColumnPresenter] + def columns + [AllStudent, AllTeacher, AllAdmin, GroupedBarColumnPresenter] + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/all_admin.rb b/app/presenters/dashboard/analyze/graph/column/all_admin.rb index d63c927..2753453 100644 --- a/app/presenters/dashboard/analyze/graph/column/all_admin.rb +++ b/app/presenters/dashboard/analyze/graph/column/all_admin.rb @@ -1,37 +1,39 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - class AllAdmin < GroupedBarColumnPresenter - def label - %w[All Admin] - end - - def basis - "admin data" - end - - def show_irrelevancy_message? - !measure.includes_admin_data_items? - end - - def show_insufficient_data_message? - !academic_years.any? do |year| - measure.sufficient_admin_data?(school:, academic_year: year) +module Dashboard + module Analyze + module Graph + module Column + class AllAdmin < GroupedBarColumnPresenter + def label + %w[All Admin] end - end - def insufficiency_message - ["data not", "available"] - end + def basis + "admin data" + end - def score(year_index) - measure.admin_score(school:, academic_year: academic_years[year_index]) - end + def show_irrelevancy_message? + !measure.includes_admin_data_items? + end - def type - :admin + def show_insufficient_data_message? + !academic_years.any? do |year| + measure.sufficient_admin_data?(school:, academic_year: year) + end + end + + def insufficiency_message + ["data not", "available"] + end + + def score(year_index) + measure.admin_score(school:, academic_year: academic_years[year_index]) + end + + def type + :admin + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/all_student.rb b/app/presenters/dashboard/analyze/graph/column/all_student.rb index 788dca3..ccb107d 100644 --- a/app/presenters/dashboard/analyze/graph/column/all_student.rb +++ b/app/presenters/dashboard/analyze/graph/column/all_student.rb @@ -1,31 +1,33 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - class AllStudent < GroupedBarColumnPresenter - def label - %w[All Students] - end - - def show_irrelevancy_message? - !measure.includes_student_survey_items? - end - - def show_insufficient_data_message? - scores = academic_years.map do |year| - measure.score(school:, academic_year: year) +module Dashboard + module Analyze + module Graph + module Column + class AllStudent < GroupedBarColumnPresenter + def label + %w[All Students] end - scores.all? { |score| !score.meets_student_threshold? } - end + def show_irrelevancy_message? + !measure.includes_student_survey_items? + end - def score(year_index) - measure.student_score(school:, academic_year: academic_years[year_index]) - end + def show_insufficient_data_message? + scores = academic_years.map do |year| + measure.score(school:, academic_year: year) + end - def type - :student + scores.all? { |score| !score.meets_student_threshold? } + end + + def score(year_index) + measure.student_score(school:, academic_year: academic_years[year_index]) + end + + def type + :student + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/all_survey_data.rb b/app/presenters/dashboard/analyze/graph/column/all_survey_data.rb index c3e42c9..8f77db1 100644 --- a/app/presenters/dashboard/analyze/graph/column/all_survey_data.rb +++ b/app/presenters/dashboard/analyze/graph/column/all_survey_data.rb @@ -1,45 +1,47 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - class AllSurveyData < GroupedBarColumnPresenter - def label - %w[Survey Data] - end - - def show_irrelevancy_message? - false - end - - def show_insufficient_data_message? - scores = academic_years.map do |year| - combined_score(school:, academic_year: year) +module Dashboard + module Analyze + module Graph + module Column + class AllSurveyData < GroupedBarColumnPresenter + def label + %w[Survey Data] end - scores.all? { |score| !score.meets_student_threshold? && !score.meets_teacher_threshold? } - end + def show_irrelevancy_message? + false + end - def score(year_index) - combined_score(school:, academic_year: academic_years[year_index]) - end + def show_insufficient_data_message? + scores = academic_years.map do |year| + combined_score(school:, academic_year: year) + end - def type - :all_survey_data - end + scores.all? { |score| !score.meets_student_threshold? && !score.meets_teacher_threshold? } + end - private + def score(year_index) + combined_score(school:, academic_year: academic_years[year_index]) + end - def combined_score(school:, academic_year:) - teacher_score = measure.teacher_score(school:, academic_year:) - student_score = measure.student_score(school:, academic_year:) + def type + :all_survey_data + end - averages = [] - averages << student_score.average unless student_score.average.nil? - averages << teacher_score.average unless teacher_score.average.nil? - average = averages.average if averages.length > 0 - combined_score = Score.new(average:, meets_student_threshold: student_score.meets_student_threshold, - meets_teacher_threshold: teacher_score.meets_teacher_threshold) + private + + def combined_score(school:, academic_year:) + teacher_score = measure.teacher_score(school:, academic_year:) + student_score = measure.student_score(school:, academic_year:) + + averages = [] + averages << student_score.average unless student_score.average.nil? + averages << teacher_score.average unless teacher_score.average.nil? + average = averages.average if averages.length > 0 + combined_score = Score.new(average:, meets_student_threshold: student_score.meets_student_threshold, + meets_teacher_threshold: teacher_score.meets_teacher_threshold) + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/all_teacher.rb b/app/presenters/dashboard/analyze/graph/column/all_teacher.rb index dc3a844..fd0105a 100644 --- a/app/presenters/dashboard/analyze/graph/column/all_teacher.rb +++ b/app/presenters/dashboard/analyze/graph/column/all_teacher.rb @@ -1,40 +1,42 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - class AllTeacher < GroupedBarColumnPresenter - def label - %w[All Teachers] - end - - def basis - "teacher surveys" - end - - def show_irrelevancy_message? - !measure.includes_teacher_survey_items? - end - - def show_insufficient_data_message? - scores = academic_years.map do |year| - measure.score(school:, academic_year: year) +module Dashboard + module Analyze + module Graph + module Column + class AllTeacher < GroupedBarColumnPresenter + def label + %w[All Teachers] end - scores.all? { |score| !score.meets_teacher_threshold? } - end + def basis + "teacher surveys" + end - def score(year_index) - measure.teacher_score(school:, academic_year: academic_years[year_index]) - end + def show_irrelevancy_message? + !measure.includes_teacher_survey_items? + end - def type - :teacher - end + def show_insufficient_data_message? + scores = academic_years.map do |year| + measure.score(school:, academic_year: year) + end - def n_size(year_index) - SurveyItemResponse.where(survey_item: measure.teacher_survey_items, school:, - academic_year: academic_years[year_index]).select(:response_id).distinct.count + scores.all? { |score| !score.meets_teacher_threshold? } + end + + def score(year_index) + measure.teacher_score(school:, academic_year: academic_years[year_index]) + end + + def type + :teacher + end + + def n_size(year_index) + SurveyItemResponse.where(survey_item: measure.teacher_survey_items, school:, + academic_year: academic_years[year_index]).select(:response_id).distinct.count + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/ell_column/ell.rb b/app/presenters/dashboard/analyze/graph/column/ell_column/ell.rb index cba0740..f965cd8 100644 --- a/app/presenters/dashboard/analyze/graph/column/ell_column/ell.rb +++ b/app/presenters/dashboard/analyze/graph/column/ell_column/ell.rb @@ -1,30 +1,32 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module EllColumn - class Ell < GroupedBarColumnPresenter - include Analyze::Graph::Column::EllColumn::ScoreForEll - include Analyze::Graph::Column::EllColumn::EllCount - def label - %w[ELL] - end +module Dashboard + module Analyze + module Graph + module Column + module EllColumn + class Ell < GroupedBarColumnPresenter + include Analyze::Graph::Column::EllColumn::ScoreForEll + include Analyze::Graph::Column::EllColumn::EllCount + def label + %w[ELL] + end - def basis - "student" - end + def basis + "student" + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def ell - ::Ell.find_by_slug "ell" + def ell + ::Ell.find_by_slug "ell" + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/ell_column/ell_count.rb b/app/presenters/dashboard/analyze/graph/column/ell_column/ell_count.rb index fa20518..5a70519 100644 --- a/app/presenters/dashboard/analyze/graph/column/ell_column/ell_count.rb +++ b/app/presenters/dashboard/analyze/graph/column/ell_column/ell_count.rb @@ -1,15 +1,19 @@ -module Analyze - module Graph - module Column - module EllColumn - module EllCount - def type - :student - end +# frozen_string_literal: true - def n_size(year_index) - SurveyItemResponse.where(ell:, survey_item: measure.student_survey_items, school:, grade: grades(year_index), - academic_year: academic_years[year_index]).select(:response_id).distinct.count +module Dashboard + module Analyze + module Graph + module Column + module EllColumn + module EllCount + def type + :student + end + + def n_size(year_index) + SurveyItemResponse.where(ell:, survey_item: measure.student_survey_items, school:, grade: grades(year_index), + academic_year: academic_years[year_index]).select(:response_id).distinct.count + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/ell_column/not_ell.rb b/app/presenters/dashboard/analyze/graph/column/ell_column/not_ell.rb index 1c3ca59..de3085b 100644 --- a/app/presenters/dashboard/analyze/graph/column/ell_column/not_ell.rb +++ b/app/presenters/dashboard/analyze/graph/column/ell_column/not_ell.rb @@ -1,30 +1,32 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module EllColumn - class NotEll < GroupedBarColumnPresenter - include Analyze::Graph::Column::EllColumn::ScoreForEll - include Analyze::Graph::Column::EllColumn::EllCount - def label - ["Not ELL"] - end +module Dashboard + module Analyze + module Graph + module Column + module EllColumn + class NotEll < GroupedBarColumnPresenter + include Analyze::Graph::Column::EllColumn::ScoreForEll + include Analyze::Graph::Column::EllColumn::EllCount + def label + ["Not ELL"] + end - def basis - "student" - end + def basis + "student" + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def ell - ::Ell.find_by_slug "not-ell" + def ell + Ell.find_by_slug "not-ell" + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/ell_column/score_for_ell.rb b/app/presenters/dashboard/analyze/graph/column/ell_column/score_for_ell.rb index cd39cd0..6d8d792 100644 --- a/app/presenters/dashboard/analyze/graph/column/ell_column/score_for_ell.rb +++ b/app/presenters/dashboard/analyze/graph/column/ell_column/score_for_ell.rb @@ -1,38 +1,42 @@ -module Analyze - module Graph - module Column - module EllColumn - module ScoreForEll - def score(year_index) - academic_year = academic_years[year_index] - meets_student_threshold = sufficient_student_responses?(academic_year:) - return Score::NIL_SCORE unless meets_student_threshold +# frozen_string_literal: true - averages = SurveyItemResponse.averages_for_ell(measure.student_survey_items, school, academic_year, - ell) - average = bubble_up_averages(averages:).round(2) +module Dashboard + module Analyze + module Graph + module Column + module EllColumn + module ScoreForEll + def score(year_index) + academic_year = academic_years[year_index] + meets_student_threshold = sufficient_student_responses?(academic_year:) + return Score::NIL_SCORE unless meets_student_threshold - Score.new(average:, - meets_teacher_threshold: false, - meets_student_threshold:, - meets_admin_data_threshold: false) - end + averages = SurveyItemResponse.averages_for_ell(measure.student_survey_items, school, academic_year, + ell) + average = bubble_up_averages(averages:).round(2) - def bubble_up_averages(averages:) - measure.student_scales.map do |scale| - scale.survey_items.map do |survey_item| - averages[survey_item] + Score.new(average:, + meets_teacher_threshold: false, + meets_student_threshold:, + meets_admin_data_threshold: false) + end + + def bubble_up_averages(averages:) + measure.student_scales.map do |scale| + scale.survey_items.map do |survey_item| + averages[survey_item] + end.remove_blanks.average end.remove_blanks.average - end.remove_blanks.average - end + end - def sufficient_student_responses?(academic_year:) - return false unless measure.subcategory.response_rate(school:, academic_year:).meets_student_threshold? + def sufficient_student_responses?(academic_year:) + return false unless measure.subcategory.response_rate(school:, academic_year:).meets_student_threshold? - yearly_counts = SurveyItemResponse.where(school:, academic_year:, - ell:, survey_item: measure.student_survey_items).group(:ell).select(:response_id).distinct(:response_id).count - yearly_counts.any? do |count| - count[1] >= 10 + yearly_counts = SurveyItemResponse.where(school:, academic_year:, + ell:, survey_item: measure.student_survey_items).group(:ell).select(:response_id).distinct(:response_id).count + yearly_counts.any? do |count| + count[1] >= 10 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/ell_column/unknown.rb b/app/presenters/dashboard/analyze/graph/column/ell_column/unknown.rb index 37f077a..957e382 100644 --- a/app/presenters/dashboard/analyze/graph/column/ell_column/unknown.rb +++ b/app/presenters/dashboard/analyze/graph/column/ell_column/unknown.rb @@ -1,30 +1,32 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module EllColumn - class Unknown < GroupedBarColumnPresenter - include Analyze::Graph::Column::EllColumn::ScoreForEll - include Analyze::Graph::Column::EllColumn::EllCount - def label - %w[Unknown] - end +module Dashboard + module Analyze + module Graph + module Column + module EllColumn + class Unknown < GroupedBarColumnPresenter + include Analyze::Graph::Column::EllColumn::ScoreForEll + include Analyze::Graph::Column::EllColumn::EllCount + def label + %w[Unknown] + end - def basis - "student" - end + def basis + "student" + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def ell - ::Ell.find_by_slug "unknown" + def ell + Ell.find_by_slug "unknown" + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/gender_column/female.rb b/app/presenters/dashboard/analyze/graph/column/gender_column/female.rb index 54941fb..b85417f 100644 --- a/app/presenters/dashboard/analyze/graph/column/gender_column/female.rb +++ b/app/presenters/dashboard/analyze/graph/column/gender_column/female.rb @@ -1,30 +1,32 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module GenderColumn - class Female < GroupedBarColumnPresenter - include Analyze::Graph::Column::GenderColumn::ScoreForGender - include Analyze::Graph::Column::GenderColumn::GenderCount - def label - %w[Female] - end +module Dashboard + module Analyze + module Graph + module Column + module GenderColumn + class Female < GroupedBarColumnPresenter + include Analyze::Graph::Column::GenderColumn::ScoreForGender + include Analyze::Graph::Column::GenderColumn::GenderCount + def label + %w[Female] + end - def basis - "student" - end + def basis + "student" + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def gender - ::Gender.find_by_qualtrics_code 1 + def gender + ::Gender.find_by_qualtrics_code 1 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/gender_column/gender_count.rb b/app/presenters/dashboard/analyze/graph/column/gender_column/gender_count.rb index 9746024..82218b0 100644 --- a/app/presenters/dashboard/analyze/graph/column/gender_column/gender_count.rb +++ b/app/presenters/dashboard/analyze/graph/column/gender_column/gender_count.rb @@ -1,15 +1,19 @@ -module Analyze - module Graph - module Column - module GenderColumn - module GenderCount - def type - :student - end +# frozen_string_literal: true - def n_size(year_index) - SurveyItemResponse.where(gender:, survey_item: measure.student_survey_items, school:, grade: grades(year_index), - academic_year: academic_years[year_index]).select(:response_id).distinct.count +module Dashboard + module Analyze + module Graph + module Column + module GenderColumn + module GenderCount + def type + :student + end + + def n_size(year_index) + SurveyItemResponse.where(gender:, survey_item: measure.student_survey_items, school:, grade: grades(year_index), + academic_year: academic_years[year_index]).select(:response_id).distinct.count + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/gender_column/male.rb b/app/presenters/dashboard/analyze/graph/column/gender_column/male.rb index 031b91e..00c7467 100644 --- a/app/presenters/dashboard/analyze/graph/column/gender_column/male.rb +++ b/app/presenters/dashboard/analyze/graph/column/gender_column/male.rb @@ -1,30 +1,32 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module GenderColumn - class Male < GroupedBarColumnPresenter - include Analyze::Graph::Column::GenderColumn::ScoreForGender - include Analyze::Graph::Column::GenderColumn::GenderCount - def label - %w[Male] - end +module Dashboard + module Analyze + module Graph + module Column + module GenderColumn + class Male < GroupedBarColumnPresenter + include Analyze::Graph::Column::GenderColumn::ScoreForGender + include Analyze::Graph::Column::GenderColumn::GenderCount + def label + %w[Male] + end - def basis - "student" - end + def basis + "student" + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def gender - ::Gender.find_by_qualtrics_code 2 + def gender + ::Gender.find_by_qualtrics_code 2 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/gender_column/non_binary.rb b/app/presenters/dashboard/analyze/graph/column/gender_column/non_binary.rb index 8b3c854..2c90d0d 100644 --- a/app/presenters/dashboard/analyze/graph/column/gender_column/non_binary.rb +++ b/app/presenters/dashboard/analyze/graph/column/gender_column/non_binary.rb @@ -1,30 +1,32 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module GenderColumn - class NonBinary < GroupedBarColumnPresenter - include Analyze::Graph::Column::GenderColumn::ScoreForGender - include Analyze::Graph::Column::GenderColumn::GenderCount - def label - %w[Non-Binary] - end +module Dashboard + module Analyze + module Graph + module Column + module GenderColumn + class NonBinary < GroupedBarColumnPresenter + include Analyze::Graph::Column::GenderColumn::ScoreForGender + include Analyze::Graph::Column::GenderColumn::GenderCount + def label + %w[Non-Binary] + end - def basis - "student" - end + def basis + "student" + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def gender - ::Gender.find_by_qualtrics_code 4 + def gender + ::Gender.find_by_qualtrics_code 4 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/gender_column/score_for_gender.rb b/app/presenters/dashboard/analyze/graph/column/gender_column/score_for_gender.rb index 2b5e22c..a52991b 100644 --- a/app/presenters/dashboard/analyze/graph/column/gender_column/score_for_gender.rb +++ b/app/presenters/dashboard/analyze/graph/column/gender_column/score_for_gender.rb @@ -1,38 +1,42 @@ -module Analyze - module Graph - module Column - module GenderColumn - module ScoreForGender - def score(year_index) - academic_year = academic_years[year_index] - meets_student_threshold = sufficient_student_responses?(academic_year:) - return Score::NIL_SCORE unless meets_student_threshold +# frozen_string_literal: true - averages = SurveyItemResponse.averages_for_gender(measure.student_survey_items, school, academic_year, - gender) - average = bubble_up_averages(averages:).round(2) +module Dashboard + module Analyze + module Graph + module Column + module GenderColumn + module ScoreForGender + def score(year_index) + academic_year = academic_years[year_index] + meets_student_threshold = sufficient_student_responses?(academic_year:) + return Score::NIL_SCORE unless meets_student_threshold - Score.new(average:, - meets_teacher_threshold: false, - meets_student_threshold:, - meets_admin_data_threshold: false) - end + averages = SurveyItemResponse.averages_for_gender(measure.student_survey_items, school, academic_year, + gender) + average = bubble_up_averages(averages:).round(2) - def bubble_up_averages(averages:) - measure.student_scales.map do |scale| - scale.survey_items.map do |survey_item| - averages[survey_item] + Score.new(average:, + meets_teacher_threshold: false, + meets_student_threshold:, + meets_admin_data_threshold: false) + end + + def bubble_up_averages(averages:) + measure.student_scales.map do |scale| + scale.survey_items.map do |survey_item| + averages[survey_item] + end.remove_blanks.average end.remove_blanks.average - end.remove_blanks.average - end + end - def sufficient_student_responses?(academic_year:) - return false unless measure.subcategory.response_rate(school:, academic_year:).meets_student_threshold? + def sufficient_student_responses?(academic_year:) + return false unless measure.subcategory.response_rate(school:, academic_year:).meets_student_threshold? - yearly_counts = SurveyItemResponse.where(school:, academic_year:, - gender:, survey_item: measure.student_survey_items).group(:gender).select(:response_id).distinct(:response_id).count - yearly_counts.any? do |count| - count[1] >= 10 + yearly_counts = SurveyItemResponse.where(school:, academic_year:, + gender:, survey_item: measure.student_survey_items).group(:gender).select(:response_id).distinct(:response_id).count + yearly_counts.any? do |count| + count[1] >= 10 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/gender_column/unknown.rb b/app/presenters/dashboard/analyze/graph/column/gender_column/unknown.rb index d954cec..f114950 100644 --- a/app/presenters/dashboard/analyze/graph/column/gender_column/unknown.rb +++ b/app/presenters/dashboard/analyze/graph/column/gender_column/unknown.rb @@ -1,30 +1,32 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module GenderColumn - class Unknown < GroupedBarColumnPresenter - include Analyze::Graph::Column::GenderColumn::ScoreForGender - include Analyze::Graph::Column::GenderColumn::GenderCount - def label - %w[Unknown] - end +module Dashboard + module Analyze + module Graph + module Column + module GenderColumn + class Unknown < GroupedBarColumnPresenter + include Analyze::Graph::Column::GenderColumn::ScoreForGender + include Analyze::Graph::Column::GenderColumn::GenderCount + def label + %w[Unknown] + end - def basis - "student" - end + def basis + "student" + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def gender - ::Gender.find_by_qualtrics_code 99 + def gender + ::Gender.find_by_qualtrics_code 99 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/grade/eight.rb b/app/presenters/dashboard/analyze/graph/column/grade/eight.rb index 8d4bf62..372a791 100644 --- a/app/presenters/dashboard/analyze/graph/column/grade/eight.rb +++ b/app/presenters/dashboard/analyze/graph/column/grade/eight.rb @@ -1,30 +1,32 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module Grade - class Eight < GroupedBarColumnPresenter - include Analyze::Graph::Column::Grade::ScoreForGrade - include Analyze::Graph::Column::Grade::GradeCount - def label - %w[Grade 8] - end +module Dashboard + module Analyze + module Graph + module Column + module Grade + class Eight < GroupedBarColumnPresenter + include Analyze::Graph::Column::Grade::ScoreForGrade + include Analyze::Graph::Column::Grade::GradeCount + def label + %w[Grade 8] + end - def basis - "student" - end + def basis + "student" + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def grade - 8 + def grade + 8 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/grade/eleven.rb b/app/presenters/dashboard/analyze/graph/column/grade/eleven.rb index dba1136..dd96302 100644 --- a/app/presenters/dashboard/analyze/graph/column/grade/eleven.rb +++ b/app/presenters/dashboard/analyze/graph/column/grade/eleven.rb @@ -1,30 +1,32 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module Grade - class Eleven < GroupedBarColumnPresenter - include Analyze::Graph::Column::Grade::ScoreForGrade - include Analyze::Graph::Column::Grade::GradeCount - def label - %w[Grade 11] - end +module Dashboard + module Analyze + module Graph + module Column + module Grade + class Eleven < GroupedBarColumnPresenter + include Analyze::Graph::Column::Grade::ScoreForGrade + include Analyze::Graph::Column::Grade::GradeCount + def label + %w[Grade 11] + end - def basis - "student" - end + def basis + "student" + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def grade - 11 + def grade + 11 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/grade/five.rb b/app/presenters/dashboard/analyze/graph/column/grade/five.rb index 30033e3..cc8bc91 100644 --- a/app/presenters/dashboard/analyze/graph/column/grade/five.rb +++ b/app/presenters/dashboard/analyze/graph/column/grade/five.rb @@ -1,30 +1,32 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module Grade - class Five < GroupedBarColumnPresenter - include Analyze::Graph::Column::Grade::ScoreForGrade - include Analyze::Graph::Column::Grade::GradeCount - def label - %w[Grade 5] - end +module Dashboard + module Analyze + module Graph + module Column + module Grade + class Five < GroupedBarColumnPresenter + include Analyze::Graph::Column::Grade::ScoreForGrade + include Analyze::Graph::Column::Grade::GradeCount + def label + %w[Grade 5] + end - def basis - "student" - end + def basis + "student" + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def grade - 5 + def grade + 5 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/grade/four.rb b/app/presenters/dashboard/analyze/graph/column/grade/four.rb index 1f56374..84cd422 100644 --- a/app/presenters/dashboard/analyze/graph/column/grade/four.rb +++ b/app/presenters/dashboard/analyze/graph/column/grade/four.rb @@ -1,30 +1,32 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module Grade - class Four < GroupedBarColumnPresenter - include Analyze::Graph::Column::Grade::ScoreForGrade - include Analyze::Graph::Column::Grade::GradeCount - def label - %w[Grade 4] - end +module Dashboard + module Analyze + module Graph + module Column + module Grade + class Four < GroupedBarColumnPresenter + include Analyze::Graph::Column::Grade::ScoreForGrade + include Analyze::Graph::Column::Grade::GradeCount + def label + %w[Grade 4] + end - def basis - "student" - end + def basis + "student" + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def grade - 4 + def grade + 4 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/grade/grade_count.rb b/app/presenters/dashboard/analyze/graph/column/grade/grade_count.rb index 42ed3a2..adb248f 100644 --- a/app/presenters/dashboard/analyze/graph/column/grade/grade_count.rb +++ b/app/presenters/dashboard/analyze/graph/column/grade/grade_count.rb @@ -1,15 +1,19 @@ -module Analyze - module Graph - module Column - module Grade - module GradeCount - def type - :student - end +# frozen_string_literal: true - def n_size(year_index) - SurveyItemResponse.where(grade:, survey_item: measure.student_survey_items, school:, - academic_year: academic_years[year_index]).select(:response_id).distinct.count +module Dashboard + module Analyze + module Graph + module Column + module Grade + module GradeCount + def type + :student + end + + def n_size(year_index) + SurveyItemResponse.where(grade:, survey_item: measure.student_survey_items, school:, + academic_year: academic_years[year_index]).select(:response_id).distinct.count + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/grade/nine.rb b/app/presenters/dashboard/analyze/graph/column/grade/nine.rb index 9c3a939..50086c2 100644 --- a/app/presenters/dashboard/analyze/graph/column/grade/nine.rb +++ b/app/presenters/dashboard/analyze/graph/column/grade/nine.rb @@ -1,30 +1,32 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module Grade - class Nine < GroupedBarColumnPresenter - include Analyze::Graph::Column::Grade::ScoreForGrade - include Analyze::Graph::Column::Grade::GradeCount - def label - %w[Grade 9] - end +module Dashboard + module Analyze + module Graph + module Column + module Grade + class Nine < GroupedBarColumnPresenter + include Analyze::Graph::Column::Grade::ScoreForGrade + include Analyze::Graph::Column::Grade::GradeCount + def label + %w[Grade 9] + end - def basis - "student" - end + def basis + "student" + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def grade - 9 + def grade + 9 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/grade/one.rb b/app/presenters/dashboard/analyze/graph/column/grade/one.rb index b1e3bcd..a328764 100644 --- a/app/presenters/dashboard/analyze/graph/column/grade/one.rb +++ b/app/presenters/dashboard/analyze/graph/column/grade/one.rb @@ -1,30 +1,32 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module Grade - class One < GroupedBarColumnPresenter - include Analyze::Graph::Column::Grade::ScoreForGrade - include Analyze::Graph::Column::Grade::GradeCount - def label - %w[Grade 1] - end +module Dashboard + module Analyze + module Graph + module Column + module Grade + class One < GroupedBarColumnPresenter + include Analyze::Graph::Column::Grade::ScoreForGrade + include Analyze::Graph::Column::Grade::GradeCount + def label + %w[Grade 1] + end - def basis - "student" - end + def basis + "student" + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def grade - 1 + def grade + 1 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/grade/score_for_grade.rb b/app/presenters/dashboard/analyze/graph/column/grade/score_for_grade.rb index 812c9cb..5d25552 100644 --- a/app/presenters/dashboard/analyze/graph/column/grade/score_for_grade.rb +++ b/app/presenters/dashboard/analyze/graph/column/grade/score_for_grade.rb @@ -1,38 +1,42 @@ -module Analyze - module Graph - module Column - module Grade - module ScoreForGrade - def score(year_index) - academic_year = academic_years[year_index] - meets_student_threshold = sufficient_student_responses?(academic_year:) - return Score::NIL_SCORE unless meets_student_threshold +# frozen_string_literal: true - averages = SurveyItemResponse.averages_for_grade(measure.student_survey_items, school, - academic_year, grade) - average = bubble_up_averages(averages:).round(2) +module Dashboard + module Analyze + module Graph + module Column + module Grade + module ScoreForGrade + def score(year_index) + academic_year = academic_years[year_index] + meets_student_threshold = sufficient_student_responses?(academic_year:) + return Score::NIL_SCORE unless meets_student_threshold - Score.new(average:, - meets_teacher_threshold: false, - meets_student_threshold:, - meets_admin_data_threshold: false) - end + averages = SurveyItemResponse.averages_for_grade(measure.student_survey_items, school, + academic_year, grade) + average = bubble_up_averages(averages:).round(2) - def bubble_up_averages(averages:) - measure.student_scales.map do |scale| - scale.survey_items.map do |survey_item| - averages[survey_item] + Score.new(average:, + meets_teacher_threshold: false, + meets_student_threshold:, + meets_admin_data_threshold: false) + end + + def bubble_up_averages(averages:) + measure.student_scales.map do |scale| + scale.survey_items.map do |survey_item| + averages[survey_item] + end.remove_blanks.average end.remove_blanks.average - end.remove_blanks.average - end + end - def sufficient_student_responses?(academic_year:) - return false unless measure.subcategory.response_rate(school:, academic_year:).meets_student_threshold? + def sufficient_student_responses?(academic_year:) + return false unless measure.subcategory.response_rate(school:, academic_year:).meets_student_threshold? - yearly_counts = SurveyItemResponse.where(school:, academic_year:, - survey_item: measure.student_survey_items).group(:grade).select(:response_id).distinct(:response_id).count - yearly_counts.any? do |count| - count[1] >= 10 + yearly_counts = SurveyItemResponse.where(school:, academic_year:, + survey_item: measure.student_survey_items).group(:grade).select(:response_id).distinct(:response_id).count + yearly_counts.any? do |count| + count[1] >= 10 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/grade/seven.rb b/app/presenters/dashboard/analyze/graph/column/grade/seven.rb index 6aa5a81..8082ce6 100644 --- a/app/presenters/dashboard/analyze/graph/column/grade/seven.rb +++ b/app/presenters/dashboard/analyze/graph/column/grade/seven.rb @@ -1,30 +1,32 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module Grade - class Seven < GroupedBarColumnPresenter - include Analyze::Graph::Column::Grade::ScoreForGrade - include Analyze::Graph::Column::Grade::GradeCount - def label - %w[Grade 7] - end +module Dashboard + module Analyze + module Graph + module Column + module Grade + class Seven < GroupedBarColumnPresenter + include Analyze::Graph::Column::Grade::ScoreForGrade + include Analyze::Graph::Column::Grade::GradeCount + def label + %w[Grade 7] + end - def basis - "student" - end + def basis + "student" + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def grade - 7 + def grade + 7 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/grade/six.rb b/app/presenters/dashboard/analyze/graph/column/grade/six.rb index 1e40703..3ea0ce8 100644 --- a/app/presenters/dashboard/analyze/graph/column/grade/six.rb +++ b/app/presenters/dashboard/analyze/graph/column/grade/six.rb @@ -1,30 +1,32 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module Grade - class Six < GroupedBarColumnPresenter - include Analyze::Graph::Column::Grade::ScoreForGrade - include Analyze::Graph::Column::Grade::GradeCount - def label - %w[Grade 6] - end +module Dashboard + module Analyze + module Graph + module Column + module Grade + class Six < GroupedBarColumnPresenter + include Analyze::Graph::Column::Grade::ScoreForGrade + include Analyze::Graph::Column::Grade::GradeCount + def label + %w[Grade 6] + end - def basis - "student" - end + def basis + "student" + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def grade - 6 + def grade + 6 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/grade/ten.rb b/app/presenters/dashboard/analyze/graph/column/grade/ten.rb index 45839d3..c89a5c3 100644 --- a/app/presenters/dashboard/analyze/graph/column/grade/ten.rb +++ b/app/presenters/dashboard/analyze/graph/column/grade/ten.rb @@ -1,30 +1,32 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module Grade - class Ten < GroupedBarColumnPresenter - include Analyze::Graph::Column::Grade::ScoreForGrade - include Analyze::Graph::Column::Grade::GradeCount - def label - %w[Grade 10] - end +module Dashboard + module Analyze + module Graph + module Column + module Grade + class Ten < GroupedBarColumnPresenter + include Analyze::Graph::Column::Grade::ScoreForGrade + include Analyze::Graph::Column::Grade::GradeCount + def label + %w[Grade 10] + end - def basis - "student" - end + def basis + "student" + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def grade - 10 + def grade + 10 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/grade/three.rb b/app/presenters/dashboard/analyze/graph/column/grade/three.rb index 44a3277..96c5858 100644 --- a/app/presenters/dashboard/analyze/graph/column/grade/three.rb +++ b/app/presenters/dashboard/analyze/graph/column/grade/three.rb @@ -1,30 +1,32 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module Grade - class Three < GroupedBarColumnPresenter - include Analyze::Graph::Column::Grade::ScoreForGrade - include Analyze::Graph::Column::Grade::GradeCount - def label - %w[Grade 3] - end +module Dashboard + module Analyze + module Graph + module Column + module Grade + class Three < GroupedBarColumnPresenter + include Analyze::Graph::Column::Grade::ScoreForGrade + include Analyze::Graph::Column::Grade::GradeCount + def label + %w[Grade 3] + end - def basis - "student" - end + def basis + "student" + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def grade - 3 + def grade + 3 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/grade/twelve.rb b/app/presenters/dashboard/analyze/graph/column/grade/twelve.rb index 0a8f7a2..2a6b16d 100644 --- a/app/presenters/dashboard/analyze/graph/column/grade/twelve.rb +++ b/app/presenters/dashboard/analyze/graph/column/grade/twelve.rb @@ -1,30 +1,32 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module Grade - class Twelve < GroupedBarColumnPresenter - include Analyze::Graph::Column::Grade::ScoreForGrade - include Analyze::Graph::Column::Grade::GradeCount - def label - %w[Grade 12] - end +module Dashboard + module Analyze + module Graph + module Column + module Grade + class Twelve < GroupedBarColumnPresenter + include Analyze::Graph::Column::Grade::ScoreForGrade + include Analyze::Graph::Column::Grade::GradeCount + def label + %w[Grade 12] + end - def basis - "student" - end + def basis + "student" + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def grade - 12 + def grade + 12 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/grade/two.rb b/app/presenters/dashboard/analyze/graph/column/grade/two.rb index 195661e..d0ee270 100644 --- a/app/presenters/dashboard/analyze/graph/column/grade/two.rb +++ b/app/presenters/dashboard/analyze/graph/column/grade/two.rb @@ -1,30 +1,32 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module Grade - class Two < GroupedBarColumnPresenter - include Analyze::Graph::Column::Grade::ScoreForGrade - include Analyze::Graph::Column::Grade::GradeCount - def label - %w[Grade 2] - end +module Dashboard + module Analyze + module Graph + module Column + module Grade + class Two < GroupedBarColumnPresenter + include Analyze::Graph::Column::Grade::ScoreForGrade + include Analyze::Graph::Column::Grade::GradeCount + def label + %w[Grade 2] + end - def basis - "student" - end + def basis + "student" + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def grade - 2 + def grade + 2 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/grade/zero.rb b/app/presenters/dashboard/analyze/graph/column/grade/zero.rb index 611f9d3..6bba79b 100644 --- a/app/presenters/dashboard/analyze/graph/column/grade/zero.rb +++ b/app/presenters/dashboard/analyze/graph/column/grade/zero.rb @@ -1,30 +1,32 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module Grade - class Zero < GroupedBarColumnPresenter - include Analyze::Graph::Column::Grade::ScoreForGrade - include Analyze::Graph::Column::Grade::GradeCount - def label - %w[Kindergarten] - end +module Dashboard + module Analyze + module Graph + module Column + module Grade + class Zero < GroupedBarColumnPresenter + include Analyze::Graph::Column::Grade::ScoreForGrade + include Analyze::Graph::Column::Grade::GradeCount + def label + %w[Kindergarten] + end - def basis - "student" - end + def basis + "student" + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def grade - 0 + def grade + 0 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/grouped_bar_column_presenter.rb b/app/presenters/dashboard/analyze/graph/column/grouped_bar_column_presenter.rb index d38563e..e685f03 100644 --- a/app/presenters/dashboard/analyze/graph/column/grouped_bar_column_presenter.rb +++ b/app/presenters/dashboard/analyze/graph/column/grouped_bar_column_presenter.rb @@ -1,170 +1,172 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - class GroupedBarColumnPresenter - include AnalyzeHelper +module Dashboard + module Analyze + module Graph + module Column + class GroupedBarColumnPresenter + include AnalyzeHelper - attr_reader :measure_name, :measure_id, :category, :position, :measure, :school, :academic_years, - :number_of_columns + attr_reader :measure_name, :measure_id, :category, :position, :measure, :school, :academic_years, + :number_of_columns - def initialize(measure:, school:, academic_years:, position:, number_of_columns:) - @measure = measure - @measure_name = @measure.name - @measure_id = @measure.measure_id - @category = @measure.subcategory.category - @school = school - @academic_years = academic_years - @position = position - @number_of_columns = number_of_columns - end - - def academic_year_for_year_index(year_index) - academic_years[year_index] - end - - def score(year_index) - measure.score(school:, academic_year: academic_years[year_index]) || 0 - end - - def bars - @bars ||= yearly_scores.map.each_with_index do |yearly_score, index| - year = yearly_score.year - Analyze::BarPresenter.new(measure:, academic_year: year, - score: yearly_score.score, - x_position: bar_x(index), - color: bar_color(year)) - end - end - - def label - %w[All Data] - end - - def show_irrelevancy_message? - false - end - - def show_insufficient_data_message? - scores = academic_years.map do |year| - measure.score(school:, academic_year: year) + def initialize(measure:, school:, academic_years:, position:, number_of_columns:) + @measure = measure + @measure_name = @measure.name + @measure_id = @measure.measure_id + @category = @measure.subcategory.category + @school = school + @academic_years = academic_years + @position = position + @number_of_columns = number_of_columns end - scores.all? do |score| - !score.meets_teacher_threshold? && !score.meets_student_threshold? && !score.meets_admin_data_threshold? + def academic_year_for_year_index(year_index) + academic_years[year_index] end - end - def column_midpoint - zone_label_width + (grouped_chart_column_width * (position + 1)) - (grouped_chart_column_width / 2) - end - - def bar_width - min_bar_width(10.5 / data_sources) - end - - def min_bar_width(number) - min_width = 2 - number < min_width ? min_width : number - end - - def message_x - column_midpoint - message_width / 2 - end - - def message_y - 17 - end - - def message_width - 20 - end - - def message_height - 34 - end - - def column_end_x - zone_label_width + (grouped_chart_column_width * (position + 1)) - end - - def column_start_x - zone_label_width + (grouped_chart_column_width * position) - end - - def grouped_chart_column_width - graph_width / data_sources - end - - def bar_label_height - (100 - ((100 - analyze_graph_height) / 2)) - end - - def data_sources - number_of_columns - end - - def basis - "student surveys" - end - - def type - :all_data - end - - def show_popover? - %i[student teacher].include? type - end - - def n_size(year_index) - SurveyItemResponse.where(survey_item: measure.student_survey_items, school:, grade: grades(year_index), - academic_year: academic_years[year_index]).select(:response_id).distinct.count - end - - def popover_content(year_index) - "#{n_size(year_index)} #{type.to_s.capitalize}s" - end - - def insufficiency_message - ["survey response", "rate below 25%"] - end - - def sufficient_data?(year_index) - case basis - when "student" - score(year_index).meets_student_threshold - when "teacher" - score(year_index).meets_teacher_threshold - else - true + def score(year_index) + measure.score(school:, academic_year: academic_years[year_index]) || 0 end - end - def grades(year_index) - Respondent.by_school_and_year(school:, academic_year: academic_years[year_index]).enrollment_by_grade.keys - end - - private - - YearlyScore = Struct.new(:year, :score) - def yearly_scores - yearly_scores = academic_years.each_with_index.map do |year, index| - YearlyScore.new(year, score(index)) + def bars + @bars ||= yearly_scores.map.each_with_index do |yearly_score, index| + year = yearly_score.year + Analyze::BarPresenter.new(measure:, academic_year: year, + score: yearly_score.score, + x_position: bar_x(index), + color: bar_color(year)) + end end - yearly_scores.reject do |yearly_score| - yearly_score.score.blank? + + def label + %w[All Data] end - end - def bar_color(year) - @available_academic_years ||= AcademicYear.order(:range).all - colors[@available_academic_years.find_index(year)] - end + def show_irrelevancy_message? + false + end - def bar_x(index) - column_start_x + (index * bar_width * 1.2) + - ((column_end_x - column_start_x) - (yearly_scores.size * bar_width * 1.2)) / 2 + def show_insufficient_data_message? + scores = academic_years.map do |year| + measure.score(school:, academic_year: year) + end + + scores.all? do |score| + !score.meets_teacher_threshold? && !score.meets_student_threshold? && !score.meets_admin_data_threshold? + end + end + + def column_midpoint + zone_label_width + (grouped_chart_column_width * (position + 1)) - (grouped_chart_column_width / 2) + end + + def bar_width + min_bar_width(10.5 / data_sources) + end + + def min_bar_width(number) + min_width = 2 + number < min_width ? min_width : number + end + + def message_x + column_midpoint - message_width / 2 + end + + def message_y + 17 + end + + def message_width + 20 + end + + def message_height + 34 + end + + def column_end_x + zone_label_width + (grouped_chart_column_width * (position + 1)) + end + + def column_start_x + zone_label_width + (grouped_chart_column_width * position) + end + + def grouped_chart_column_width + graph_width / data_sources + end + + def bar_label_height + (100 - ((100 - analyze_graph_height) / 2)) + end + + def data_sources + number_of_columns + end + + def basis + "student surveys" + end + + def type + :all_data + end + + def show_popover? + %i[student teacher].include? type + end + + def n_size(year_index) + SurveyItemResponse.where(survey_item: measure.student_survey_items, school:, grade: grades(year_index), + academic_year: academic_years[year_index]).select(:response_id).distinct.count + end + + def popover_content(year_index) + "#{n_size(year_index)} #{type.to_s.capitalize}s" + end + + def insufficiency_message + ["survey response", "rate below 25%"] + end + + def sufficient_data?(year_index) + case basis + when "student" + score(year_index).meets_student_threshold + when "teacher" + score(year_index).meets_teacher_threshold + else + true + end + end + + def grades(year_index) + Respondent.by_school_and_year(school:, academic_year: academic_years[year_index]).enrollment_by_grade.keys + end + + private + + YearlyScore = Struct.new(:year, :score) + def yearly_scores + yearly_scores = academic_years.each_with_index.map do |year, index| + YearlyScore.new(year, score(index)) + end + yearly_scores.reject do |yearly_score| + yearly_score.score.blank? + end + end + + def bar_color(year) + @available_academic_years ||= AcademicYear.order(:range).all + colors[@available_academic_years.find_index(year)] + end + + def bar_x(index) + column_start_x + (index * bar_width * 1.2) + + ((column_end_x - column_start_x) - (yearly_scores.size * bar_width * 1.2)) / 2 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/income_column/disadvantaged.rb b/app/presenters/dashboard/analyze/graph/column/income_column/disadvantaged.rb index 6765d64..eae9911 100644 --- a/app/presenters/dashboard/analyze/graph/column/income_column/disadvantaged.rb +++ b/app/presenters/dashboard/analyze/graph/column/income_column/disadvantaged.rb @@ -1,26 +1,28 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module IncomeColumn - class Disadvantaged < GroupedBarColumnPresenter - include Analyze::Graph::Column::IncomeColumn::ScoreForIncome - include Analyze::Graph::Column::IncomeColumn::IncomeCount - def label - %w[Economically Disadvantaged] - end +module Dashboard + module Analyze + module Graph + module Column + module IncomeColumn + class Disadvantaged < GroupedBarColumnPresenter + include Analyze::Graph::Column::IncomeColumn::ScoreForIncome + include Analyze::Graph::Column::IncomeColumn::IncomeCount + def label + %w[Economically Disadvantaged] + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def income - Income.find_by_designation "Economically Disadvantaged - Y" + def income + Income.find_by_designation "Economically Disadvantaged - Y" + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/income_column/income_count.rb b/app/presenters/dashboard/analyze/graph/column/income_column/income_count.rb index 642f730..e1bba34 100644 --- a/app/presenters/dashboard/analyze/graph/column/income_column/income_count.rb +++ b/app/presenters/dashboard/analyze/graph/column/income_column/income_count.rb @@ -1,15 +1,19 @@ -module Analyze - module Graph - module Column - module IncomeColumn - module IncomeCount - def type - :student - end +# frozen_string_literal: true - def n_size(year_index) - SurveyItemResponse.where(income:, survey_item: measure.student_survey_items, school:, grade: grades(year_index), - academic_year: academic_years[year_index]).select(:response_id).distinct.count +module Dashboard + module Analyze + module Graph + module Column + module IncomeColumn + module IncomeCount + def type + :student + end + + def n_size(year_index) + SurveyItemResponse.where(income:, survey_item: measure.student_survey_items, school:, grade: grades(year_index), + academic_year: academic_years[year_index]).select(:response_id).distinct.count + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/income_column/not_disadvantaged.rb b/app/presenters/dashboard/analyze/graph/column/income_column/not_disadvantaged.rb index cfca2ba..f73d555 100644 --- a/app/presenters/dashboard/analyze/graph/column/income_column/not_disadvantaged.rb +++ b/app/presenters/dashboard/analyze/graph/column/income_column/not_disadvantaged.rb @@ -1,26 +1,28 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module IncomeColumn - class NotDisadvantaged < GroupedBarColumnPresenter - include Analyze::Graph::Column::IncomeColumn::ScoreForIncome - include Analyze::Graph::Column::IncomeColumn::IncomeCount - def label - ["Not Economically", "Disadvantaged"] - end +module Dashboard + module Analyze + module Graph + module Column + module IncomeColumn + class NotDisadvantaged < GroupedBarColumnPresenter + include Analyze::Graph::Column::IncomeColumn::ScoreForIncome + include Analyze::Graph::Column::IncomeColumn::IncomeCount + def label + ["Not Economically", "Disadvantaged"] + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def income - Income.find_by_designation "Economically Disadvantaged - N" + def income + Income.find_by_designation "Economically Disadvantaged - N" + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/income_column/score_for_income.rb b/app/presenters/dashboard/analyze/graph/column/income_column/score_for_income.rb index 52a2324..d280e04 100644 --- a/app/presenters/dashboard/analyze/graph/column/income_column/score_for_income.rb +++ b/app/presenters/dashboard/analyze/graph/column/income_column/score_for_income.rb @@ -1,38 +1,42 @@ -module Analyze - module Graph - module Column - module IncomeColumn - module ScoreForIncome - def score(year_index) - academic_year = academic_years[year_index] - meets_student_threshold = sufficient_student_responses?(academic_year:) - return Score::NIL_SCORE unless meets_student_threshold +# frozen_string_literal: true - averages = SurveyItemResponse.averages_for_income(measure.student_survey_items, school, academic_year, - income) - average = bubble_up_averages(averages:).round(2) +module Dashboard + module Analyze + module Graph + module Column + module IncomeColumn + module ScoreForIncome + def score(year_index) + academic_year = academic_years[year_index] + meets_student_threshold = sufficient_student_responses?(academic_year:) + return Score::NIL_SCORE unless meets_student_threshold - Score.new(average:, - meets_teacher_threshold: false, - meets_student_threshold:, - meets_admin_data_threshold: false) - end + averages = SurveyItemResponse.averages_for_income(measure.student_survey_items, school, academic_year, + income) + average = bubble_up_averages(averages:).round(2) - def bubble_up_averages(averages:) - measure.student_scales.map do |scale| - scale.survey_items.map do |survey_item| - averages[survey_item] + Score.new(average:, + meets_teacher_threshold: false, + meets_student_threshold:, + meets_admin_data_threshold: false) + end + + def bubble_up_averages(averages:) + measure.student_scales.map do |scale| + scale.survey_items.map do |survey_item| + averages[survey_item] + end.remove_blanks.average end.remove_blanks.average - end.remove_blanks.average - end + end - def sufficient_student_responses?(academic_year:) - return false unless measure.subcategory.response_rate(school:, academic_year:).meets_student_threshold? + def sufficient_student_responses?(academic_year:) + return false unless measure.subcategory.response_rate(school:, academic_year:).meets_student_threshold? - yearly_counts = SurveyItemResponse.where(school:, academic_year:, - income:, survey_item: measure.student_survey_items).group(:income).select(:response_id).distinct(:response_id).count - yearly_counts.any? do |count| - count[1] >= 10 + yearly_counts = SurveyItemResponse.where(school:, academic_year:, + income:, survey_item: measure.student_survey_items).group(:income).select(:response_id).distinct(:response_id).count + yearly_counts.any? do |count| + count[1] >= 10 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/income_column/unknown.rb b/app/presenters/dashboard/analyze/graph/column/income_column/unknown.rb index 7a03580..65c2fb6 100644 --- a/app/presenters/dashboard/analyze/graph/column/income_column/unknown.rb +++ b/app/presenters/dashboard/analyze/graph/column/income_column/unknown.rb @@ -1,26 +1,28 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module IncomeColumn - class Unknown < GroupedBarColumnPresenter - include Analyze::Graph::Column::IncomeColumn::ScoreForIncome - include Analyze::Graph::Column::IncomeColumn::IncomeCount - def label - ["Unknown"] - end +module Dashboard + module Analyze + module Graph + module Column + module IncomeColumn + class Unknown < GroupedBarColumnPresenter + include Analyze::Graph::Column::IncomeColumn::ScoreForIncome + include Analyze::Graph::Column::IncomeColumn::IncomeCount + def label + ["Unknown"] + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def income - Income.find_by_designation "Unknown" + def income + Income.find_by_designation "Unknown" + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/race_column/american_indian.rb b/app/presenters/dashboard/analyze/graph/column/race_column/american_indian.rb index b5d2af8..dea8a7a 100644 --- a/app/presenters/dashboard/analyze/graph/column/race_column/american_indian.rb +++ b/app/presenters/dashboard/analyze/graph/column/race_column/american_indian.rb @@ -1,26 +1,28 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module RaceColumn - class AmericanIndian < GroupedBarColumnPresenter - include Analyze::Graph::Column::ScoreForRace - include Analyze::Graph::Column::RaceColumn::RaceCount - def label - %w[American Indian] - end +module Dashboard + module Analyze + module Graph + module Column + module RaceColumn + class AmericanIndian < GroupedBarColumnPresenter + include Analyze::Graph::Column::ScoreForRace + include Analyze::Graph::Column::RaceColumn::RaceCount + def label + %w[American Indian] + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def race - Race.find_by_qualtrics_code 1 + def race + Race.find_by_qualtrics_code 1 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/race_column/asian.rb b/app/presenters/dashboard/analyze/graph/column/race_column/asian.rb index 7b0af7f..96a704e 100644 --- a/app/presenters/dashboard/analyze/graph/column/race_column/asian.rb +++ b/app/presenters/dashboard/analyze/graph/column/race_column/asian.rb @@ -1,26 +1,28 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module RaceColumn - class Asian < GroupedBarColumnPresenter - include Analyze::Graph::Column::ScoreForRace - include Analyze::Graph::Column::RaceColumn::RaceCount - def label - %w[Asian] - end +module Dashboard + module Analyze + module Graph + module Column + module RaceColumn + class Asian < GroupedBarColumnPresenter + include Analyze::Graph::Column::ScoreForRace + include Analyze::Graph::Column::RaceColumn::RaceCount + def label + %w[Asian] + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def race - Race.find_by_qualtrics_code 2 + def race + Race.find_by_qualtrics_code 2 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/race_column/black.rb b/app/presenters/dashboard/analyze/graph/column/race_column/black.rb index 72046c9..de3db23 100644 --- a/app/presenters/dashboard/analyze/graph/column/race_column/black.rb +++ b/app/presenters/dashboard/analyze/graph/column/race_column/black.rb @@ -1,26 +1,28 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module RaceColumn - class Black < GroupedBarColumnPresenter - include Analyze::Graph::Column::ScoreForRace - include Analyze::Graph::Column::RaceColumn::RaceCount - def label - %w[Black] - end +module Dashboard + module Analyze + module Graph + module Column + module RaceColumn + class Black < GroupedBarColumnPresenter + include Analyze::Graph::Column::ScoreForRace + include Analyze::Graph::Column::RaceColumn::RaceCount + def label + %w[Black] + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def race - Race.find_by_qualtrics_code 3 + def race + Race.find_by_qualtrics_code 3 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/race_column/hispanic.rb b/app/presenters/dashboard/analyze/graph/column/race_column/hispanic.rb index 6f92a77..630fb0d 100644 --- a/app/presenters/dashboard/analyze/graph/column/race_column/hispanic.rb +++ b/app/presenters/dashboard/analyze/graph/column/race_column/hispanic.rb @@ -1,26 +1,28 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module RaceColumn - class Hispanic < GroupedBarColumnPresenter - include Analyze::Graph::Column::ScoreForRace - include Analyze::Graph::Column::RaceColumn::RaceCount - def label - %w[Hispanic] - end +module Dashboard + module Analyze + module Graph + module Column + module RaceColumn + class Hispanic < GroupedBarColumnPresenter + include Analyze::Graph::Column::ScoreForRace + include Analyze::Graph::Column::RaceColumn::RaceCount + def label + %w[Hispanic] + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def race - Race.find_by_qualtrics_code 4 + def race + Race.find_by_qualtrics_code 4 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/race_column/middle_eastern.rb b/app/presenters/dashboard/analyze/graph/column/race_column/middle_eastern.rb index 36955bf..83b546e 100644 --- a/app/presenters/dashboard/analyze/graph/column/race_column/middle_eastern.rb +++ b/app/presenters/dashboard/analyze/graph/column/race_column/middle_eastern.rb @@ -1,27 +1,29 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module RaceColumn - class MiddleEastern < GroupedBarColumnPresenter - include Analyze::Graph::Column::ScoreForRace - include Analyze::Graph::Column::RaceColumn::RaceCount +module Dashboard + module Analyze + module Graph + module Column + module RaceColumn + class MiddleEastern < GroupedBarColumnPresenter + include Analyze::Graph::Column::ScoreForRace + include Analyze::Graph::Column::RaceColumn::RaceCount - def label - %w[Middle Eastern] - end + def label + %w[Middle Eastern] + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def race - Race.find_by_qualtrics_code 8 + def race + Race.find_by_qualtrics_code 8 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/race_column/multiracial.rb b/app/presenters/dashboard/analyze/graph/column/race_column/multiracial.rb index c150cea..d45f7ad 100644 --- a/app/presenters/dashboard/analyze/graph/column/race_column/multiracial.rb +++ b/app/presenters/dashboard/analyze/graph/column/race_column/multiracial.rb @@ -1,26 +1,28 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module RaceColumn - class Multiracial < GroupedBarColumnPresenter - include Analyze::Graph::Column::ScoreForRace - include Analyze::Graph::Column::RaceColumn::RaceCount - def label - %w[Multiracial] - end +module Dashboard + module Analyze + module Graph + module Column + module RaceColumn + class Multiracial < GroupedBarColumnPresenter + include Analyze::Graph::Column::ScoreForRace + include Analyze::Graph::Column::RaceColumn::RaceCount + def label + %w[Multiracial] + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def race - Race.find_by_qualtrics_code 100 + def race + Race.find_by_qualtrics_code 100 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/race_column/race_count.rb b/app/presenters/dashboard/analyze/graph/column/race_column/race_count.rb index b46d3de..70acc40 100644 --- a/app/presenters/dashboard/analyze/graph/column/race_column/race_count.rb +++ b/app/presenters/dashboard/analyze/graph/column/race_column/race_count.rb @@ -1,17 +1,21 @@ -module Analyze - module Graph - module Column - module RaceColumn - module RaceCount - def type - :student - end +# frozen_string_literal: true - def n_size(year_index) - SurveyItemResponse.joins("JOIN student_races on survey_item_responses.student_id = student_races.student_id JOIN students on students.id = student_races.student_id").where( - school:, academic_year: academic_years[year_index], - survey_item: measure.student_survey_items - ).where("student_races.race_id": race.id).select(:response_id).distinct.count +module Dashboard + module Analyze + module Graph + module Column + module RaceColumn + module RaceCount + def type + :student + end + + def n_size(year_index) + SurveyItemResponse.joins("JOIN student_races on survey_item_responses.student_id = student_races.student_id JOIN students on students.id = student_races.student_id").where( + school:, academic_year: academic_years[year_index], + survey_item: measure.student_survey_items + ).where("student_races.race_id": race.id).select(:response_id).distinct.count + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/race_column/unknown.rb b/app/presenters/dashboard/analyze/graph/column/race_column/unknown.rb index 8c6b786..28523f8 100644 --- a/app/presenters/dashboard/analyze/graph/column/race_column/unknown.rb +++ b/app/presenters/dashboard/analyze/graph/column/race_column/unknown.rb @@ -1,26 +1,28 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module RaceColumn - class Unknown < GroupedBarColumnPresenter - include Analyze::Graph::Column::ScoreForRace - include Analyze::Graph::Column::RaceColumn::RaceCount - def label - %w[Not Listed] - end +module Dashboard + module Analyze + module Graph + module Column + module RaceColumn + class Unknown < GroupedBarColumnPresenter + include Analyze::Graph::Column::ScoreForRace + include Analyze::Graph::Column::RaceColumn::RaceCount + def label + %w[Not Listed] + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def race - Race.find_by_qualtrics_code 99 + def race + Race.find_by_qualtrics_code 99 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/race_column/white.rb b/app/presenters/dashboard/analyze/graph/column/race_column/white.rb index 221ecc8..9f4bb65 100644 --- a/app/presenters/dashboard/analyze/graph/column/race_column/white.rb +++ b/app/presenters/dashboard/analyze/graph/column/race_column/white.rb @@ -1,26 +1,28 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module RaceColumn - class White < GroupedBarColumnPresenter - include Analyze::Graph::Column::ScoreForRace - include Analyze::Graph::Column::RaceColumn::RaceCount - def label - %w[White] - end +module Dashboard + module Analyze + module Graph + module Column + module RaceColumn + class White < GroupedBarColumnPresenter + include Analyze::Graph::Column::ScoreForRace + include Analyze::Graph::Column::RaceColumn::RaceCount + def label + %w[White] + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def race - Race.find_by_qualtrics_code 5 + def race + Race.find_by_qualtrics_code 5 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/score_for_race.rb b/app/presenters/dashboard/analyze/graph/column/score_for_race.rb index e1b9ce5..d0585c7 100644 --- a/app/presenters/dashboard/analyze/graph/column/score_for_race.rb +++ b/app/presenters/dashboard/analyze/graph/column/score_for_race.rb @@ -1,38 +1,42 @@ -module Analyze - module Graph - module Column - module ScoreForRace - def score(year_index) - academic_year = academic_years[year_index] - meets_student_threshold = sufficient_student_responses?(academic_year:) - return Score::NIL_SCORE unless meets_student_threshold +# frozen_string_literal: true - survey_items = measure.student_survey_items +module Dashboard + module Analyze + module Graph + module Column + module ScoreForRace + def score(year_index) + academic_year = academic_years[year_index] + meets_student_threshold = sufficient_student_responses?(academic_year:) + return Score::NIL_SCORE unless meets_student_threshold - averages = SurveyItemResponse.averages_for_race(school, academic_year, race) - average = bubble_up_averages(averages:).round(2) + survey_items = measure.student_survey_items - Score.new(average:, - meets_teacher_threshold: false, - meets_student_threshold:, - meets_admin_data_threshold: false) - end + averages = SurveyItemResponse.averages_for_race(school, academic_year, race) + average = bubble_up_averages(averages:).round(2) - def bubble_up_averages(averages:) - measure.student_scales.map do |scale| - scale.survey_items.map do |survey_item| - averages[survey_item.id] + Score.new(average:, + meets_teacher_threshold: false, + meets_student_threshold:, + meets_admin_data_threshold: false) + end + + def bubble_up_averages(averages:) + measure.student_scales.map do |scale| + scale.survey_items.map do |survey_item| + averages[survey_item.id] + end.remove_blanks.average end.remove_blanks.average - end.remove_blanks.average - end + end - def sufficient_student_responses?(academic_year:) - return false unless measure.subcategory.response_rate(school:, academic_year:).meets_student_threshold? + def sufficient_student_responses?(academic_year:) + return false unless measure.subcategory.response_rate(school:, academic_year:).meets_student_threshold? - number_of_students_for_a_racial_group = SurveyItemResponse.joins("JOIN student_races on dashboard_survey_item_responses.student_id = student_races.student_id JOIN students on students.id = student_races.student_id").where( - school:, academic_year: - ).where("student_races.race_id": race.id).distinct.pluck(:student_id).count - number_of_students_for_a_racial_group >= 10 + number_of_students_for_a_racial_group = SurveyItemResponse.joins("JOIN student_races on dashboard_survey_item_responses.student_id = student_races.student_id JOIN students on students.id = student_races.student_id").where( + school:, academic_year: + ).where("student_races.race_id": race.id).distinct.pluck(:student_id).count + number_of_students_for_a_racial_group >= 10 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/sped_column/not_sped.rb b/app/presenters/dashboard/analyze/graph/column/sped_column/not_sped.rb index cd4ece2..4e424e8 100644 --- a/app/presenters/dashboard/analyze/graph/column/sped_column/not_sped.rb +++ b/app/presenters/dashboard/analyze/graph/column/sped_column/not_sped.rb @@ -1,31 +1,33 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module SpedColumn - class NotSped < GroupedBarColumnPresenter - include Analyze::Graph::Column::SpedColumn::ScoreForSped - include Analyze::Graph::Column::SpedColumn::SpedCount +module Dashboard + module Analyze + module Graph + module Column + module SpedColumn + class NotSped < GroupedBarColumnPresenter + include Analyze::Graph::Column::SpedColumn::ScoreForSped + include Analyze::Graph::Column::SpedColumn::SpedCount - def label - ["Not Special", "Education"] - end + def label + ["Not Special", "Education"] + end - def basis - "student" - end + def basis + "student" + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def sped - ::Sped.find_by_slug "not-special-education" + def sped + ::Sped.find_by_slug "not-special-education" + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/sped_column/score_for_sped.rb b/app/presenters/dashboard/analyze/graph/column/sped_column/score_for_sped.rb index 4727e37..ced4778 100644 --- a/app/presenters/dashboard/analyze/graph/column/sped_column/score_for_sped.rb +++ b/app/presenters/dashboard/analyze/graph/column/sped_column/score_for_sped.rb @@ -1,38 +1,42 @@ -module Analyze - module Graph - module Column - module SpedColumn - module ScoreForSped - def score(year_index) - academic_year = academic_years[year_index] - meets_student_threshold = sufficient_student_responses?(academic_year:) - return Score::NIL_SCORE unless meets_student_threshold +# frozen_string_literal: true - averages = SurveyItemResponse.averages_for_sped(measure.student_survey_items, school, academic_year, - sped) - average = bubble_up_averages(averages:).round(2) +module Dashboard + module Analyze + module Graph + module Column + module SpedColumn + module ScoreForSped + def score(year_index) + academic_year = academic_years[year_index] + meets_student_threshold = sufficient_student_responses?(academic_year:) + return Score::NIL_SCORE unless meets_student_threshold - Score.new(average:, - meets_teacher_threshold: false, - meets_student_threshold:, - meets_admin_data_threshold: false) - end + averages = SurveyItemResponse.averages_for_sped(measure.student_survey_items, school, academic_year, + sped) + average = bubble_up_averages(averages:).round(2) - def bubble_up_averages(averages:) - measure.student_scales.map do |scale| - scale.survey_items.map do |survey_item| - averages[survey_item] + Score.new(average:, + meets_teacher_threshold: false, + meets_student_threshold:, + meets_admin_data_threshold: false) + end + + def bubble_up_averages(averages:) + measure.student_scales.map do |scale| + scale.survey_items.map do |survey_item| + averages[survey_item] + end.remove_blanks.average end.remove_blanks.average - end.remove_blanks.average - end + end - def sufficient_student_responses?(academic_year:) - return false unless measure.subcategory.response_rate(school:, academic_year:).meets_student_threshold? + def sufficient_student_responses?(academic_year:) + return false unless measure.subcategory.response_rate(school:, academic_year:).meets_student_threshold? - yearly_counts = SurveyItemResponse.where(school:, academic_year:, - sped:, survey_item: measure.student_survey_items).group(:sped).select(:response_id).distinct(:response_id).count - yearly_counts.any? do |count| - count[1] >= 10 + yearly_counts = SurveyItemResponse.where(school:, academic_year:, + sped:, survey_item: measure.student_survey_items).group(:sped).select(:response_id).distinct(:response_id).count + yearly_counts.any? do |count| + count[1] >= 10 + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/sped_column/sped.rb b/app/presenters/dashboard/analyze/graph/column/sped_column/sped.rb index 7e67e10..5170f0c 100644 --- a/app/presenters/dashboard/analyze/graph/column/sped_column/sped.rb +++ b/app/presenters/dashboard/analyze/graph/column/sped_column/sped.rb @@ -1,31 +1,33 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module SpedColumn - class Sped < GroupedBarColumnPresenter - include Analyze::Graph::Column::SpedColumn::ScoreForSped - include Analyze::Graph::Column::SpedColumn::SpedCount +module Dashboard + module Analyze + module Graph + module Column + module SpedColumn + class Sped < GroupedBarColumnPresenter + include Analyze::Graph::Column::SpedColumn::ScoreForSped + include Analyze::Graph::Column::SpedColumn::SpedCount - def label - %w[Special Education] - end + def label + %w[Special Education] + end - def basis - "student" - end + def basis + "student" + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def sped - ::Sped.find_by_slug "special-education" + def sped + ::Sped.find_by_slug "special-education" + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/sped_column/sped_count.rb b/app/presenters/dashboard/analyze/graph/column/sped_column/sped_count.rb index 72f1b78..fc1e1fb 100644 --- a/app/presenters/dashboard/analyze/graph/column/sped_column/sped_count.rb +++ b/app/presenters/dashboard/analyze/graph/column/sped_column/sped_count.rb @@ -1,15 +1,19 @@ -module Analyze - module Graph - module Column - module SpedColumn - module SpedCount - def type - :student - end +# frozen_string_literal: true - def n_size(year_index) - SurveyItemResponse.where(sped:, survey_item: measure.student_survey_items, school:, grade: grades(year_index), - academic_year: academic_years[year_index]).select(:response_id).distinct.count +module Dashboard + module Analyze + module Graph + module Column + module SpedColumn + module SpedCount + def type + :student + end + + def n_size(year_index) + SurveyItemResponse.where(sped:, survey_item: measure.student_survey_items, school:, grade: grades(year_index), + academic_year: academic_years[year_index]).select(:response_id).distinct.count + end end end end diff --git a/app/presenters/dashboard/analyze/graph/column/sped_column/unknown.rb b/app/presenters/dashboard/analyze/graph/column/sped_column/unknown.rb index e3e7fa5..df0efb6 100644 --- a/app/presenters/dashboard/analyze/graph/column/sped_column/unknown.rb +++ b/app/presenters/dashboard/analyze/graph/column/sped_column/unknown.rb @@ -1,31 +1,33 @@ # frozen_string_literal: true -module Analyze - module Graph - module Column - module SpedColumn - class Unknown < GroupedBarColumnPresenter - include Analyze::Graph::Column::SpedColumn::ScoreForSped - include Analyze::Graph::Column::SpedColumn::SpedCount +module Dashboard + module Analyze + module Graph + module Column + module SpedColumn + class Unknown < GroupedBarColumnPresenter + include Analyze::Graph::Column::SpedColumn::ScoreForSped + include Analyze::Graph::Column::SpedColumn::SpedCount - def label - %w[Unknown] - end + def label + %w[Unknown] + end - def basis - "student" - end + def basis + "student" + end - def show_irrelevancy_message? - false - end + def show_irrelevancy_message? + false + end - def show_insufficient_data_message? - false - end + def show_insufficient_data_message? + false + end - def sped - ::Sped.find_by_slug "unknown" + def sped + ::Sped.find_by_slug "unknown" + end end end end diff --git a/app/presenters/dashboard/analyze/graph/students_and_teachers.rb b/app/presenters/dashboard/analyze/graph/students_and_teachers.rb index 482f817..c6cac35 100644 --- a/app/presenters/dashboard/analyze/graph/students_and_teachers.rb +++ b/app/presenters/dashboard/analyze/graph/students_and_teachers.rb @@ -1,19 +1,21 @@ # frozen_string_literal: true -module Analyze - module Graph - class StudentsAndTeachers - include Analyze::Graph::Column - def to_s - 'Students & Teachers' - end +module Dashboard + module Analyze + module Graph + class StudentsAndTeachers + include Analyze::Graph::Column + def to_s + "Students & Teachers" + end - def slug - 'students-and-teachers' - end + def slug + "students-and-teachers" + end - def columns - [AllStudent, AllTeacher, AllSurveyData] + def columns + [AllStudent, AllTeacher, AllSurveyData] + end end end end diff --git a/app/presenters/dashboard/analyze/graph/students_by_ell.rb b/app/presenters/dashboard/analyze/graph/students_by_ell.rb index 7431faa..334b495 100644 --- a/app/presenters/dashboard/analyze/graph/students_by_ell.rb +++ b/app/presenters/dashboard/analyze/graph/students_by_ell.rb @@ -1,44 +1,46 @@ # frozen_string_literal: true -module Analyze - module Graph - class StudentsByEll - include Analyze::Graph::Column::EllColumn - attr_reader :ells +module Dashboard + module Analyze + module Graph + class StudentsByEll + include Analyze::Graph::Column::EllColumn + attr_reader :ells - def initialize(ells:) - @ells = ells - end - - def to_s - "Students by Ell" - end - - def slug - "students-by-ell" - end - - def columns - [].tap do |array| - ells.each do |ell| - array << column_for_ell_code(code: ell.slug) - end - array.sort_by!(&:to_s) - array << Analyze::Graph::Column::AllStudent + def initialize(ells:) + @ells = ells end + + def to_s + "Students by Ell" + end + + def slug + "students-by-ell" + end + + def columns + [].tap do |array| + ells.each do |ell| + array << column_for_ell_code(code: ell.slug) + end + array.sort_by!(&:to_s) + array << Analyze::Graph::Column::AllStudent + end + end + + private + + def column_for_ell_code(code:) + CFR[code] + end + + CFR = { + "ell" => Analyze::Graph::Column::EllColumn::Ell, + "not-ell" => Analyze::Graph::Column::EllColumn::NotEll, + "unknown" => Analyze::Graph::Column::EllColumn::Unknown + }.freeze end - - private - - def column_for_ell_code(code:) - CFR[code] - end - - CFR = { - "ell" => Analyze::Graph::Column::EllColumn::Ell, - "not-ell" => Analyze::Graph::Column::EllColumn::NotEll, - "unknown" => Analyze::Graph::Column::EllColumn::Unknown - }.freeze end end end diff --git a/app/presenters/dashboard/analyze/graph/students_by_gender.rb b/app/presenters/dashboard/analyze/graph/students_by_gender.rb index 97d3363..9a0493e 100644 --- a/app/presenters/dashboard/analyze/graph/students_by_gender.rb +++ b/app/presenters/dashboard/analyze/graph/students_by_gender.rb @@ -1,45 +1,47 @@ # frozen_string_literal: true -module Analyze - module Graph - class StudentsByGender - include Analyze::Graph::Column::GenderColumn - attr_reader :genders +module Dashboard + module Analyze + module Graph + class StudentsByGender + include Analyze::Graph::Column::GenderColumn + attr_reader :genders - def initialize(genders:) - @genders = genders - end - - def to_s - "Students by Gender" - end - - def slug - "students-by-gender" - end - - def columns - [].tap do |array| - genders.each do |gender| - array << column_for_gender_code(code: gender.qualtrics_code) - end - array.sort_by!(&:to_s) - array << Analyze::Graph::Column::AllStudent + def initialize(genders:) + @genders = genders end + + def to_s + "Students by Gender" + end + + def slug + "students-by-gender" + end + + def columns + [].tap do |array| + genders.each do |gender| + array << column_for_gender_code(code: gender.qualtrics_code) + end + array.sort_by!(&:to_s) + array << Analyze::Graph::Column::AllStudent + end + end + + private + + def column_for_gender_code(code:) + CFR[code] + end + + CFR = { + 1 => Analyze::Graph::Column::GenderColumn::Female, + 2 => Analyze::Graph::Column::GenderColumn::Male, + 4 => Analyze::Graph::Column::GenderColumn::NonBinary, + 99 => Analyze::Graph::Column::GenderColumn::Unknown + }.freeze end - - private - - def column_for_gender_code(code:) - CFR[code] - end - - CFR = { - 1 => Analyze::Graph::Column::GenderColumn::Female, - 2 => Analyze::Graph::Column::GenderColumn::Male, - 4 => Analyze::Graph::Column::GenderColumn::NonBinary, - 99 => Analyze::Graph::Column::GenderColumn::Unknown - }.freeze end end end diff --git a/app/presenters/dashboard/analyze/graph/students_by_grade.rb b/app/presenters/dashboard/analyze/graph/students_by_grade.rb index 3fb113d..9805953 100644 --- a/app/presenters/dashboard/analyze/graph/students_by_grade.rb +++ b/app/presenters/dashboard/analyze/graph/students_by_grade.rb @@ -1,53 +1,55 @@ # frozen_string_literal: true -module Analyze - module Graph - class StudentsByGrade - include Analyze::Graph::Column::Grade - attr_reader :grades +module Dashboard + module Analyze + module Graph + class StudentsByGrade + include Analyze::Graph::Column::Grade + attr_reader :grades - def initialize(grades:) - @grades = grades - end - - def to_s - "Students by Grade" - end - - def slug - "students-by-grade" - end - - def columns - [].tap do |array| - grades.each do |grade| - array << column_for_grade_code(code: grade) - end - array << Analyze::Graph::Column::AllStudent + def initialize(grades:) + @grades = grades end + + def to_s + "Students by Grade" + end + + def slug + "students-by-grade" + end + + def columns + [].tap do |array| + grades.each do |grade| + array << column_for_grade_code(code: grade) + end + array << Analyze::Graph::Column::AllStudent + end + end + + private + + def column_for_grade_code(code:) + CFR[code] + end + + CFR = { + 0 => Zero, + 1 => One, + 2 => Two, + 3 => Three, + 4 => Four, + 5 => Five, + 6 => Six, + 7 => Seven, + 8 => Eight, + 9 => Nine, + 10 => Ten, + 11 => Eleven, + 12 => Twelve + }.freeze end - - private - - def column_for_grade_code(code:) - CFR[code] - end - - CFR = { - 0 => Zero, - 1 => One, - 2 => Two, - 3 => Three, - 4 => Four, - 5 => Five, - 6 => Six, - 7 => Seven, - 8 => Eight, - 9 => Nine, - 10 => Ten, - 11 => Eleven, - 12 => Twelve - }.freeze end end end diff --git a/app/presenters/dashboard/analyze/graph/students_by_income.rb b/app/presenters/dashboard/analyze/graph/students_by_income.rb index e72b6ef..7810ac7 100644 --- a/app/presenters/dashboard/analyze/graph/students_by_income.rb +++ b/app/presenters/dashboard/analyze/graph/students_by_income.rb @@ -1,42 +1,44 @@ # frozen_string_literal: true -module Analyze - module Graph - class StudentsByIncome - attr_reader :incomes +module Dashboard + module Analyze + module Graph + class StudentsByIncome + attr_reader :incomes - def initialize(incomes:) - @incomes = incomes - end - - def to_s - "Students by income" - end - - def slug - "students-by-income" - end - - def columns - [].tap do |array| - incomes.each do |income| - array << column_for_income_code(code: income.slug) - end - array << Analyze::Graph::Column::AllStudent + def initialize(incomes:) + @incomes = incomes end + + def to_s + "Students by income" + end + + def slug + "students-by-income" + end + + def columns + [].tap do |array| + incomes.each do |income| + array << column_for_income_code(code: income.slug) + end + array << Analyze::Graph::Column::AllStudent + end + end + + private + + def column_for_income_code(code:) + CFR[code.to_s] + end + + CFR = { + "economically-disadvantaged-y" => Analyze::Graph::Column::IncomeColumn::Disadvantaged, + "economically-disadvantaged-n" => Analyze::Graph::Column::IncomeColumn::NotDisadvantaged, + "unknown" => Analyze::Graph::Column::IncomeColumn::Unknown + }.freeze end - - private - - def column_for_income_code(code:) - CFR[code.to_s] - end - - CFR = { - "economically-disadvantaged-y" => Analyze::Graph::Column::IncomeColumn::Disadvantaged, - "economically-disadvantaged-n" => Analyze::Graph::Column::IncomeColumn::NotDisadvantaged, - "unknown" => Analyze::Graph::Column::IncomeColumn::Unknown - }.freeze end end end diff --git a/app/presenters/dashboard/analyze/graph/students_by_race.rb b/app/presenters/dashboard/analyze/graph/students_by_race.rb index 74a7cb8..4ea5087 100644 --- a/app/presenters/dashboard/analyze/graph/students_by_race.rb +++ b/app/presenters/dashboard/analyze/graph/students_by_race.rb @@ -1,47 +1,49 @@ # frozen_string_literal: true -module Analyze - module Graph - class StudentsByRace - attr_reader :races +module Dashboard + module Analyze + module Graph + class StudentsByRace + attr_reader :races - def initialize(races:) - @races = races - end - - def to_s - "Students by Race" - end - - def slug - "students-by-race" - end - - def columns - [].tap do |array| - races.each do |race| - array << column_for_race_code(code: race.qualtrics_code) - end - array << Analyze::Graph::Column::AllStudent + def initialize(races:) + @races = races end + + def to_s + "Students by Race" + end + + def slug + "students-by-race" + end + + def columns + [].tap do |array| + races.each do |race| + array << column_for_race_code(code: race.qualtrics_code) + end + array << Analyze::Graph::Column::AllStudent + end + end + + private + + def column_for_race_code(code:) + CFR[code.to_s] + end + + CFR = { + "1" => Analyze::Graph::Column::RaceColumn::AmericanIndian, + "2" => Analyze::Graph::Column::RaceColumn::Asian, + "3" => Analyze::Graph::Column::RaceColumn::Black, + "4" => Analyze::Graph::Column::RaceColumn::Hispanic, + "5" => Analyze::Graph::Column::RaceColumn::White, + "8" => Analyze::Graph::Column::RaceColumn::MiddleEastern, + "99" => Analyze::Graph::Column::RaceColumn::Unknown, + "100" => Analyze::Graph::Column::RaceColumn::Multiracial + }.freeze end - - private - - def column_for_race_code(code:) - CFR[code.to_s] - end - - CFR = { - "1" => Analyze::Graph::Column::RaceColumn::AmericanIndian, - "2" => Analyze::Graph::Column::RaceColumn::Asian, - "3" => Analyze::Graph::Column::RaceColumn::Black, - "4" => Analyze::Graph::Column::RaceColumn::Hispanic, - "5" => Analyze::Graph::Column::RaceColumn::White, - "8" => Analyze::Graph::Column::RaceColumn::MiddleEastern, - "99" => Analyze::Graph::Column::RaceColumn::Unknown, - "100" => Analyze::Graph::Column::RaceColumn::Multiracial - }.freeze end end end diff --git a/app/presenters/dashboard/analyze/graph/students_by_sped.rb b/app/presenters/dashboard/analyze/graph/students_by_sped.rb index 6129d62..d9509e4 100644 --- a/app/presenters/dashboard/analyze/graph/students_by_sped.rb +++ b/app/presenters/dashboard/analyze/graph/students_by_sped.rb @@ -1,43 +1,45 @@ # frozen_string_literal: true -module Analyze - module Graph - class StudentsBySped - include Analyze::Graph::Column::SpedColumn - attr_reader :speds +module Dashboard + module Analyze + module Graph + class StudentsBySped + include Analyze::Graph::Column::SpedColumn + attr_reader :speds - def initialize(speds:) - @speds = speds - end - - def to_s - "Students by SpEd" - end - - def slug - "students-by-sped" - end - - def columns - [].tap do |array| - speds.each do |sped| - array << column_for_sped_code(code: sped.slug) - end - array << Analyze::Graph::Column::AllStudent + def initialize(speds:) + @speds = speds end + + def to_s + "Students by SpEd" + end + + def slug + "students-by-sped" + end + + def columns + [].tap do |array| + speds.each do |sped| + array << column_for_sped_code(code: sped.slug) + end + array << Analyze::Graph::Column::AllStudent + end + end + + private + + def column_for_sped_code(code:) + CFR[code] + end + + CFR = { + "special-education" => Analyze::Graph::Column::SpedColumn::Sped, + "not-special-education" => Analyze::Graph::Column::SpedColumn::NotSped, + "unknown" => Analyze::Graph::Column::SpedColumn::Unknown + }.freeze end - - private - - def column_for_sped_code(code:) - CFR[code] - end - - CFR = { - "special-education" => Analyze::Graph::Column::SpedColumn::Sped, - "not-special-education" => Analyze::Graph::Column::SpedColumn::NotSped, - "unknown" => Analyze::Graph::Column::SpedColumn::Unknown - }.freeze end end end diff --git a/app/presenters/dashboard/analyze/group/ell.rb b/app/presenters/dashboard/analyze/group/ell.rb index 512b3d5..189f173 100644 --- a/app/presenters/dashboard/analyze/group/ell.rb +++ b/app/presenters/dashboard/analyze/group/ell.rb @@ -1,12 +1,16 @@ -module Analyze - module Group - class Ell - def name - "ELL" - end +# frozen_string_literal: true - def slug - "ell" +module Dashboard + module Analyze + module Group + class Ell + def name + "ELL" + end + + def slug + "ell" + end end end end diff --git a/app/presenters/dashboard/analyze/group/gender.rb b/app/presenters/dashboard/analyze/group/gender.rb index 901d24d..d745d56 100644 --- a/app/presenters/dashboard/analyze/group/gender.rb +++ b/app/presenters/dashboard/analyze/group/gender.rb @@ -1,12 +1,16 @@ -module Analyze - module Group - class Gender - def name - 'Gender' - end +# frozen_string_literal: true - def slug - 'gender' +module Dashboard + module Analyze + module Group + class Gender + def name + "Gender" + end + + def slug + "gender" + end end end end diff --git a/app/presenters/dashboard/analyze/group/grade.rb b/app/presenters/dashboard/analyze/group/grade.rb index 9504469..668f1a5 100644 --- a/app/presenters/dashboard/analyze/group/grade.rb +++ b/app/presenters/dashboard/analyze/group/grade.rb @@ -1,12 +1,16 @@ -module Analyze - module Group - class Grade - def name - 'Grade' - end +# frozen_string_literal: true - def slug - 'grade' +module Dashboard + module Analyze + module Group + class Grade + def name + "Grade" + end + + def slug + "grade" + end end end end diff --git a/app/presenters/dashboard/analyze/group/income.rb b/app/presenters/dashboard/analyze/group/income.rb index 21e364b..5cc4485 100644 --- a/app/presenters/dashboard/analyze/group/income.rb +++ b/app/presenters/dashboard/analyze/group/income.rb @@ -1,12 +1,16 @@ -module Analyze - module Group - class Income - def name - 'Income' - end +# frozen_string_literal: true - def slug - 'income' +module Dashboard + module Analyze + module Group + class Income + def name + "Income" + end + + def slug + "income" + end end end end diff --git a/app/presenters/dashboard/analyze/group/race.rb b/app/presenters/dashboard/analyze/group/race.rb index 1155d1c..6d0f993 100644 --- a/app/presenters/dashboard/analyze/group/race.rb +++ b/app/presenters/dashboard/analyze/group/race.rb @@ -1,12 +1,16 @@ -module Analyze - module Group - class Race - def name - 'Race' - end +# frozen_string_literal: true - def slug - 'race' +module Dashboard + module Analyze + module Group + class Race + def name + "Race" + end + + def slug + "race" + end end end end diff --git a/app/presenters/dashboard/analyze/group/sped.rb b/app/presenters/dashboard/analyze/group/sped.rb index 6f4b221..9b6c136 100644 --- a/app/presenters/dashboard/analyze/group/sped.rb +++ b/app/presenters/dashboard/analyze/group/sped.rb @@ -1,12 +1,16 @@ -module Analyze - module Group - class Sped - def name - "Special Education" - end +# frozen_string_literal: true - def slug - "sped" +module Dashboard + module Analyze + module Group + class Sped + def name + "Special Education" + end + + def slug + "sped" + end end end end diff --git a/app/presenters/dashboard/analyze/presenter.rb b/app/presenters/dashboard/analyze/presenter.rb index 99f3128..7241a5e 100644 --- a/app/presenters/dashboard/analyze/presenter.rb +++ b/app/presenters/dashboard/analyze/presenter.rb @@ -1,200 +1,206 @@ -module Analyze - class Presenter - attr_reader :params, :school, :academic_year +module Dashboard + module Analyze + class Presenter + attr_reader :params, :school, :academic_year - def initialize(params:, school:, academic_year:) - @params = params - @school = school - @academic_year = academic_year - end - - def category - @category ||= Category.find_by_category_id(params[:category]) || Category.order(:category_id).first - end - - def categories - @categories = Category.all.order(:category_id) - end - - def subcategory - @subcategory ||= Subcategory.find_by_subcategory_id(params[:subcategory]) || subcategories.first - end - - def subcategories - @subcategories = category.subcategories.order(:subcategory_id) - end - - def measures - @measures = subcategory.measures.order(:measure_id).includes(%i[admin_data_items subcategory]) - end - - def academic_years - @academic_years = AcademicYear.order(:range).all - end - - def selected_academic_years - @selected_academic_years ||= begin - year_params = params[:academic_years] - return [] unless year_params - - year_params.split(",").map { |year| AcademicYear.find_by_range(year) }.compact + def initialize(params:, school:, academic_year:) + @params = params + @school = school + @academic_year = academic_year end - end - def races - @races ||= Race.all.order(designation: :ASC) - end - - def selected_races - @selected_races ||= begin - race_params = params[:races] - return races unless race_params - - race_params.split(",").map { |race| Race.find_by_slug race }.compact + def category + @category ||= Category.find_by_category_id(params[:category]) || Category.order(:category_id).first end - end - def ells - @ells ||= Ell.all.order(slug: :ASC) - end - - def selected_ells - @selected_ells ||= begin - ell_params = params[:ells] - return ells unless ell_params - - ell_params.split(",").map { |ell| Ell.find_by_slug ell }.compact + def categories + @categories = Category.all.order(:category_id) end - end - def speds - @speds ||= Sped.all.order(id: :ASC) - end - - def selected_speds - @selected_speds ||= begin - sped_params = params[:speds] - return speds unless sped_params - - sped_params.split(",").map { |sped| Sped.find_by_slug sped }.compact + def subcategory + @subcategory ||= Subcategory.find_by_subcategory_id(params[:subcategory]) || subcategories.first end - end - def graphs - @graphs ||= [Analyze::Graph::AllData.new, - Analyze::Graph::StudentsAndTeachers.new, - Analyze::Graph::StudentsByRace.new(races: selected_races), - Analyze::Graph::StudentsByGrade.new(grades: selected_grades), - Analyze::Graph::StudentsByGender.new(genders: selected_genders), - Analyze::Graph::StudentsByIncome.new(incomes: selected_incomes), - Analyze::Graph::StudentsByEll.new(ells: selected_ells), - Analyze::Graph::StudentsBySped.new(speds: selected_speds)] - end - - def graph - @graph ||= graphs.reduce(graphs.first) do |acc, graph| - graph.slug == params[:graph] ? graph : acc + def subcategories + @subcategories = category.subcategories.order(:subcategory_id) end - end - def selected_grades - @selected_grades ||= begin - grade_params = params[:grades] - return grades unless grade_params - - grade_params.split(",").map(&:to_i) + def measures + @measures = subcategory.measures.order(:measure_id).includes(%i[admin_data_items subcategory]) end - end - def selected_genders - @selected_genders ||= begin - gender_params = params[:genders] - return genders unless gender_params - - gender_params.split(",").sort.map { |gender| Gender.find_by_designation(gender) }.compact + def academic_years + @academic_years = AcademicYear.order(:range).all end - end - def genders - @genders ||= Gender.all.order(designation: :ASC) - end + def selected_academic_years + @selected_academic_years ||= begin + year_params = params[:academic_years] + return [] unless year_params - def groups - @groups = [Analyze::Group::Ell.new, Analyze::Group::Gender.new, Analyze::Group::Grade.new, Analyze::Group::Income.new, - Analyze::Group::Race.new, Analyze::Group::Sped.new] - end - - def group - @group ||= groups.reduce(groups.first) do |acc, group| - group.slug == params[:group] ? group : acc + year_params.split(",").map { |year| AcademicYear.find_by_range(year) }.compact + end end - end - def slice - @slice ||= slices.reduce(slices.first) do |acc, slice| - slice.slug == params[:slice] ? slice : acc + def races + @races ||= Race.all.order(designation: :ASC) end - end - def slices - source.slices - end + def selected_races + @selected_races ||= begin + race_params = params[:races] + return races unless race_params - def source - @source ||= sources.reduce(sources.first) do |acc, source| - source.slug == params[:source] ? source : acc + race_params.split(",").map { |race| Race.find_by_slug race }.compact + end end - end - def sources - all_data_slices = [Analyze::Slice::AllData.new] - all_data_source = Analyze::Source::AllData.new(slices: all_data_slices) - - students_and_teachers = Analyze::Slice::StudentsAndTeachers.new - students_by_group = Analyze::Slice::StudentsByGroup.new(races:, grades:) - survey_data_slices = [students_and_teachers, students_by_group] - survey_data_source = Analyze::Source::SurveyData.new(slices: survey_data_slices) - - @sources = [all_data_source, survey_data_source] - end - - def grades - @grades ||= SurveyItemResponse.where(school:, academic_year:) - .where.not(grade: nil) - .group(:grade) - .select(:response_id) - .distinct(:response_id) - .count.reject do |_key, value| - value < 10 - end.keys - end - - def incomes - @incomes ||= Income.all - end - - def selected_incomes - @selected_incomes ||= begin - income_params = params[:incomes] - return incomes unless income_params - - income_params.split(",").map { |income| Income.find_by_slug(income) }.compact + def ells + @ells ||= Ell.all.order(slug: :ASC) end - end - def cache_objects - [subcategory, - selected_academic_years, - graph, - selected_races, - selected_grades, - grades, - selected_genders, - genders, - selected_ells, - ells, - selected_speds, - speds] + def selected_ells + @selected_ells ||= begin + ell_params = params[:ells] + return ells unless ell_params + + ell_params.split(",").map { |ell| Ell.find_by_slug ell }.compact + end + end + + def speds + @speds ||= Sped.all.order(id: :ASC) + end + + def selected_speds + @selected_speds ||= begin + sped_params = params[:speds] + return speds unless sped_params + + sped_params.split(",").map { |sped| Sped.find_by_slug sped }.compact + end + end + + def graphs + @graphs ||= [Analyze::Graph::AllData.new, + Analyze::Graph::StudentsAndTeachers.new, + Analyze::Graph::StudentsByRace.new(races: selected_races), + Analyze::Graph::StudentsByGrade.new(grades: selected_grades), + Analyze::Graph::StudentsByGender.new(genders: selected_genders), + Analyze::Graph::StudentsByIncome.new(incomes: selected_incomes), + Analyze::Graph::StudentsByEll.new(ells: selected_ells), + Analyze::Graph::StudentsBySped.new(speds: selected_speds)] + end + + def graph + @graph ||= graphs.reduce(graphs.first) do |acc, graph| + graph.slug == params[:graph] ? graph : acc + end + end + + def selected_grades + @selected_grades ||= begin + grade_params = params[:grades] + return grades unless grade_params + + grade_params.split(",").map(&:to_i) + end + end + + def selected_genders + @selected_genders ||= begin + gender_params = params[:genders] + return genders unless gender_params + + gender_params.split(",").sort.map { |gender| Gender.find_by_designation(gender) }.compact + end + end + + def genders + @genders ||= Gender.all.order(designation: :ASC) + end + + def groups + @groups = [Analyze::Group::Ell.new, + Analyze::Group::Gender.new, + Analyze::Group::Grade.new, + Analyze::Group::Income.new, + Analyze::Group::Race.new, + Analyze::Group::Sped.new] + end + + def group + @group ||= groups.reduce(groups.first) do |acc, group| + group.slug == params[:group] ? group : acc + end + end + + def slice + @slice ||= slices.reduce(slices.first) do |acc, slice| + slice.slug == params[:slice] ? slice : acc + end + end + + def slices + source.slices + end + + def source + @source ||= sources.reduce(sources.first) do |acc, source| + source.slug == params[:source] ? source : acc + end + end + + def sources + all_data_slices = [Analyze::Slice::AllData.new] + all_data_source = Analyze::Source::AllData.new(slices: all_data_slices) + + students_and_teachers = Analyze::Slice::StudentsAndTeachers.new + students_by_group = Analyze::Slice::StudentsByGroup.new(races:, grades:) + survey_data_slices = [students_and_teachers, students_by_group] + survey_data_source = Analyze::Source::SurveyData.new(slices: survey_data_slices) + + @sources = [all_data_source, survey_data_source] + end + + def grades + @grades ||= SurveyItemResponse.where(school:, academic_year:) + .where.not(grade: nil) + .group(:grade) + .select(:response_id) + .distinct(:response_id) + .count.reject do |_key, value| + value < 10 + end.keys + end + + def incomes + @incomes ||= Income.all + end + + def selected_incomes + @selected_incomes ||= begin + income_params = params[:incomes] + return incomes unless income_params + + income_params.split(",").map { |income| Income.find_by_slug(income) }.compact + end + end + + def cache_objects + [subcategory, + selected_academic_years, + graph, + selected_races, + selected_grades, + grades, + selected_genders, + genders, + selected_ells, + ells, + selected_speds, + speds] + end end end end diff --git a/app/presenters/dashboard/analyze/slice/all_data.rb b/app/presenters/dashboard/analyze/slice/all_data.rb index 10137a7..75303e1 100644 --- a/app/presenters/dashboard/analyze/slice/all_data.rb +++ b/app/presenters/dashboard/analyze/slice/all_data.rb @@ -1,16 +1,20 @@ -module Analyze - module Slice - class AllData - def to_s - 'All Data' - end +# frozen_string_literal: true - def slug - 'all-data' - end +module Dashboard + module Analyze + module Slice + class AllData + def to_s + "All Data" + end - def graphs - [Analyze::Graph::AllData.new] + def slug + "all-data" + end + + def graphs + [Analyze::Graph::AllData.new] + end end end end diff --git a/app/presenters/dashboard/analyze/slice/students_and_teachers.rb b/app/presenters/dashboard/analyze/slice/students_and_teachers.rb index 75eb921..923c638 100644 --- a/app/presenters/dashboard/analyze/slice/students_and_teachers.rb +++ b/app/presenters/dashboard/analyze/slice/students_and_teachers.rb @@ -1,16 +1,20 @@ -module Analyze - module Slice - class StudentsAndTeachers - def to_s - 'Students & Teachers' - end +# frozen_string_literal: true - def slug - 'students-and-teachers' - end +module Dashboard + module Analyze + module Slice + class StudentsAndTeachers + def to_s + "Students & Teachers" + end - def graphs - [Analyze::Graph::StudentsAndTeachers.new] + def slug + "students-and-teachers" + end + + def graphs + [Analyze::Graph::StudentsAndTeachers.new] + end end end end diff --git a/app/presenters/dashboard/analyze/slice/students_by_group.rb b/app/presenters/dashboard/analyze/slice/students_by_group.rb index af62be6..6c5790e 100644 --- a/app/presenters/dashboard/analyze/slice/students_by_group.rb +++ b/app/presenters/dashboard/analyze/slice/students_by_group.rb @@ -1,23 +1,28 @@ -module Analyze - module Slice - class StudentsByGroup - attr_reader :races, :grades +# frozen_string_literal: true - def initialize(races:, grades:) - @races = races - @grades = grades - end +module Dashboard + module Analyze + module Slice + class StudentsByGroup + attr_reader :races, :grades - def to_s - 'Students by Group' - end + def initialize(races:, grades:) + @races = races + @grades = grades + end - def slug - 'students-by-group' - end + def to_s + "Students by Group" + end - def graphs - [Analyze::Graph::StudentsByRace.new(races:), Analyze::Graph::StudentsByGrade.new(grades:)] + def slug + "students-by-group" + end + + def graphs + [Analyze::Graph::StudentsByRace.new(races:), + Analyze::Graph::StudentsByGrade.new(grades:)] + end end end end diff --git a/app/presenters/dashboard/analyze/source/all_data.rb b/app/presenters/dashboard/analyze/source/all_data.rb index 7288990..26920e2 100644 --- a/app/presenters/dashboard/analyze/source/all_data.rb +++ b/app/presenters/dashboard/analyze/source/all_data.rb @@ -1,20 +1,24 @@ -module Analyze - module Source - class AllData - attr_reader :slices +# frozen_string_literal: true - include Analyze::Slice +module Dashboard + module Analyze + module Source + class AllData + attr_reader :slices - def initialize(slices:) - @slices = slices - end + include Analyze::Slice - def to_s - 'All Data' - end + def initialize(slices:) + @slices = slices + end - def slug - 'all-data' + def to_s + "All Data" + end + + def slug + "all-data" + end end end end diff --git a/app/presenters/dashboard/analyze/source/survey_data.rb b/app/presenters/dashboard/analyze/source/survey_data.rb index 654020b..967e4ec 100644 --- a/app/presenters/dashboard/analyze/source/survey_data.rb +++ b/app/presenters/dashboard/analyze/source/survey_data.rb @@ -1,20 +1,24 @@ -module Analyze - module Source - class SurveyData - attr_reader :slices +# frozen_string_literal: true - include Analyze::Slice +module Dashboard + module Analyze + module Source + class SurveyData + attr_reader :slices - def initialize(slices:) - @slices = slices - end + include Analyze::Slice - def to_s - 'Survey Data Only' - end + def initialize(slices:) + @slices = slices + end - def slug - 'survey-data-only' + def to_s + "Survey Data Only" + end + + def slug + "survey-data-only" + end end end end diff --git a/app/views/dashboard/analyze/_checkboxes.html.erb b/app/views/dashboard/analyze/_checkboxes.html.erb new file mode 100644 index 0000000..d64d7e6 --- /dev/null +++ b/app/views/dashboard/analyze/_checkboxes.html.erb @@ -0,0 +1,17 @@ +
Select a category & subcategory to analyze measure-level results
+ + diff --git a/app/views/dashboard/analyze/_graph_background.html.erb b/app/views/dashboard/analyze/_graph_background.html.erb new file mode 100644 index 0000000..fca394c --- /dev/null +++ b/app/views/dashboard/analyze/_graph_background.html.erb @@ -0,0 +1,30 @@ +Select a group
+ +<% @presenter.races.each do |race| %> + <%= render(partial: "checkboxes", locals: {id: "race-#{race.slug}", item: race, selected_items: @presenter.selected_races, name: "race", label_text: race.designation}) %> +<% end %> + +<% @presenter.grades.each do |grade| %> + <%= render(partial: "checkboxes", locals: {id: "grade-#{grade}", item: grade, selected_items: @presenter.selected_grades, name: "grade", label_text: grade}) %> +<% end %> + +<% @presenter.genders.each do |gender| %> + <%= render(partial: "checkboxes", locals: {id: "gender-#{gender.designation}", item: gender, selected_items: @presenter.selected_genders, name: "gender", label_text: gender.designation}) %> +<% end %> + +<% @presenter.incomes.each do |income| %> + <%= render(partial: "checkboxes", locals: {id: "income-#{income.slug}", item: income, selected_items: @presenter.selected_incomes, name: "income", label_text: income.label}) %> +<% end %> + +<% @presenter.ells.each do |ell| %> + <%= render(partial: "checkboxes", locals: {id: "ell-#{ell.slug}", item: ell, selected_items: @presenter.selected_ells, name: "ell", label_text: ell.designation}) %> +<% end %> + +<% @presenter.speds.each do |sped| %> + <%= render(partial: "checkboxes", locals: {id: "sped-#{sped.slug}", item: sped, selected_items: @presenter.selected_speds, name: "sped", label_text: sped.designation}) %> +<% end %> diff --git a/app/views/dashboard/analyze/_grouped_bar_chart.html.erb b/app/views/dashboard/analyze/_grouped_bar_chart.html.erb new file mode 100644 index 0000000..47feb8e --- /dev/null +++ b/app/views/dashboard/analyze/_grouped_bar_chart.html.erb @@ -0,0 +1,10 @@ + diff --git a/app/views/dashboard/analyze/_grouped_bar_column.html.erb b/app/views/dashboard/analyze/_grouped_bar_column.html.erb new file mode 100644 index 0000000..3d2b026 --- /dev/null +++ b/app/views/dashboard/analyze/_grouped_bar_column.html.erb @@ -0,0 +1,53 @@ +Measure <%= measure.measure_id %>
+