concept-collection / mri-scanner
mri-scanner / src / seq / summary.ts
47 lines · 1.3 KBBlameHistoryRaw
1// A light summary of a .seq file for display (and to validate it parses before
2// we store it). Built on the parser + reconstruction reused from seqlab.
3import { parseSeq } from './parseSeq.ts'
4import { reconstruct } from './reconstruct.ts'
6export interface SeqSummary {
7 ok: boolean
8 error?: string
9 name?: string
10 version?: string
11 numBlocks: number
12 durationSec: number
13 rfCount: number
14 adcCount: number
15 adcSamples: number
16 signatureValid?: boolean
19export function summarizeSeq(text: string): SeqSummary {
20 try {
21 const seq = parseSeq(text)
22 const rec = reconstruct(seq)
23 const nameDef = seq.definitions.get('Name')
24 const name = typeof nameDef === 'string' ? nameDef : undefined
25 return {
26 ok: true,
27 name,
28 version: `${seq.version.major}.${seq.version.minor}.${seq.version.revision}`,
29 numBlocks: seq.blocks.length,
30 durationSec: rec.duration,
31 rfCount: rec.stats.rfCount,
32 adcCount: rec.stats.adcCount,
33 adcSamples: rec.stats.adcSamples,
34 signatureValid: seq.signature?.valid,
35 }
36 } catch (err) {
37 return {
38 ok: false,
39 error: err instanceof Error ? err.message : String(err),
40 numBlocks: 0,
41 durationSec: 0,
42 rfCount: 0,
43 adcCount: 0,
44 adcSamples: 0,
45 }
46 }