0 レビュー
3 回答
PHPの加重平均を使用した評価
このテストをphpで採点するにはどうすればよいですか?パーセンテージスコアが必要です...
正しい/間違ったブール値と対応する重みを含む一連の質問があります。
最初に正解の平均を見つける必要がありますか?
方程式はどうなりますか?
$questions = array(
0=>array(
'Question'=>"Some Question",
'Correct'=>true,
'Weight'=>5,
),
1=>array(
'Question'=>"Some Question",
'Correct'=>false,
'Weight'=>5,
),
2=>array(
'Question'=>"Some Question",
'Correct'=>true,
'Weight'=>4,
),
3=>array(
'Question'=>"Some Question",
'Correct'=>true,
'Weight'=>0,
),
4=>array(
'Question'=>"Some Question",
'Correct'=>false,
'Weight'=>5,
),
5=>array(
'Question'=>"Some Question",
'Correct'=>true,
'Weight'=>4,
),
);
$weights = array(
0=>0
1=>0
2=>.05
3=>.20
4=>.25
5=>.50
);
$totalQuestions=0;
$correctAnswers=0;
$points=0;
foreach($questions as $question){
$totalQuestions++;
if($question['Correct']){
$correctAnswers++;
$points = $points = $weights[$question['Weight'];
}
}
わからない
0
レビュー
答え :
解決策:
候補者が獲得した重みの量(つまり、あなたが持っているポイント)を計算してから、可能な合計の重み(つまり、満点)を計算できます。
次に、候補スコアを合計スコアで割ることができます。
スコア=候補スコア/合計スコア
そこからパーセンテージを計算できます:
パーセンテージ=スコア*100
コードの使用:
$totalQuestions=0; $totalWeights=0; $correctAnswers=0; $weightsEarned=0; foreach($questions as $question){ $totalQuestions++; $totalWeights+=$weights[$question['Weight']]; if($question['Correct']){ $correctAnswers++; $weightsEarned += $weights[$question['Weight']]; } } echo "Score Overview: "; echo "<br/>Weights Earned: " . $weightsEarned; echo "<br/>Correct Answers: " . $correctAnswers; echo "<br/>Total Weights Possible : " . $totalWeights; echo "<br/>Percentage Earned: " . ($weightsEarned / $totalWeights) * 100;
わからない
0
レビュー
答え :
解決策:
通常、平均(加重されているかどうかに関係なく)は、考えられるものの合計に対するものの合計です。重み付けされている場合、これは通常、各ものが1つではなく、実際には weightOfThing
のものであることを意味します。
例:
$totalQuestions = count($questions); //No need to increment
$totalWeight = 0; //Could do a sum here but no need
$weightedSum = 0;
foreach($questions as $question){
$totalWeight += isset($question["Weight"])?$question["Weight"]:0; //Assume a question with no weight has 0 weight, i.e., doesn't count. Adjust accordingly
if($question['Correct']){
$weightedSum += isset($question["Weight"])?$question["Weight"]:0;
}
}
$weightedAverage = $weightedSum / $totalWeight;
わからない
0
レビュー
答え :
解決策:
最適化できますが、完成した方程式は次のとおりです:
$weights = array(
0=>0,
1=>0,
2=>.05,
3=>.20,
4=>.25,
5=>.50,
);
$byWeight = array();
foreach($questions as $question){
//$totalQuestions++;
$byWeight[$question['Weight']]['TotalNumberOfQuestionsForWeight']++;
if($question['Correct']){
$byWeight[$question['Weight']]['CorrectAnswers']++;
}
}
$totalWeightsSum = 0;
foreach($byWeight as $weight => $data){
$totalWeightsSum = $totalWeightsSum + (($data['CorrectAnswers'] / $data['TotalNumberOfQuestionsForWeight']) * $weights[$weight]);
}
echo '<pre>'.var_export($byWeight,1).'</pre>';
echo $totalWeightsSum / array_sum($weights);
わからない
同様の質問
私たちのウェブサイトで同様の質問で答えを見つけてください。