<?php
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* AveragePctStrategy.php
|
|
* Created by PhpStorm.
|
|
* Date: 2026/10/17
|
|
* Time: 09:40
|
|
* Author: qian.guo
|
|
* E-mail: yiyezhiqiutel@gmail.com
|
|
*/
|
|
|
|
namespace app\service\score\strategy;
|
|
|
|
use app\service\score\AbstractScoreStrategy;
|
|
use app\service\score\ScoreContext;
|
|
|
|
/**
|
|
* 均分百分比制
|
|
* 设计说明:
|
|
* - 与累加制的差别只在归一化:不去比两极的总分,而是把每题换算成百分比后逐题取平均
|
|
* 让每道题的说话分量相同
|
|
* - 什么时候必须用它:两极题量不等,或题目分值不一时
|
|
* 举例:E 极有 9 道题、I 极有 6 道题,累加制下 E 的满分天然高 50%
|
|
* 即使用户全部选 I,E 的百分比也会被分母拉高,对偶轴比较直接失真
|
|
* - 当前题库两极题量相等(每轴 15 题、两极各占一半),所以与累加制结果一致
|
|
* 这是题库的对称性给的,不是算法给的。一旦题量失衡,本策略才是安全选择
|
|
*/
|
|
class AveragePctStrategy extends AbstractScoreStrategy
|
|
{
|
|
/**
|
|
* 获取策略标识
|
|
* getName
|
|
* @return string
|
|
*/
|
|
public function getName()
|
|
{
|
|
return 'average_pct';
|
|
}
|
|
|
|
/**
|
|
* 获取策略版本
|
|
* getVersion
|
|
* @return string
|
|
*/
|
|
public function getVersion()
|
|
{
|
|
return '1.0.0';
|
|
}
|
|
|
|
/**
|
|
* 归一化为百分比(逐题取平均)
|
|
* normalize
|
|
* @param array $agg_data 聚合结果
|
|
* @param ScoreContext $context 评分输入
|
|
* @return array 键为极点码,值 0..100
|
|
*/
|
|
protected function normalize($agg_data, ScoreContext $context)
|
|
{
|
|
$pct_list = [];
|
|
|
|
foreach ($context->pole_list as $pole_code => $pole_info) {
|
|
$score_sum = 0.0;
|
|
$count = 0;
|
|
|
|
$part_list = [];
|
|
if (!empty($agg_data['part_list'][$pole_code])) {
|
|
$part_list = $agg_data['part_list'][$pole_code];
|
|
}
|
|
|
|
foreach ($part_list as $part) {
|
|
$score = $part[0];
|
|
$q_max = $part[1];
|
|
|
|
// 该题对此极点无信息量,不参与平均,避免拉低均值
|
|
if ($q_max <= 0) {
|
|
continue;
|
|
}
|
|
|
|
$score_sum += $score / $q_max * 100;
|
|
$count++;
|
|
}
|
|
|
|
$pct = 0.0;
|
|
if ($count > 0) {
|
|
$pct = $score_sum / $count;
|
|
}
|
|
|
|
$pct_list[$pole_code] = $pct;
|
|
}
|
|
|
|
return $pct_list;
|
|
}
|
|
}
|