Files
InfoRSI/eval/lib/reference-scores.ts
T
iomgaa b7be524cdc eval: 准备正向采纳的真实运行恢复与质量评估
新增单份串行启动入口、首个正向运行杀进程恢复证据、逐候选审阅导出与账目统计;参考只读副本分数对照。456项免费测试通过,尚未启动三份真实验收。同步结构说明与当前工作状态。
2026-10-04 04:25:00 -04:00

71 lines
2.2 KiB
TypeScript

import { basename, dirname } from "node:path";
import { DatabaseSync } from "node:sqlite";
/** 只读已有副本;保留 incomplete 的数值及重复尝试,不冒充有效成绩。 */
export function referenceScores(path: string) {
const study = basename(dirname(path));
const db = new DatabaseSync(path, { readOnly: true });
try {
type Fact<T> = { seq: number; content: T };
const facts = <T>(kind: string): Fact<T>[] =>
(
db
.prepare(
"SELECT created_seq, payload FROM facts WHERE kind = ? ORDER BY created_seq",
)
.all(kind) as Array<{ created_seq: number; payload: string }>
).map((r) => ({
seq: r.created_seq,
content: JSON.parse(r.payload) as T,
}));
const links = facts<{
purpose: string;
roundId: string;
runId: string;
candidateId: string;
}>("run-link");
const observations = facts<{
runId: string;
status: string;
finalMetric: { value: number | null };
reasons: string[];
}>("run-observation");
const adoption = facts<{
roundId: string;
adoptedRunId: string | null;
newBaselineId: string;
}>("adoption").find((r) => r.content.roundId === `${study}.r1`)!;
return links
.filter(
(r) =>
r.content.purpose === "forward" &&
r.content.roundId === `${study}.r1`,
)
.map((link) => {
const observation = observations.find(
(r) => r.content.runId === link.content.runId,
)!;
return {
source: path,
study,
candidate: link.content.candidateId,
run: link.content.runId,
status: observation.content.status,
rawScore: observation.content.finalMetric.value,
validScore:
observation.content.status === "valid"
? observation.content.finalMetric.value
: null,
adopted: adoption.content.adoptedRunId === link.content.runId,
newBaseline: adoption.content.newBaselineId,
linkSeq: link.seq,
observationSeq: observation.seq,
adoptionSeq: adoption.seq,
reasons: observation.content.reasons,
};
});
} finally {
db.close();
}
}