VEHwang's picture
Upload CoCogni4D-Bench (questions, media, scripts, render records, code) (part 6)
5afd2f7 verified
Raw History Blame Contribute Delete
3.54 kB
import type {ObserverSplit, ReviewEvent, ScriptReview, SegmentView} from './contract.ts';
import {INTENT_LABELS, STATUS_LABELS} from './visual.ts';
import {arrangementStatus} from './arrangements.ts';
export function groupSituations(planned: ReviewEvent[], situations: ReviewEvent[]) {
const seen = new Set<string>(), groups = new Map<string, ReviewEvent[]>();
for (const event of [...planned, ...situations]) {
if (seen.has(event.id)) continue;
seen.add(event.id);
if (!groups.has(event.kind)) groups.set(event.kind, []);
groups.get(event.kind)!.push(event);
}
return Array.from(groups, ([kind, events]) => ({kind, label: kind, events, count: events.length}));
}
// 右栏的安排清单收全部安排(生成器计划、证据层情形、动作安排),默认只列没生效和偏了的
export const isProblem = (event: ReviewEvent) => ['deviated', 'ineffective'].includes(arrangementStatus(event));
export function arrangementList(review: Pick<ScriptReview, 'planned' | 'situations' | 'actual_arrangements'> | undefined, all: boolean) {
const groups = groupSituations([...(review?.planned || []), ...(review?.actual_arrangements || [])], review?.situations || []);
const total = groups.reduce((n, g) => n + g.count, 0), problems = groups.reduce((n, g) => n + g.events.filter(isProblem).length, 0);
const shown = all ? groups : groups.map(g => ({...g, events: g.events.filter(isProblem)})).map(g => ({...g, count: g.events.length})).filter(g => g.count);
return {groups: shown, total, problems};
}
// 两路 seek 的剧本记着是否按时间错开(segment_conversion.observer_split);各路记的是同一件事,去重后一句
export function splitLine(observers: Record<string, {split?: ObserverSplit}> | undefined): string | null {
const s = (x: number | null | undefined) => x == null ? '?' : x.toFixed(1);
const lines = new Set(Object.values(observers || {}).flatMap(o => !o.split ? [] : [o.split.layer === 'time'
? `按时间错开:${o.split.mover ?? '?'} 两次过门 ${s(o.split.first_s)} s、${s(o.split.second_s)} s,先录的是 ${o.split.early_view ?? '?'}`
: o.split.drawn ? '不错开:抽中了按时间错开,但排不开' : '不错开']));
return lines.size ? '录像' + [...lines].join(';') : null;
}
export type ScriptEvent = ReviewEvent & {statusLabel?: string};
export function entityScript(review: ScriptReview | undefined, intents: SegmentView['intents'], entityId: string): ScriptEvent[] {
const events: ScriptEvent[] = review
? (review.actual_arrangements || []).filter(event => event.entity_ids[0] === entityId)
: (intents[entityId] || []).map(intent => ({
id: `intent-${entityId}-${intent.intent_index}`, kind: INTENT_LABELS[intent.kind] || intent.kind,
label: intent.target?.stop_id || intent.target?.id || intent.target?.region_id || '原地',
entity_ids: [entityId], span_s: [intent.start_s, intent.end_s],
status: 'NOT_CHECKED', statusLabel: STATUS_LABELS[intent.status], source: '原始意图',
basis: intent.discard_reason || intent.reason || '', regions_uv: [],
}));
return [...events].sort((a, b) => (a.span_s?.[0] ?? Infinity) - (b.span_s?.[0] ?? Infinity));
}
export function adjacentEvent(events: ReviewEvent[], selectedId: string | null, direction: -1 | 1): ReviewEvent | null {
if (!events.length) return null;
const index = events.findIndex(event => event.id === selectedId);
return events[index < 0 ? 0 : Math.max(0, Math.min(events.length - 1, index + direction))];
}