0

First post, so apologize if I have not chosen the best spot for it:

If I had table of values, let's say corresponding to a question number and its corresponding answer, what is the correct way to plan a database to allow users to store formulas to calculate a score based on said answers?

Example:

Let's say I have a table of answer given to a series of questions:

Question_and_answer_table

ID Answer 1 3 2 5 3 7 4 9

Then I have 3 different users, User1, User2, User 3.

If I want each user to be able to define how they want to weigh the answers to determine a final score

ex: User1: A1*3-A2*2+A3*7*A4=SCORE

what's the best way to handle storing a formula for each user?

Thank you for your time and help!

Cheers

asked May 4, 2015 at 18:39
4
  • Will the number of questions always be the same? Commented May 4, 2015 at 19:10
  • Whatever is most convenient for your application language. PHP? Java? Whatever? Commented May 4, 2015 at 21:54
  • @Vérace Thanks for replying. No - this is more of a hypothetical. Was trying to better understand how to build this type interaction so I can expand on it. Commented May 6, 2015 at 22:45
  • 1
    @RickJames - I work mainly with PHP and Mysql. More of a database planning (diagramming) question. Apologies if this was in the wrong place. Commented May 6, 2015 at 22:46

1 Answer 1

1

You can have a table of weights -- that is, an association of user with each question and how much that answer is weighted. Then you can give each user their own weight for each answer.

create table Weights(
 UserID int not null references Users( ID ),
 AnswerID int not null references Answers( ID ),
 Weight int default 1, -- For Ux: Ax * Weight,
 constraint PK_Weights primary key( UserID, AnswerID )
);

I've shown the weight as an integer but you can change that if you want fractional values (A1 * 3.5 + A2 * -2.75 + A3 * 7 + A4 * 3.1415 = SCORE ).

answered May 5, 2015 at 16:28
1
  • Thank you @TommCatt. This was very helpful. Essentially break the weights down by User-and-Answer combo, and call individual weighting when calculating the score. I appreciate your time and help. Cheers. Commented May 6, 2015 at 22:49

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.