<?php
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* ScoreResult.php
|
|
* Created by PhpStorm.
|
|
* Date: 2026/10/17
|
|
* Time: 09:40
|
|
* Author: qian.guo
|
|
* E-mail: yiyezhiqiutel@gmail.com
|
|
*/
|
|
|
|
namespace app\service\score;
|
|
|
|
/**
|
|
* 评分输出
|
|
* 设计说明:
|
|
* - 多策略的统一契约:任何策略返回的结构必须与本类完全同构
|
|
* 否则前端渲染、报告文案查表、结果落库三处会分别崩在不同地方
|
|
* 这条由 ScoreEngineTest 的契约测试守住
|
|
* - radar 与 functions 是两张不同的图,前端不要混用
|
|
* radar :各极点强度,环形分布,看整体形状
|
|
* functions :各认知功能强度,线性排布,看功能优先级次序
|
|
*/
|
|
class ScoreResult
|
|
{
|
|
// 类型码,如 INFP
|
|
public $type_code = '';
|
|
|
|
// 类型名称
|
|
public $type_name = '';
|
|
|
|
// 各极点得分,键为极点码
|
|
public $dimension_scores = [];
|
|
|
|
// 各轴判定结果,键为轴码
|
|
public $axes = [];
|
|
|
|
// 雷达图数据(4 轴 8 极)
|
|
public $radar = [];
|
|
|
|
// 认知功能数据(荣格八维线图),未配置时为空数组
|
|
public $functions = [];
|
|
|
|
// 置信度 0..100
|
|
public $confidence = 0;
|
|
|
|
// 综合评分 0..100,语义是「结果清晰度」不是能力高低
|
|
public $match_score = 0;
|
|
|
|
// 关键词
|
|
public $keywords = [];
|
|
|
|
// 策略名
|
|
public $strategy = '';
|
|
|
|
// 策略版本
|
|
public $strategy_version = '';
|
|
|
|
// 中间量,仅调试模式填充
|
|
public $debug = [];
|
|
|
|
public function __construct($param)
|
|
{
|
|
$this->type_code = (string) ($param['type_code'] ?? '');
|
|
$this->type_name = (string) ($param['type_name'] ?? '');
|
|
$this->dimension_scores = (array) ($param['dimension_scores'] ?? []);
|
|
$this->axes = (array) ($param['axes'] ?? []);
|
|
$this->radar = (array) ($param['radar'] ?? []);
|
|
$this->functions = (array) ($param['functions'] ?? []);
|
|
$this->confidence = intval($param['confidence'] ?? 0);
|
|
$this->match_score = intval($param['match_score'] ?? 0);
|
|
$this->keywords = (array) ($param['keywords'] ?? []);
|
|
$this->strategy = (string) ($param['strategy'] ?? '');
|
|
$this->strategy_version = (string) ($param['strategy_version'] ?? '');
|
|
$this->debug = (array) ($param['debug'] ?? []);
|
|
}
|
|
|
|
/**
|
|
* 是否含倾向不显著的轴
|
|
* checkMiddleAxis
|
|
* @return bool 前端据此决定是否展示「倾向不显著」提示
|
|
*/
|
|
public function checkMiddleAxis()
|
|
{
|
|
foreach ($this->axes as $axis) {
|
|
if (!empty($axis['is_middle'])) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* 是否含认知功能数据
|
|
* checkFunctions
|
|
* @return bool false 时前端不出线图
|
|
*/
|
|
public function checkFunctions()
|
|
{
|
|
if (empty($this->functions)) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 获取对外数据结构
|
|
* getData
|
|
* @param bool $with_debug 是否附带中间量
|
|
* @return array
|
|
*
|
|
* 新增字段只能追加,不得改名或删字段:前端与落库都按这个结构对齐
|
|
*/
|
|
public function getData($with_debug = false)
|
|
{
|
|
$data = [];
|
|
$data['type_code'] = $this->type_code;
|
|
$data['type_name'] = $this->type_name;
|
|
$data['dimension_scores'] = $this->dimension_scores;
|
|
$data['axes'] = $this->axes;
|
|
$data['radar'] = $this->radar;
|
|
$data['functions'] = $this->functions;
|
|
$data['confidence'] = $this->confidence;
|
|
$data['match_score'] = $this->match_score;
|
|
$data['keywords'] = $this->keywords;
|
|
$data['has_middle_axis'] = $this->checkMiddleAxis();
|
|
$data['has_functions'] = $this->checkFunctions();
|
|
$data['strategy'] = $this->strategy;
|
|
$data['strategy_version'] = $this->strategy_version;
|
|
|
|
if ($with_debug) {
|
|
$data['debug'] = $this->debug;
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
}
|