分数计算逻辑

时间:2011-06-07 22:01:15

标签: javascript math logic

this SO question更复杂,我想你的测验得分计算,这是我的情景:

我有X个选项(任何HTML元素都可以作为选项提供),用户可以从中选择一个选项组合作为答案。到目前为止,我试图通过以下方式保持通用:

  • 维护一系列正确答案
  • 通过索引条目将所选答案与正确答案进行比较
  • 如果找到正确的匹配,则将分数增加1
  • 单独处理无线电选项问题,因为它们总是真/假

以下示例:假设选择了6个节点0,1,2正确的分心节点。 'selectedAnswers'是一个包含任何选定干扰物的索引值的数组。 “correctAnswers”是一组预先确定的正确的干扰指数。

// Each option is worth a standardised amount, unless custom weightings
// are required - not implemented.
var weighting = (100/this.distractors.length);
var score = 0;
for(var i=0;i<this.selectedAnswers.length;i++){
  if( ut.arrayContains(this.correctAnswer, this.selectedAnswers[i]) ){
    // Correct answer found, increase total
    score += weighting*2;
  } else {
    if( yd.hasClass(this.distractors[ this.selectedAnswers[i] ], SELECTED_CLASS) ){
      // Penalise the score by a double weightingfor selecting an incorrect answer
      score -= weighting*2;
      //log('reducing score by 2 weightings');
    } else {
      // Penalise the score by a single weighting for leaving an incorrect node unselected
      score -= weighting;
      //log('reducing score by 1 weighting');
    }
  }
}
this.score( (score<0)? 0 : Math.ceil(score) );

当一个选项未被选中时,如果选择它会不正确,那么降低分数似乎是违反直觉的 - 但它似乎让我更接近我所追求的逻辑。事实上,在您考虑选择越来越多不正确的选项和不正确的选项的情况之前,所提供的分数似乎相当准确。

如果必须的话,我会从我们的构建中创建一个演示并将它现场直播,让我知道!


编辑: 呃,对不起,我在想这个问题,问题是:

如何在考虑错误和正确答案的情况下提供准确的百分比?

1 个答案:

答案 0 :(得分:0)

我已经确定了这一点,但我仍然认为它没有足够的理由:

var correctWeighting = 100/this.correctAnswer.length;
var incorrectWeighting = 100/(this.distractors.length-this.correctAnswer.length);
var score = 0;
for(var i=0;i<this.selectedAnswers.length;i++){
    // Scan through all selected distractors and determine if they are in/correct,
    // adjusting the score accordingly
    if( ut.arrayContains(this.correctAnswer, this.selectedAnswers[i]) ){
        score += correctWeighting;
    } else {
        score -= incorrectWeighting;
    }
}

// The score can be calculated to be <0 if there are many incorrect distractors
// selected, which isn't technically wrong (if a bit imprecise?), but a workable
// score should be in the 0-100 range.
this.score( (score<0)? 0 : Math.ceil(score) );

它似乎有效,但是,当选择了许多不正确的答案并且很少或没有正确答案时(分数进入底片)。这可能不够好的一个例子是,如果我有10个左右的选项,其中3个是正确的,我选择了1个正确(+ 34%),其中3个以上被选中但不正确。在这种情况下,合理地说用户的1个正确选择的答案应该至少获得一些功劳是合理的。

我觉得我需要根据围绕“correctWeighting”的某些因素来调整“incorrectWeight”。

相关问题