Instantly share code, notes, and snippets.
Created
September 14, 2017 17:29
-
Save zackster/ac3bca42c441f16cbf2b4895fdbb2abb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Authoritarianism < ActiveRecord::Base | |
belongs_to :potential_juror | |
def score | |
(demographic_structure_calc + occupation_calc + education_calc + marital_status_calc + focused_calc) / 5.0 | |
end | |
private | |
def demographic_structure_calc | |
if self.sex == 'male' | |
if self.race == 'black' | |
return 0 | |
elsif self.race == 'hispanic' | |
return 3 | |
else | |
if self.age == 'age_30_39' || self.age == 'age_40_plus' | |
return 92 | |
elsif self.age == 'age_18_29' | |
return 66 | |
end | |
end | |
else # female | |
if self.race == 'black' | |
return 0 | |
elsif self.race == 'hispanic' | |
return 19 | |
else | |
if self.age == 'age_18_29' | |
return 50 | |
elsif self.age == 'age_30_39' | |
return 76 | |
elsif self.age == 'age_40_plus' | |
return 94 | |
end | |
end | |
end | |
raise "Bad demographic value: age #{self.age} sex #{self.sex} race #{self.race}" | |
end | |
def occupation_calc | |
if self.sex == 'male' | |
if ['Truck Driver', 'Carpenter', 'Craftsman', 'Electrician', 'Police', 'Foreperson', 'Insurance', 'Farmer'].include? self.occupation | |
return 100 | |
elsif self.occupation == 'Self Employed' | |
return 95 | |
elsif self.occupation == 'Clerical' | |
return 90 | |
elsif self.occupation == 'Engineer' | |
return 89 | |
elsif self.occupation == 'Mechanic' | |
return 88 | |
elsif self.occupation == 'Transporation Operator' | |
return 87 | |
elsif self.occupation == 'Sales' | |
return 86 | |
elsif self.occupation == 'Protect Service' | |
return 85 | |
elsif self.occupation == 'Operative' | |
return 84 | |
elsif self.occupation == 'Retired' | |
return 83 | |
elsif self.occupation == 'Manager' | |
return 82 | |
elsif self.occupation == 'Secondary School Teacher' | |
return 71 | |
elsif self.occupation == 'Laborer' | |
return 68 | |
elsif self.occupation == 'Accountant' | |
return 64 | |
elsif self.occupation == 'Assembler' | |
return 62 | |
elsif self.occupation == 'Technician' | |
return 61 | |
elsif self.occupation == 'Guard' | |
return 59 | |
elsif self.occupation == 'Machine Operator' | |
return 39 | |
elsif self.occupation == 'Cleaner' | |
return 38 | |
elsif self.occupation == 'Physician' | |
return 37 | |
elsif self.occupation == 'Profession' | |
return 32 | |
elsif self.occupation == 'Service Industry' | |
return 29 | |
elsif self.occupation == 'Computer Specialist' | |
return 28 | |
elsif self.occupation == 'Farm Labor' | |
return 21 | |
elsif self.occupation == 'Unemployed' | |
return 18 | |
elsif self.occupation == 'Cook' | |
return 6 | |
elsif ['Attorney', 'Student', 'Expressive'].include? self.occupation | |
return 0 | |
end | |
else # female | |
if ['Hairdresser', 'Machine Operator', 'Packer', 'Bookkeeper', 'Real Estate','Retail Manager', 'Restaurant Manager', 'Banker', 'Accountant', 'Manager'].include? self.occupation | |
return 100 | |
elsif self.occupation == 'Self Employed' | |
return 92 | |
elsif self.occupation == 'Office Manager' | |
return 89 | |
elsif self.occupation == 'Clerical' | |
return 85 | |
elsif self.occupation == 'Cashier' | |
return 84 | |
elsif self.occupation == 'Sales' | |
return 82 | |
elsif self.occupation == 'Secretary' | |
return 81 | |
elsif self.occupation == 'Laborer' | |
return 80 | |
elsif self.occupation == 'Sewer' | |
return 79 | |
elsif self.occupation == 'Nurse' | |
return 78 | |
elsif self.occupation == 'Craft' | |
return 71 | |
elsif self.occupation == 'Retired' | |
return 68 | |
elsif self.occupation == 'Homemaker' | |
return 66 | |
elsif self.occupation == 'Student' | |
return 65 | |
elsif self.occupation == 'Technician' | |
return 61 | |
elsif self.occupation == 'Operative' | |
return 57 | |
elsif self.occupation == 'Elementary School Teacher' | |
return 54 | |
elsif self.occupation == 'Profession' | |
return 50 | |
elsif self.occupation == 'Assembler' | |
return 49 | |
elsif self.occupation == 'Waitress' | |
return 41 | |
elsif self.occupation == 'Service' | |
return 31 | |
elsif self.occupation == 'Cleaner' | |
return 30 | |
elsif self.occupation == 'Unemployed' | |
return 24 | |
elsif self.occupation == 'Secondary School Teacher' | |
return 22 | |
elsif self.occupation == 'Nurse Aid' | |
return 16 | |
elsif self.occupation == 'Cook' | |
return 15 | |
elsif self.occupation == 'Maid' | |
return 7 | |
elsif ['Expressive', 'Computer Specialist', 'Social Work'].include? self.occupation | |
return 0 | |
end | |
end | |
raise "Bad occupation value | occupation: #{self.occupation}" | |
end | |
def education_calc | |
if self.sex == 'male' | |
if self.race == 'black' | |
return 0 | |
end | |
case self.education | |
when 'high_school' | |
return 100 | |
when 'some_college' | |
return 90 | |
when 'high_school_dropout' | |
return 84 | |
when 'college' | |
return 58 | |
when 'advanced' | |
return 10 | |
end | |
else # female | |
if self.race == 'black' | |
return 0 | |
end | |
case self.education | |
when 'high_school' | |
return 100 | |
when 'some_college' | |
return 87 | |
when 'high_school_dropout' | |
return 70 | |
when 'college' | |
return 45 | |
when 'advanced' | |
return 0 | |
end | |
end | |
raise "Bad education value | #{self.education}" | |
end | |
def marital_status_calc | |
if self.sex == 'male' | |
if self.race == 'black' | |
if self.marital_status == 'widowed' | |
return 8 | |
else | |
return 0 | |
end | |
end | |
case self.marital_status | |
when 'married' | |
return 100 | |
when 'divorced' | |
return 92 | |
when 'widowed' | |
return 82 | |
when 'never_married' | |
return 46 | |
when 'separated' | |
return 25 | |
end | |
else #female | |
if self.race == 'black' | |
return 0 | |
end | |
case self.marital_status | |
when 'married' | |
return 96 | |
when 'divorced' | |
return 69 | |
when 'widowed' | |
return 80 | |
when 'never_married' | |
return 26 | |
when 'separated' | |
return 41 | |
end | |
end | |
raise "Bad marital status value | #{self.marital_status}" | |
end | |
def focused_calc | |
if self.sex == 'male' | |
if self.religion == 'jewish' | |
return 0 | |
elsif self.political == 'republican' | |
return 100 | |
elsif self.religion == 'methodist' | |
return 99 | |
elsif self.religion == 'lutheran' | |
return 95 | |
end | |
else | |
if self.political == 'republican' | |
return 100 | |
elsif self.religion == 'lutheran' | |
return 97 | |
elsif self.religion == 'methodist' | |
return 89 | |
end | |
end | |
raise 'Bad focused calculation value' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment