diff --git a/app/models/language.rb b/app/models/language.rb index a7c3cbe9..a361ac6e 100644 --- a/app/models/language.rb +++ b/app/models/language.rb @@ -15,8 +15,10 @@ class Language < ApplicationRecord "Portuguese" in /^3$/i "Spanish" - in /^99$|^100$/i - "Unknown" + in /^99$/i + "Prefer not to disclose" + in /|^100$/i + "Prefer to self-describe" else puts "************************************" puts "******** ERROR **********" diff --git a/app/presenters/analyze/graph/column/language.rb b/app/presenters/analyze/graph/column/language.rb new file mode 100644 index 00000000..caa5b1b0 --- /dev/null +++ b/app/presenters/analyze/graph/column/language.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +module Analyze + module Graph + module Column + class Language < ColumnBase + attr_reader :language, :label + + def initialize(languages:, label:) + @language = languages + @label = label + end + + def basis + "parent surveys" + end + + def show_irrelevancy_message?(measure:) + false + end + + def show_insufficient_data_message?(measure:, school:, academic_years:) + false + end + + def type + :parent + end + + def n_size(measure:, school:, academic_year:) + SurveyItemResponse.joins([parent: :languages]).where(languages: { designation: designations }, school:, academic_year:).select(:parent_id).distinct.count + end + + def score(measure:, school:, academic_year:) + average = SurveyItemResponse.joins([parent: :languages]).where(languages: { designation: designations }, school:, academic_year:).average(:likert_score) + + Score.new(average:, + meets_teacher_threshold: false, + meets_student_threshold: true, + meets_admin_data_threshold: false) + end + + def designations + language.map(&:designation) + end + end + end + end +end diff --git a/app/presenters/analyze/graph/parents_by_language.rb b/app/presenters/analyze/graph/parents_by_language.rb index 28ca7aa6..7dde24fd 100644 --- a/app/presenters/analyze/graph/parents_by_language.rb +++ b/app/presenters/analyze/graph/parents_by_language.rb @@ -5,9 +5,10 @@ module Analyze class ParentsByLanguage attr_reader :speds - def initialize(speds:) - @speds = speds - end + ALL_LANGUAGES = Language.all + ENGLISH_LANGUAGES = ALL_LANGUAGES.select { |language| language.designation == "English" } + UNKNOWN_LANGUAGES = ALL_LANGUAGES.select { |language| language.designation == "Prefer not to disclose" } + NON_ENGLISH_LANGUAGES = (ALL_LANGUAGES - ENGLISH_LANGUAGES - UNKNOWN_LANGUAGES) def to_s "Parents by Language" @@ -19,10 +20,9 @@ module Analyze def columns [].tap do |array| - speds.each do |sped| - array << Analyze::Graph::Column::Sped.new(sped:) - end - array << Analyze::Graph::Column::AllStudent.new + array << Analyze::Graph::Column::Language.new(languages: ENGLISH_LANGUAGES, label: ["English", "Speaking"]) + array << Analyze::Graph::Column::Language.new(languages: NON_ENGLISH_LANGUAGES, label: ["Non English", "Speaking"]) + array << Analyze::Graph::Column::Language.new(languages: UNKNOWN_LANGUAGES, label: ["Unknown"]) end end diff --git a/app/presenters/analyze/presenter.rb b/app/presenters/analyze/presenter.rb index d3dde077..b501794c 100644 --- a/app/presenters/analyze/presenter.rb +++ b/app/presenters/analyze/presenter.rb @@ -96,10 +96,14 @@ module Analyze end def groups - @groups = graphs.map(&:group) - .reject { |group| group.name.nil? } - .sort_by { |group| group.name } - .uniq + @groups ||= + begin + selectable_groups = graph.class.name.demodulize.first(4) + graphs.select { |graph| graph.class.name.demodulize.first(4) == selectable_groups }.map(&:group) + .reject { |group| group.name.nil? } + .sort_by { |group| group.name } + .uniq + end end def group @@ -159,7 +163,8 @@ module Analyze Analyze::Graph::StudentsByGender.new(genders: selected_genders), Analyze::Graph::StudentsByIncome.new(incomes: selected_incomes), Analyze::Graph::StudentsBySped.new(speds: selected_speds), - Analyze::Graph::StudentsByEll.new(ells: selected_ells)] + Analyze::Graph::StudentsByEll.new(ells: selected_ells), + Analyze::Graph::ParentsByLanguage.new] end def graph diff --git a/app/views/analyze/_data_filters.html.erb b/app/views/analyze/_data_filters.html.erb index f1eecfa4..a1698a36 100644 --- a/app/views/analyze/_data_filters.html.erb +++ b/app/views/analyze/_data_filters.html.erb @@ -1,32 +1,8 @@