WIP: 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)
This commit is contained in:
rebuilt 2025-04-15 15:03:32 -07:00
parent a48a2b1d7a
commit 446b3b1096
11 changed files with 182 additions and 23 deletions

19
app/models/housing.rb Normal file
View file

@ -0,0 +1,19 @@
class Housing < ApplicationRecord
has_many :parents, dependent: :nullify
def self.to_designation(housing)
return "Unknown" if housing.blank?
housing = housing
case housing
in /^1$/i
"Own"
in /^2$/i
"Rent"
in /^99$|^100$/i
"Unknown"
else
"Unknown"
end
end
end

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

@ -0,0 +1,30 @@
class Language < ApplicationRecord
scope :by_designation, -> { all.map { |language| [language.designation, language] }.to_h }
has_many :parents, dependent: :nullify
include FriendlyId
friendly_id :designation, use: [:slugged]
def self.to_designation(language)
return "Unknown" if language.blank?
case language
in /^1$|^1[^0]/i
"English"
in /^2$/i
"Portuguese"
in /^3$/i
"Spanish"
in /^99$|^100$/i
"Unknown"
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

@ -1,2 +1,4 @@
class Parent < ApplicationRecord
belongs_to :language, optional: true
belongs_to :housing, optional: true
end

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, language|
SurveyItemResponse.where(survey_item: survey_items, school:,
academic_year:, language:, grade: school.grades(academic_year:)).group(:survey_item).having("count(*) >= 10").average(:likert_score)
}
def self.grouped_responses(school:, academic_year:)
@grouped_responses ||= Hash.new do |memo, (school, academic_year)|
memo[[school, academic_year]] =

View file

@ -0,0 +1,46 @@
module Analyze
module Graph
module Column
module Parent
class Language < ColumnBase
attr_reader :parent
def initialize(parent:)
@parent = parent
end
def label
["#{parent.designation}"]
end
def basis
"parent"
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.where( survey_item: measure.parent_survey_items, school:, academic_year:),
academic_year:).select(:response_id).distinct.count
end
def score(measure:, school:, academic_year:)
Score.new(average: 3,
meets_teacher_threshold: false,
meets_student_threshold:,
meets_admin_data_threshold: false)
end
end
end
end
end

View file

@ -0,0 +1,42 @@
# frozen_string_literal: true
module Analyze
module Graph
class ParentsByLanguage
attr_reader :speds
def initialize(speds:)
@speds = speds
end
def to_s
"Parents by Language"
end
def slug
"parents-by-language"
end
def columns
[].tap do |array|
speds.each do |sped|
array << Analyze::Graph::Column::Sped.new(sped:)
end
array << Analyze::Graph::Column::AllStudent.new
end
end
def source
Analyze::Source::SurveyData.new(slices: nil, graph: self)
end
def slice
Analyze::Slice::StudentsByGroup.new(graph: self)
end
def group
Analyze::Group::Base.new(name: "Special Education", slug: "sped", graph: self)
end
end
end
end

View file

@ -108,6 +108,7 @@ class SurveyResponsesDataLoader
if row.respondent_type == :parent
parent = Parent.find_or_create_by(response_id: row.response_id)
parent.number_of_children = row.number_of_children
parent.language = row.language
parent.save
end