From c91558898921c2063762c3b346eaa36a259b6391 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Sat, 8 Feb 2014 15:49:03 -0800 Subject: Changing the scoring process for slider questions. Previously sliders were scored as a value between 1 and 4 based on the percentage across the screen that the slider was slid. This required you to slide fully to the right to get a 4. Now the slider is divided into n sections, where n is the number of answers on the slider. With 4 answers the score will be exactly 1, 2, 3, or 4. With more answers you may get a decimals, but the last section of the slider will always result in a 4. --- src/com/p4square/grow/model/SliderScoringEngine.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/com') diff --git a/src/com/p4square/grow/model/SliderScoringEngine.java b/src/com/p4square/grow/model/SliderScoringEngine.java index 76811b3..2961e95 100644 --- a/src/com/p4square/grow/model/SliderScoringEngine.java +++ b/src/com/p4square/grow/model/SliderScoringEngine.java @@ -15,12 +15,18 @@ public class SliderScoringEngine extends ScoringEngine { @Override public boolean scoreAnswer(Score score, Question question, RecordedAnswer userAnswer) { - float delta = Float.valueOf(userAnswer.getAnswerId()) * 3 + 1; + int numberOfAnswers = question.getAnswers().size(); + if (numberOfAnswers == 0) { + throw new IllegalArgumentException("Question has no answers."); + } - if (delta < 0 || delta > 4) { + double answer = Double.valueOf(userAnswer.getAnswerId()); + if (answer < 0 || answer > 1) { throw new IllegalArgumentException("Answer out of bounds."); } + double delta = Math.max(1, Math.ceil(answer * numberOfAnswers) / numberOfAnswers * 4); + score.sum += delta; score.count++; -- cgit v1.2.3