在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'];
    }
}
乍得·费舍尔

您可以计算候选人获得的权重数量(即您拥有的积分),然后计算可能的总权重(即满分)。

然后,您可以将候选分数除以总分数:

分数=候选人分数/总分数

从那里您可以计算百分比:

百分比=分数* 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;

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在r中使用跨组汇总的加权平均值

来自分类Dev

使用Pandas数据框计算加权平均值

来自分类Dev

使用熊猫/数据框计算加权平均值

来自分类Dev

使用numpy.average的加权平均值

来自分类Dev

使用汇总的加权平均值

来自分类Dev

XSLT计算加权平均值

来自分类Dev

地理加权平均值

来自分类Dev

PyTorch张量的加权平均值

来自分类Dev

取列表的加权平均值

来自分类Dev

多行的SQL加权平均值-

来自分类Dev

如何计算加权平均值?

来自分类Dev

Gnuplot误差加权平均值

来自分类Dev

BigQuery 中的加权平均值

来自分类Dev

不同行的加权平均值

来自分类Dev

POSTGRESQL:加权平均值而不是平均值?

来自分类Dev

在PySpark中计算加权平均值

来自分类Dev

如何获得按列分组的加权平均值

来自分类Dev

python numpy与nans的加权平均值

来自分类Dev

在单个查询中计算加权平均值

来自分类Dev

将加权平均值与合计值相加

来自分类Dev

Postgres(Amazon RDS)如何计算加权平均值

来自分类Dev

多列熊猫群加权平均值

来自分类Dev

我如何计算标题的加权平均值?

来自分类Dev

numpy / python中的加权平均值

来自分类Dev

3 Excel中的可变加权平均值

来自分类Dev

包含特定值的行的熊猫加权平均值

来自分类Dev

如果为负,则为加权平均值

来自分类Dev

在查询中找到加权平均值

来自分类Dev

python中数组的加权平均值