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.main-eol
parent
bedab713af
commit
0f457becf0
@ -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
|
||||
@ -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
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
class ParentLanguage < ApplicationRecord
|
||||
belongs_to :parent
|
||||
belongs_to :language
|
||||
end
|
||||
@ -0,0 +1,60 @@
|
||||
# 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 }, survey_item: measure.parent_survey_items, school:, academic_year:).select(:parent_id).distinct.count
|
||||
end
|
||||
|
||||
def score(measure:, school:, academic_year:)
|
||||
return Score::NIL_SCORE if n_size(measure:, school:, academic_year:) < 10
|
||||
|
||||
averages = SurveyItemResponse.averages_for_language(measure.parent_survey_items, school, academic_year,
|
||||
designations)
|
||||
average = bubble_up_averages(measure:, averages:).round(2)
|
||||
Score.new(average:,
|
||||
meets_teacher_threshold: false,
|
||||
meets_student_threshold: true,
|
||||
meets_admin_data_threshold: false)
|
||||
end
|
||||
|
||||
def designations
|
||||
language.map(&:designation)
|
||||
end
|
||||
|
||||
def bubble_up_averages(measure:, averages:)
|
||||
measure.parent_scales.map do |scale|
|
||||
scale.survey_items.map do |survey_item|
|
||||
averages[survey_item]
|
||||
end.remove_blanks.average
|
||||
end.remove_blanks.average
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,43 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Analyze
|
||||
module Graph
|
||||
class ParentsByLanguage
|
||||
attr_reader :speds
|
||||
|
||||
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"
|
||||
end
|
||||
|
||||
def slug
|
||||
"parents-by-language"
|
||||
end
|
||||
|
||||
def columns
|
||||
[].tap do |array|
|
||||
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"])
|
||||
array << Analyze::Graph::Column::Language.new(languages: ALL_LANGUAGES, label: ["All", "Parents"])
|
||||
end
|
||||
end
|
||||
|
||||
def source
|
||||
Analyze::Source::SurveyData.new(slices: nil, graph: self)
|
||||
end
|
||||
|
||||
def slice
|
||||
Analyze::Slice::ParentsByGroup.new(graph: self)
|
||||
end
|
||||
|
||||
def group
|
||||
Analyze::Group::Base.new(name: "Language", slug: "language", graph: self)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,9 @@
|
||||
module Analyze
|
||||
module Slice
|
||||
class ParentsByGroup < Base
|
||||
def initialize(graph:, label: "Parents by Group", slug: "parents-by-group")
|
||||
super(label:, slug:, graph:)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,5 @@
|
||||
class AddHousingToParent < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
add_reference :parents, :housing, foreign_key: true
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,10 @@
|
||||
class CreateLanguages < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
create_table :languages do |t|
|
||||
t.string :designation
|
||||
t.string :slug
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,12 @@
|
||||
class CreateParentLanguages < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
create_table :parent_languages do |t|
|
||||
t.references :parent, null: false, foreign_key: true
|
||||
t.references :language, null: false, foreign_key: true
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :parent_languages, %i[parent_id language_id]
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,5 @@
|
||||
class AddDesignationIndexToLanguage < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
add_index :languages, %i[designation]
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,5 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Language, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
@ -0,0 +1,5 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ParentLanguage, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
Loading…
Reference in new issue