mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 13:38:18 -08:00
ECP-162 fix benefits so it gets scored correctly
This commit is contained in:
parent
35ac43da10
commit
690f2db863
8 changed files with 44 additions and 24 deletions
|
|
@ -25,7 +25,7 @@ class Benefit < ApplicationRecord
|
|||
end
|
||||
|
||||
def points
|
||||
return 1 if designation == "Yes"
|
||||
return 1 if designation == "No"
|
||||
|
||||
0
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ module Analyze
|
|||
class SocioEconomicStatus < Base
|
||||
attr_reader :socio_economic_status, :label
|
||||
|
||||
def initialize(socio_economic_status:, label:, show_irrelevancy_message:)
|
||||
def initialize(socio_economic_status:, label:, show_irrelevancy_message: false)
|
||||
@socio_economic_status = socio_economic_status
|
||||
@label = label
|
||||
@show_irrelevancy_message = show_irrelevancy_message
|
||||
|
|
|
|||
|
|
@ -13,8 +13,7 @@ module Analyze
|
|||
|
||||
def columns
|
||||
[].tap do |array|
|
||||
array << Analyze::Graph::Column::Parent::SocioEconomicStatus.new(socio_economic_status: 0, label: ["No Advantage"], show_irrelevancy_message: false)
|
||||
array << Analyze::Graph::Column::Parent::SocioEconomicStatus.new(socio_economic_status: 1, label: ["Low Advantage"], show_irrelevancy_message: false)
|
||||
array << Analyze::Graph::Column::Parent::SocioEconomicStatus.new(socio_economic_status: [0, 1], label: ["Low Advantage"], show_irrelevancy_message: false)
|
||||
array << Analyze::Graph::Column::Parent::SocioEconomicStatus.new(socio_economic_status: 2, label: ["Mediumn Advantage"], show_irrelevancy_message: false)
|
||||
array << Analyze::Graph::Column::Parent::SocioEconomicStatus.new(socio_economic_status: 3, label: ["High Advantage"], show_irrelevancy_message: false)
|
||||
|
||||
|
|
|
|||
23
app/services/socio_economic_calculator.rb
Normal file
23
app/services/socio_economic_calculator.rb
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
class SocioEconomicCalculator
|
||||
def self.update_socio_economic_scores
|
||||
parent_list = [].tap do |list|
|
||||
Parent.all.each do |parent|
|
||||
parent.socio_economic_status = socio_economic_score(parent.education, parent.benefit, parent.employments)
|
||||
list << parent
|
||||
end
|
||||
end
|
||||
|
||||
Parent.import(
|
||||
parent_list,
|
||||
batch_size: 500,
|
||||
on_duplicate_key_update: :all
|
||||
)
|
||||
end
|
||||
|
||||
def self.socio_economic_score(education, benefits, employment)
|
||||
employment_points = employment.map(&:points).sum.clamp(0, 1)
|
||||
ed_points = education&.points || 0
|
||||
benefits_points = benefits&.points || 0
|
||||
ed_points + benefits_points + employment_points
|
||||
end
|
||||
end
|
||||
|
|
@ -56,13 +56,6 @@ class SurveyResponsesDataLoader
|
|||
SurveyItemResponse.import(survey_item_responses.compact.flatten, batch_size:, on_duplicate_key_update: :all)
|
||||
end
|
||||
|
||||
def socio_economic_score(education, benefits, employment)
|
||||
employment_points = employment.map(&:points).sum.clamp(0, 1)
|
||||
ed_points = education&.points || 0
|
||||
benefits_points = benefits&.points || 0
|
||||
ed_points + benefits_points + employment_points
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def schools
|
||||
|
|
@ -134,8 +127,7 @@ class SurveyResponsesDataLoader
|
|||
parent = Parent.find_or_create_by(response_id: row.response_id)
|
||||
parent.number_of_children = row.number_of_children
|
||||
parent.education = educations[row.education] if row.education.present?
|
||||
parent.benefits_id = benefits[row.benefits].id if row.benefits.present?
|
||||
|
||||
parent.benefit = benefits[row.benefits] if row.benefits.present?
|
||||
tmp_languages = row.languages.map { |language| languages[language] }.reject(&:nil?)
|
||||
parent.languages.delete_all
|
||||
parent.languages.concat(tmp_languages)
|
||||
|
|
@ -152,7 +144,7 @@ class SurveyResponsesDataLoader
|
|||
tmp_employments = row.employments.map { |employment| employments[employment] }.reject(&:nil?)
|
||||
parent.employments.concat(tmp_employments)
|
||||
|
||||
parent.socio_economic_status = socio_economic_score(educations[row.education], benefits[row.benefits], tmp_employments)
|
||||
parent.socio_economic_status = SocioEconomicCalculator.socio_economic_score(educations[row.education], benefits[row.benefits], tmp_employments)
|
||||
parent.housing = housings[row.housing] if row.housing.present?
|
||||
|
||||
parent.save
|
||||
|
|
|
|||
6
db/migrate/20250704001027_add_benefit_to_parents.rb
Normal file
6
db/migrate/20250704001027_add_benefit_to_parents.rb
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
class AddBenefitToParents < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
remove_reference :parents, :benefits, foreign_key: true
|
||||
add_reference :parents, :benefit, foreign_key: true
|
||||
end
|
||||
end
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[8.0].define(version: 2025_06_30_181104) do
|
||||
ActiveRecord::Schema[8.0].define(version: 2025_07_04_001027) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pg_catalog.plpgsql"
|
||||
|
||||
|
|
@ -190,9 +190,9 @@ ActiveRecord::Schema[8.0].define(version: 2025_06_30_181104) do
|
|||
t.datetime "updated_at", null: false
|
||||
t.bigint "housing_id"
|
||||
t.bigint "education_id"
|
||||
t.bigint "benefits_id"
|
||||
t.integer "socio_economic_status"
|
||||
t.index ["benefits_id"], name: "index_parents_on_benefits_id"
|
||||
t.bigint "benefit_id"
|
||||
t.index ["benefit_id"], name: "index_parents_on_benefit_id"
|
||||
t.index ["education_id"], name: "index_parents_on_education_id"
|
||||
t.index ["housing_id"], name: "index_parents_on_housing_id"
|
||||
end
|
||||
|
|
@ -386,7 +386,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_06_30_181104) do
|
|||
add_foreign_key "parent_languages", "parents"
|
||||
add_foreign_key "parent_races", "parents"
|
||||
add_foreign_key "parent_races", "races"
|
||||
add_foreign_key "parents", "benefits", column: "benefits_id"
|
||||
add_foreign_key "parents", "benefits"
|
||||
add_foreign_key "parents", "educations"
|
||||
add_foreign_key "parents", "housings"
|
||||
add_foreign_key "respondents", "academic_years"
|
||||
|
|
|
|||
|
|
@ -344,28 +344,28 @@ describe SurveyResponsesDataLoader do
|
|||
|
||||
describe ".socio_economic_score" do
|
||||
it "returns 0 when none of the rubrics meet the standard for higher advantage" do
|
||||
score = SurveyResponsesDataLoader.new.socio_economic_score(Education.new(designation: "No formal schooling completed"), Benefit.new(designation: "No"), [Employment.new(designation: "No full-time or part-time employment")])
|
||||
score = SocioEconomicCalculator.socio_economic_score(Education.new(designation: "No formal schooling completed"), Benefit.new(designation: "Yes"), [Employment.new(designation: "No full-time or part-time employment")])
|
||||
expect(score).to eq 0
|
||||
|
||||
score = SurveyResponsesDataLoader.new.socio_economic_score(Education.new(designation: "Unknown"), Benefit.new(designation: "Unknown"), [Employment.new(designation: "Unknown")])
|
||||
score = SocioEconomicCalculator.socio_economic_score(Education.new(designation: "Unknown"), Benefit.new(designation: "Unknown"), [Employment.new(designation: "Unknown")])
|
||||
expect(score).to eq 0
|
||||
end
|
||||
|
||||
it "returns 1 when one of the rubrics meets the standard for higher advantage" do
|
||||
score = SurveyResponsesDataLoader.new.socio_economic_score(Education.new(designation: "Associates Degree"), Benefit.new(designation: "No"), [Employment.new(designation: "No full-time or part-time employment")])
|
||||
score = SocioEconomicCalculator.socio_economic_score(Education.new(designation: "Associates Degree"), Benefit.new(designation: "Yes"), [Employment.new(designation: "No full-time or part-time employment")])
|
||||
expect(score).to eq 1
|
||||
end
|
||||
|
||||
it "returns 2 when two of the rubrics meet the standard for higher advantage" do
|
||||
score = SurveyResponsesDataLoader.new.socio_economic_score(Education.new(designation: "Associates Degree"), Benefit.new(designation: "Yes"), [Employment.new(designation: "No full-time or part-time employment")])
|
||||
score = SocioEconomicCalculator.socio_economic_score(Education.new(designation: "Associates Degree"), Benefit.new(designation: "No"), [Employment.new(designation: "No full-time or part-time employment")])
|
||||
expect(score).to eq 2
|
||||
end
|
||||
|
||||
it "returns 3 when all three of the rubrics meet the standard for higher advantage" do
|
||||
score = SurveyResponsesDataLoader.new.socio_economic_score(Education.new(designation: "Associates Degree"), Benefit.new(designation: "Yes"), [Employment.new(designation: "Two adults with full-time employment")])
|
||||
score = SocioEconomicCalculator.socio_economic_score(Education.new(designation: "Associates Degree"), Benefit.new(designation: "No"), [Employment.new(designation: "Two adults with full-time employment")])
|
||||
expect(score).to eq 3
|
||||
|
||||
score = SurveyResponsesDataLoader.new.socio_economic_score(Education.new(designation: "Associates Degree"), Benefit.new(designation: "Yes"), [Employment.new(designation: "One adult with full-time employment"), Employment.new(designation: "Two adults with full-time employment")])
|
||||
score = SocioEconomicCalculator.socio_economic_score(Education.new(designation: "Associates Degree"), Benefit.new(designation: "No"), [Employment.new(designation: "One adult with full-time employment"), Employment.new(designation: "Two adults with full-time employment")])
|
||||
expect(score).to eq 3
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue