开发者

How can I create a "personality-test" using Rails?

开发者 https://www.devze.com 2023-02-24 07:32 出处:网络
This is both a开发者_开发技巧 request for existing open-source modules, as well as the \"architecture\".The data-gathering part (asking questions) looks like can be done using surveyor or wizard gems.

This is both a开发者_开发技巧 request for existing open-source modules, as well as the "architecture". The data-gathering part (asking questions) looks like can be done using surveyor or wizard gems.

The part I need help on is...how do you "weight" or "score" the answers to come up with the "personality"? For example, Myers-Briggs type tests ask multiple questions and then describe one of 16 personalities.

I want to limit my outcomes to four, but I'm not sure how. The standard "If you scored 10-16, you're a rockstar; if you scored 5-9, go home" I don't think quite works this same way?

This is more of a "design" question, so if there's a better place I can ask it, let me know, but it feels that people may know programmatically how in rails to do this kind of simplified expert-system.


You have four personality types, and each user's test creates a rank for each of these types. (e.g. By the end of the test, the user will have a score of 50 for Type-A, a score for 86 for Type-B, a score of 34 for Type-C, and a score of 60 for Type-D) The user is designated by whichever personality type has the highest score. (e.g. Type-B)

Each question in the personality test is multiple choice. Every answer contributes a certain amount to one or more of the personality types. (e.g. On question 1, an answer of "D" will contribute 5 points to Type-A, 3 points to Type-B, and 0 points to Type-C and Type-D.)

Each answer for each question would have a 4-digit value attribute, indicating how the math on your back end should be carried out. For instance:

<input type="radio" name="question_one" value="5400" />
<input type="radio" name="question_one" value="3211" />
<input type="radio" name="question_one" value="5608" />
<input type="radio" name="question_one" value="9006" />

Here's how you might handle the back end in Ruby on Rails. First, you have a User object named @user, which has four fields, type_a, type_b, type_c, type_d, indicating how well the User aligns with each of the four personality types. In your User model, include a method like this:

def process_answer(value)
  self.type_a += value[0].chr.to_i
  self.type_b += value[1].chr.to_i
  self.type_c += value[2].chr.to_i
  self.type_d += value[3].chr.to_i

In your controller, pass the form data to your User instance:

  @user.process_answer(params[:question_one])

If the user selects the second option for question_one (corresponding to a value of "3211"), then his personality profile will increase 3 pts for type-A, 2 pts for type-B, 1 pt for type-C, and 1 pt for type-D.

0

精彩评论

暂无评论...
验证码 换一张
取 消