feat: 升级结构化计分可信度

This commit is contained in:
2026-06-23 02:21:09 +02:00
parent e3825c5a4e
commit ca77aa0896
10 changed files with 705 additions and 139 deletions
+45 -10
View File
@@ -1,39 +1,74 @@
import { AssessmentProfile, AssessmentRecord } from '@/lib/assessment-types';
import { AssessmentProfile, AssessmentRecord, ScoreThreshold } from '@/lib/assessment-types';
function date(value: string) {
return new Date(value).toLocaleString('zh-CN', { hour12: false });
}
function thresholdsToText(thresholds: ScoreThreshold[]) {
if (!thresholds.length) return '无固定阈值';
return thresholds.map((item) => `${item.min} 分起:${item.label}`).join('');
}
function scoreRange(record: AssessmentRecord) {
const { min, max } = record.scoreSummary;
return max === undefined ? `最低 ${min}` : `${min} - ${max}`;
}
export function recordToMarkdown(record: AssessmentRecord, profileName: string) {
const lines = [
`# ${record.questionnaireTitle}测评记录`, '',
`# ${record.questionnaireTitle}测评记录`,
'',
'## 基本信息',
`- 档案:${profileName}`,
`- 档案:${profileName || '未命名档案'}`,
`- 测评时间:${date(record.completedAt)}`,
`- 量表编号:${record.questionnaireId}`,
`- 题目数量:${record.answers.length}`, '',
`- 量表版本${record.questionnaireVersion}`,
`- 计分版本:${record.scoreVersion}`,
`- 题目数量:${record.answers.length}`,
'',
'## 计分规则',
`- 分数范围:${scoreRange(record)}`,
`- 高分含义:${record.scoreSummary.highScoreMeaning}`,
`- 反向题:${record.scoreSummary.reverseItems.length ? record.scoreSummary.reverseItems.join('、') : '无'}`,
`- 临界值:${thresholdsToText(record.scoreSummary.thresholds)}`,
`- 计分状态:${record.scoreSummary.scoringStatus === 'structured' ? '结构化计分' : '原始分保存'}`,
'',
];
if (record.scoreSummary.metrics.length) {
lines.push('## 分数摘要');
record.scoreSummary.metrics.forEach((item) => {
lines.push(`- ${item.label}${item.value}${item.max ? ` / ${item.max}` : ''}${item.level ? `${item.level}` : ''}`);
const range = item.max !== undefined ? ` / ${item.max}` : '';
const level = item.level ? `${item.level}` : '';
lines.push(`- ${item.label}${item.value}${range}${level}`);
});
if (record.scoreSummary.note) lines.push('', record.scoreSummary.note);
lines.push('');
}
if (record.analysisText) lines.push('## 结果说明', record.analysisText, '');
lines.push('## 完整问答');
record.answers.forEach((item, index) => lines.push(`${index + 1}. ${item.question}`, ` 回答:${item.answer}`, ''));
lines.push('## 使用说明', '本记录仅供自我了解、教育和研究参考,不构成医学或心理诊断。');
record.answers.forEach((item, index) => {
lines.push(`${index + 1}. ${item.question}`, ` 回答:${item.answer}`, '');
});
lines.push(
'## 使用说明',
'本记录仅供自我了解、教育和研究参考,不构成医学或心理诊断。',
);
return lines.join('\n');
}
export function profileToMarkdown(profile: AssessmentProfile, records: AssessmentRecord[]) {
const lines = [
`# ${profile.name}的完整测评档案`, '',
`# ${profile.name}的完整测评档案`,
'',
`- 导出时间:${date(new Date().toISOString())}`,
`- 测评次数:${records.length}`, '',
'---', '',
`- 测评次数:${records.length}`,
'',
'---',
'',
];
records
.slice()