Skip to content

Instantly share code, notes, and snippets.

@zsiec
Created March 21, 2011 21:59
Show Gist options
  • Save zsiec/880308 to your computer and use it in GitHub Desktop.
Save zsiec/880308 to your computer and use it in GitHub Desktop.
def calculate_survey_score(user)
return false if !self.taken?(user)
all_questions = self.questions.order("id ASC").to_a
case self.name
when "Personality"
introvert = 0
extrovert = 0
sensing = 0
intuition = 0
thinking = 0
feeling = 0
judgement = 0
perception = 0
self.answers.where(:user_id => user.id).order("survey_question_id ASC").each do |a|
case a.survey_question_id
#begin introversion
when all_questions[0].id #question 1
introvert += 1 if a.content == "image:thinker"
extrovert += 1 if a.content == "image:monument"
when all_questions[1].id #question 2
introvert += 1 if a.content == "tired"
extrovert += 1 if a.content == "energized"
when all_questions[2].id #question 3
sub_introvert = 0 and sub_extrovert = 0
sub_introvert += 1 if a.content == "image:yoga"
sub_introvert += 1 if a.content == "image:jogging"
sub_introvert += 1 if a.content == "image:tv"
sub_introvert += 1 if a.content == "reading"
sub_extrovert += 1 if a.content == "image:basketballsam1"
sub_extrovert += 1 if a.content == "image:baseball"
sub_extrovert += 1 if a.content == "image:dinner_party"
sub_extrovert += 1 if a.content == "image:bar"
introvert += 1 if sub_introvert >= 2
extrovert += 1 if sub_extrovert >= 2
#begin perceiving
when all_questions[3].id #question 4
sensing += 1 if a.content == "Present"
intuition += 1 if a.content == "Future"
when all_questions[4].id #question 5
sensing += 1 if a.content == "Practicalities"
intuition += 1 if a.content == "Possibilities"
when all_questions[5].id #question 6
sensing += 1 if a.content == "image:cubes"
intuition += 1 if a.content == "image:portrait"
#begin judging
when all_questions[6].id #question 7
thinking += 1 if a.content == "Decide with heart"
feeling += 1 if a.content == "Decide with head"
when all_questions[7].id #question 8
thinking += 1 if a.content == "Fariness"
feeling += 1 if a.content == "Harmony"
when all_questions[8].id #question 9
thinking += 1 if a.content == "image:superman"
feeling += 1 if a.content == "image:batman"
when all_questions[9].id #question 10
thinking += 1 if a.content == "image:abe"
feeling += 1 if a.content == "image:ghandi"
#begin lifestyle
when all_questions[10].id #question 11
judgement += 1 if a.content == "Detailed itinery"
perception += 1 if a.content == "Randomly explore"
when all_questions[11].id #question 12
judgement += 1 if a.content == "Control"
perception += 1 if a.content == "Flexibility"
when all_questions[12].id #question 13
judgement += 1 if a.content == "Structure"
perception += 1 if a.content == "Organized Chaos"
end
end
#introversion calculation
introversion = extrovert > introvert ? "E" : "I"
perceiving = sensing > intuition ? "S" : "N"
judging = thinking > feeling ? "T" : "F"
lifestyle = judgement > perception ? "J" : "P"
return "#{introversion}#{perceiving}#{judging}#{lifestyle}"
else
return false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment