feat: create a parents by language graph

Update demographics table with lanugage options

Create a lanugage table to hold the new languages

Update the demographic loader to input languages into the database

Update the cleaner to read the language column

Update the parent table to hold a reference to a language

Update the data uploader script to read the language from the csv and update the language information for any parent items that already exist (or create database entries if none already exist)

update the analyze interface to add controls for selecting ‘parents by group’ and a dropdown for ‘parent by language’

Update the analyze controller to read the parent-by-group parameter

Create a graph for the parent-by-group view

Bubble up averages for language calculations.

Make sure n-size only counts responses for a given measure.
This commit is contained in:
rebuilt 2025-04-11 14:37:18 -07:00
parent bedab713af
commit 0f457becf0
31 changed files with 413 additions and 109 deletions

View file

@ -1,4 +1,7 @@
class Housing < ApplicationRecord
has_many :parents, dependent: :nullify
scope :by_designation, -> { all.map { |housing| [housing.designation, housing] }.to_h }
def self.to_designation(housing)
return "Unknown" if housing.blank?

33
app/models/language.rb Normal file
View file

@ -0,0 +1,33 @@
class Language < ApplicationRecord
scope :by_designation, -> { all.map { |language| [language.designation, language] }.to_h }
has_many :parent_languages, dependent: :destroy
has_many :parents, through: :parent_languages, dependent: :nullify
include FriendlyId
friendly_id :designation, use: [:slugged]
def self.to_designation(language)
return "Prefer not to disclose" if language.blank?
case language
in /^1$/i
"English"
in /^2$/i
"Portuguese"
in /^3$/i
"Spanish"
in /^99$/i
"Prefer not to disclose"
in /|^100$/i
"Prefer to self-describe"
else
puts "************************************"
puts "******** ERROR **********"
puts ""
puts "Error parsing Language column. '#{language}' is not a known value. Halting execution"
puts ""
puts "************************************"
exit
end
end
end

View file

@ -51,6 +51,10 @@ class Measure < ActiveRecord::Base
@student_scales ||= scales.student_scales
end
def parent_scales
@parent_scales ||= scales.parent_scales
end
def includes_teacher_survey_items?
@includes_teacher_survey_items ||= teacher_survey_items.length.positive?
end

View file

@ -1,2 +1,5 @@
class Parent < ApplicationRecord
belongs_to :housing, optional: true
has_many :parent_languages
has_and_belongs_to_many :languages, join_table: :parent_languages
end

View file

@ -0,0 +1,4 @@
class ParentLanguage < ApplicationRecord
belongs_to :parent
belongs_to :language
end

View file

@ -21,15 +21,11 @@ module Report
Thread.new do
while measure = jobs.pop(true)
academic_years.each do |academic_year|
all_grades = Set.new
respondents = Respondent.where(school: schools, academic_year:)
respondents.each do |respondent|
respondent.enrollment_by_grade.keys.each do |grade|
all_grades.add(grade)
end
end
all_grades = all_grades.to_a
enrollment = respondents.map do | respondent| respondent.enrollment_by_grade.keys end.flatten.compact.uniq.sort
grades_with_responses = ::SurveyItemResponse.where(school: schools, academic_year:).where.not(grade: nil).pluck(:grade).uniq.sort
all_grades = (enrollment & grades_with_responses).sort
grades = "#{all_grades.first}-#{all_grades.last}"
begin_date = ::SurveyItemResponse.where(school: schools,

View file

@ -10,9 +10,9 @@ class Sped < ApplicationRecord
case sped
in /active|^A$|1|^Special\s*Education$/i
"Special Education"
in %r{^I$|exited|0|^Not\s*Special\s*Education$|Does\s*not\s*apply|Referred|Ineligible|^No\s*special\s*needs$|Not\s*SPED|^#*N/*A$}i
in /^I$|exited|0|^Not\s*Special\s*Education$|Does\s*not\s*apply|Referred|Ineligible|^No\s*special\s*needs$|Not\s*SPED/i
"Not Special Education"
in /^Unknown|^SpecialEdStatus|^SPED/i
in %r{^#*N/*A$|^Unknown|^SpecialEdStatus|^SPED}i
"Unknown"
else
puts "************************************"

View file

@ -51,6 +51,10 @@ class SurveyItemResponse < ActiveRecord::Base
).where("student_races.race_id": race.id).group(:survey_item).having("count(*) >= 10").average(:likert_score)
}
scope :averages_for_language, lambda { |survey_items, school, academic_year, designations|
SurveyItemResponse.joins([parent: :languages]).where(languages: { designation: designations }, survey_item: survey_items, school:, academic_year:).group(:survey_item).average(:likert_score)
}
def self.grouped_responses(school:, academic_year:)
@grouped_responses ||= Hash.new do |memo, (school, academic_year)|
memo[[school, academic_year]] =