parent
35ac43da10
commit
690f2db863
@ -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
|
||||||
@ -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
|
||||||
Loading…
Reference in new issue