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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue