Files
OJ2/apps/web/src/utils/flowchart.ts
T
xuyueandClaude Opus 5.5 099c6d7ba6 feat(流程图): AI 点评改成拿例子和测试数据在图上走一遍,同一张图不能再原样重交抽等级
原来让 AI 按逻辑 40 / 完整 30 / 规范 20 / 清晰 10 打总分:同一张图交两次能差 35 分
(有一张 C 再交变 S),22% 的提交和上一次一模一样;评语里写 node_9 这种学生看不到的编号。
照画布稿 FlowResFail / FlowResPass:
- AI 拿题目的例子和最多 3 组测试数据,从开始照着图走到结束,逐组说输出什么、对不对、
  最先错在哪个框;全对 A,全对且写法挑不出毛病 S,走对一半以上 B,否则 C
- 结果页签:「3 组走对 2 组」,逐组 ✓ / ✗,点开看「你的图输出 / 应该输出」,画布上按先后
  编号亮出这一组走过的框、错的那个标红;图一改就不亮,载回那一版又能亮
- 画布和上次评完的那张一模一样时「交给 AI 点评」灰掉;后端也兜着:同一道题一模一样的图
  直接照搬上次走例子的结果,不再问 AI
- 题目一组例子、测试数据都没有时退回老的四项分;老提交照旧按四项分显示
- 历次等级、提交列表的胶囊只写等级,不写分数

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 21:08:42 +08:00

38 lines
1.4 KiB
TypeScript

import type { FlowchartCaseReport, FlowchartCaseResult } from "@oj2/contract"
/**
* 读出一次流程图评分里「走例子」的报告(2026-10 起的评法);老提交是四项分,给 null。
*
* 形状真相在写入侧(后端 flowchart/run.ts 的 parseTrace),这里只按约定取、缺了兜底,
* 不做运行时校验(理由见 apps/web/CLAUDE.md「什么该收紧」)。
*/
export function caseReport(details: Record<string, unknown> | null | undefined) {
if (!details || details.version !== 2 || !Array.isArray(details.cases)) return null
const cases = details.cases.map((raw): FlowchartCaseResult => {
const row = (raw ?? {}) as Partial<FlowchartCaseResult>
return {
name: String(row.name ?? ""),
input: String(row.input ?? ""),
expected: String(row.expected ?? ""),
output: String(row.output ?? ""),
ok: row.ok === true,
path: Array.isArray(row.path) ? row.path.map(String) : [],
wrongAt: typeof row.wrongAt === "string" ? row.wrongAt : null,
why: String(row.why ?? ""),
}
})
return {
version: 2,
passed: cases.filter((row) => row.ok).length,
total: cases.length,
cases,
} satisfies FlowchartCaseReport
}
/** 「6 组走对 3 组」「6 组全部走对」 */
export function caseHeadline(report: FlowchartCaseReport) {
return report.passed === report.total
? `${report.total} 组全部走对`
: `${report.total} 组走对 ${report.passed} 组`
}