Datasets:
Download code/evaluation-code/ent400-a06a1576/apps/console/web/src/App.tsx from VEHwang/cocogni4d: direct link, hf CLI and curl.
- Browser
- Download file 7.98 kB
-
https://huggingface.co/datasets/VEHwang/cocogni4d/resolve/main/code/evaluation-code/ent400-a06a1576/apps/console/web/src/App.tsx
- Command line
-
hf download hf://datasets/VEHwang/cocogni4d/code/evaluation-code/ent400-a06a1576/apps/console/web/src/App.tsx
-
curl -L -o App.tsx https://huggingface.co/datasets/VEHwang/cocogni4d/resolve/main/code/evaluation-code/ent400-a06a1576/apps/console/web/src/App.tsx
7.98 kB
| import {errorText, durationTier} from './text.ts'; | |
| import {CONCLUSION_LABELS} from './visual.ts'; | |
| import { useEffect, useState } from 'react'; | |
| import { getSegment, getSegments } from './api.ts'; | |
| import type { SegmentSummary } from './api.ts'; | |
| import type { SegmentView, RenderMedia } from './contract.ts'; | |
| import {getJSON, prefetchJSON} from './api.ts'; | |
| import { parseRoute, segmentHash } from './route.ts'; | |
| import { Review } from './Review.tsx'; | |
| import {TopBar} from './TopBar.tsx'; | |
| import {GenerationConfig} from './GenerationConfig.tsx'; | |
| import {Verification} from './Verification.tsx'; | |
| import {GenerationResult} from './GenerationResult.tsx'; | |
| // Start independent route data before mounting the page components. | |
| const firstRoute = parseRoute(location.hash); | |
| prefetchJSON('/api/v1/np/result'); | |
| if (firstRoute.page === 'segment') prefetchJSON('/api/v1/segments/' + encodeURIComponent(firstRoute.id)); | |
| if (firstRoute.page === 'config') prefetchJSON('/api/v1/np/schema'); | |
| function SegmentList() { | |
| const [rows, setRows] = useState<SegmentSummary[] | null>(null), [error, setError] = useState(''); | |
| const [root, setRoot] = useState(''), [world, setWorld] = useState(''), [tier, setTier] = useState(''); | |
| const [sort, setSort] = useState('idle'); | |
| useEffect(() => { | |
| const controller = new AbortController(); | |
| getSegments(controller.signal).then(x => setRows(x.segments)).catch(e => {if (!controller.signal.aborted) setError(errorText(e));}); | |
| return () => controller.abort(); | |
| }, []); | |
| if (error) return <div role="alert" className="error">{error}</div>; | |
| if (!rows) return <p className="loading">读取段列表…</p>; | |
| const options = (key: 'root' | 'world_id' | 'duration_tier') => Array.from(new Set(rows.map(r => r[key]))).sort(); | |
| const requestedScript = new URLSearchParams(location.hash.split('?')[1]).get('script'); | |
| const filtered = rows.filter(r => (!requestedScript || r.script_id === requestedScript) && (!root || r.root === root) && (!world || r.world_id === world) && (!tier || r.duration_tier === tier)) | |
| .sort((a, b) => sort === 'idle' ? (b.idle_remainder_fraction ?? -1) - (a.idle_remainder_fraction ?? -1) | |
| : sort === 'discard' ? b.intent_counts.discarded - a.intent_counts.discarded : a.id.localeCompare(b.id)); | |
| return <section className="list-page"> | |
| <div className="page-heading"><div><p className="eyebrow">轨迹层 · 段审阅</p><h1>先找出需要看的活动</h1></div><span>已生成段筛选 {filtered.length} / {rows.length} 段(不含未生成格)</span></div> | |
| <div className="filters"> | |
| <label>根<select value={root} onChange={e => setRoot(e.target.value)}><option value="">全部</option>{options('root').map(x => <option key={x}>{x}</option>)}</select></label> | |
| <label>住宅<select value={world} onChange={e => setWorld(e.target.value)}><option value="">全部</option>{options('world_id').map(x => <option key={x}>{x}</option>)}</select></label> | |
| <label>时长档<select value={tier} onChange={e => setTier(e.target.value)}><option value="">全部</option>{options('duration_tier').map(x => <option key={x} value={x}>{durationTier(x)}</option>)}</select></label> | |
| <label>排序<select value={sort} onChange={e => setSort(e.target.value)}><option value="idle">剩余原地占比 ↓</option><option value="discard">丢弃意图数 ↓</option><option value="id">段号</option></select></label> | |
| </div> | |
| <p className="muted">列表读取构造记录摘要。进入逐段页后核验剧本和能力表指纹。剩余原地占比是意图用完或丢光后原地待到片尾的全体主体时间比例。</p> | |
| <div className="table-scroll"><table className="segments-table"><thead><tr><th>段 / 住宅</th><th>时长</th><th>主体</th><th>完成 / 丢弃 / 截断</th><th>剩余原地占比</th><th>自检</th></tr></thead><tbody> | |
| {filtered.map(r => <tr key={r.id} data-segment-id={r.id}><td><a href={segmentHash(r.id)}>{r.id}</a><small>{r.world_id} · {r.root}</small>{r.metadata_error && <span className="error">{errorText(r.metadata_error)}</span>}</td> | |
| <td>{r.duration_s.toFixed(0)} 秒<small>{durationTier(r.duration_tier)}</small></td><td title={Object.entries(r.actor_counts).map(([k, v]) => `${k}: ${v}`).join('\n')}>{r.actor_count}</td> | |
| <td>{r.intent_counts.completed} / <strong className="discard-number">{r.intent_counts.discarded}</strong> / {r.intent_counts.truncated}</td> | |
| <td><div className="idle-meter"><i style={{width: `${(r.idle_remainder_fraction ?? 0) * 100}%`}} /></div><strong>{r.idle_remainder_fraction === null ? '未知' : `${(r.idle_remainder_fraction * 100).toFixed(1)}%`}</strong></td> | |
| <td><span className={'check ' + r.selfcheck_conclusion}>{CONCLUSION_LABELS[r.selfcheck_conclusion] || r.selfcheck_conclusion}</span><small>指纹待核</small></td></tr>)} | |
| </tbody></table>{!filtered.length && <p className="empty">没有符合筛选条件的段。</p>}</div> | |
| </section>; | |
| } | |
| function SegmentPage({id, initialTime, initialActors}: {id: string; initialTime: number; initialActors: string[] | null}) { | |
| const [view, setView] = useState<SegmentView | null>(null), [error, setError] = useState(''); | |
| const [media,setMedia]=useState<RenderMedia | null>(null), [mediaError,setMediaError]=useState(''); | |
| const [mapReady,setMapReady]=useState(false); | |
| useEffect(() => { | |
| const controller = new AbortController(); setView(null); setError(''); setMapReady(false); | |
| getSegment(id, controller.signal).then(setView).catch(e => {if (!controller.signal.aborted) setError(errorText(e));}); | |
| return () => controller.abort(); | |
| }, [id]); | |
| useEffect(() => { | |
| setMedia(null);setMediaError(''); | |
| if(!view?.media_ref || !mapReady) return; | |
| const controller=new AbortController(), ref=view.media_ref; | |
| // Paint the basemap before parsing a large media table or starting decoders. | |
| let frame=requestAnimationFrame(()=>{frame=requestAnimationFrame(()=>{ | |
| getJSON<RenderMedia>(ref.url,controller.signal).then(value=>{ | |
| if(value.schema!=='render-media/1'||value.obs_id!==ref.obs_id||value.source_group_id!==ref.source_group_id) throw Error('录像与段身份不符'); | |
| setMedia(value); | |
| }).catch(e=>{if(!controller.signal.aborted)setMediaError(errorText(e));}); | |
| });}); | |
| return()=>{cancelAnimationFrame(frame);controller.abort();}; | |
| },[view,mapReady]); | |
| if (error) return <div role="alert" className="error"><h1>这段暂时不能审阅</h1><p>{error}</p><a href="#/segments">返回段列表</a></div>; | |
| if (!view) return <p className="loading">核验剧本与能力表,读取曲线…</p>; | |
| return <Review key={id} view={view} media={media || view.media || null} mediaError={mediaError} initialTime={initialTime} initialActors={initialActors} onBasemapReady={()=>setMapReady(true)} />; | |
| } | |
| export function App() { | |
| const [route, setRoute] = useState(() => parseRoute(location.hash)); | |
| useEffect(() => { | |
| const callback = () => setRoute(parseRoute(location.hash)); | |
| window.addEventListener('hashchange', callback); | |
| return () => window.removeEventListener('hashchange', callback); | |
| }, []); | |
| const active = route.page === 'verify' ? 'verify' : route.page === 'config' || route.page === 'results' ? 'config' : route.page === 'segments' || route.page === 'segment' ? 'segments' : null; | |
| const batch = route.page === 'results' ? new URLSearchParams(location.hash.split('?')[1]).get('run') || undefined | |
| : route.page === 'segment' ? route.id.split('/')[0] : undefined; | |
| return <><TopBar active={active} batch={batch} /> | |
| <div className="app-shell"><main> | |
| {route.page === 'verify' ? <Verification key={route.run} run={route.run}/> : route.page === 'segments' ? <SegmentList /> : route.page === 'segment' ? <SegmentPage key={route.id} id={route.id} initialTime={route.time} initialActors={route.actors} /> : route.page === 'config' ? <GenerationConfig /> : route.page === 'results' ? <GenerationResult /> : null} | |
| </main></div></>; | |
| } | |