mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-09 07:28:41 -07:00
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:
parent
a48a2b1d7a
commit
446b3b1096
11 changed files with 182 additions and 23 deletions
19
app/models/housing.rb
Normal file
19
app/models/housing.rb
Normal 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
30
app/models/language.rb
Normal 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
|
||||
|
|
@ -1,2 +1,4 @@
|
|||
class Parent < ApplicationRecord
|
||||
belongs_to :language, optional: true
|
||||
belongs_to :housing, optional: true
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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]] =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue