ECP-201 Add an unknown categories to the parent survey SES filter

main
rebuilt 5 months ago
parent df96f08c12
commit 138c61e7f0

@ -14,8 +14,9 @@ module Analyze
def columns
[].tap do |array|
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: 2, label: ["Medium Advantage"], show_irrelevancy_message: false)
array << Analyze::Graph::Column::Parent::SocioEconomicStatus.new(socio_economic_status: 3, label: ["High Advantage"], show_irrelevancy_message: false)
array << Analyze::Graph::Column::Parent::SocioEconomicStatus.new(socio_economic_status: -1, label: ["Unknown"], show_irrelevancy_message: false)
array << Analyze::Graph::Column::Parent::SocioEconomicStatus.new(socio_economic_status: [0, 1, 2, 3, nil], label: ["All Students"], show_irrelevancy_message: true)
end

@ -2,7 +2,12 @@ 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)
parent.socio_economic_status = if has_all_socio_economic_data?(parent:)
socio_economic_score(parent.education, parent.benefit, parent.employments)
else
-1
end
list << parent
end
end
@ -14,7 +19,18 @@ class SocioEconomicCalculator
)
end
def self.has_all_socio_economic_data?(parent:)
parent.education.present? && parent.education.designation != "Unknown" && parent.benefit.present? && parent.benefit.designation != "Unknown" && parent.employments.any? && parent.employments.any? { |employment| employment.designation != "Unknown" }
end
def self.socio_economic_score(education, benefits, employment)
return -1 if education.designation == "Unknown" || benefits.designation == "Unknown" || employment.empty? || employment.all? { |employment| employment.designation == "Unknown" }
# Calculate the total points from employment, education, and benefits
# Assuming each of these has a method `points` that returns a numeric value
# If any of these are nil, we treat them as 0 points
# Clamp the total points to be between 0 and 1
employment_points = employment.map(&:points).sum.clamp(0, 1)
ed_points = education&.points || 0
benefits_points = benefits&.points || 0

@ -20,6 +20,7 @@ class SurveyResponsesDataLoader
)
end
end
SocioEconomicCalculator.update_socio_economic_scores
end
def from_file(file:)
@ -144,7 +145,6 @@ class SurveyResponsesDataLoader
tmp_employments = row.employments.map { |employment| employments[employment] }.reject(&:nil?)
parent.employments.concat(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

@ -346,9 +346,6 @@ describe SurveyResponsesDataLoader do
it "returns 0 when none of the rubrics meet the standard for higher advantage" do
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 = 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
@ -368,6 +365,20 @@ describe SurveyResponsesDataLoader do
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
it "returns -1 when any aspect of the data is unknown" do
score = SocioEconomicCalculator.socio_economic_score(Education.new(designation: "Associates Degree"), Benefit.new(designation: "Unknown"), [Employment.new(designation: "Two adults with full-time employment")])
expect(score).to eq -1
score = SocioEconomicCalculator.socio_economic_score(Education.new(designation: "Associates Degree"), Benefit.new(designation: "No"), [Employment.new(designation: "Unknown")])
expect(score).to eq -1
score = SocioEconomicCalculator.socio_economic_score(Education.new(designation: "Unknown"), Benefit.new(designation: "No"), [Employment.new(designation: "No full-time or part-time employment")])
expect(score).to eq -1
score = SocioEconomicCalculator.socio_economic_score(Education.new(designation: "Unknown"), Benefit.new(designation: "No"), [])
expect(score).to eq -1
end
end
end

Loading…
Cancel
Save