VEHwang's picture
Upload CoCogni4D-Bench (questions, media, scripts, render records, code) (part 4)
9d57416 verified
Raw History Blame Contribute Delete
794 Bytes
import type {MetricUnits, ReviewProgress} from './contract.ts';
export function metric(value: number | null | undefined, field: string, units: MetricUnits): string {
if (value == null) return '本段还没有';
const unit = units[field];
if (!Number.isFinite(value) || !unit) throw Error('指标数值或单位缺失:' + field);
if (unit === 'count') {
if (!Number.isInteger(value)) throw Error('计数不是整数:' + field);
return String(value);
}
return unit === 'ratio' ? (value * 100).toFixed(1) + '%' : value.toFixed(1) + ' s';
}
export function populationText(p: ReviewProgress): string {
if (p.total !== p.generated + p.not_generated) throw Error('批次分母不一致');
return `${p.total} 格:${p.generated} 生成、${p.not_generated} 未生成`;
}