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; } }