edf2csv 0.5.0 → 0.5.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,298 @@
3
3
  Notable changes to edf2csv. Versions follow [semantic versioning](https://semver.org); while the
4
4
  major version is 0, a minor bump may contain breaking changes.
5
5
 
6
+ ## 0.5.13
7
+
8
+ ### Fixed: the test suite reached for a website dependency, and every publish since 0.5.1 failed
9
+
10
+ 0.5.1 stopped the link checker carrying its own copy of the site's slug rule and had it
11
+ import `slugify` from `website/src/lib/markdown.js` instead. That file imports `marked`.
12
+
13
+ The package has no dependencies, deliberately, and `npm test` runs with none installed —
14
+ which is a claim the correctness page makes in as many words. So the release workflow failed
15
+ on `Cannot find package 'marked'` for 0.5.1 through 0.5.12, and npm stayed on 0.5.0 while
16
+ twelve tags, twelve GitHub releases and twelve sets of green local tests said otherwise. It
17
+ passed here because this machine has the website's `node_modules` sitting next to the
18
+ package's.
19
+
20
+ `slugify` is its own module now, `website/src/lib/slug.js`, importing nothing. The renderer
21
+ imports it and re-exports it; the test imports it directly. Both callers share the function
22
+ without sharing a dependency graph.
23
+
24
+ Verified the way it should have been the first time: a fresh clone, `npm ci`, no website
25
+ `node_modules` anywhere, all 253 tests passing.
26
+
27
+ ## 0.5.12
28
+
29
+ ### Fixed: the summary claimed a conversion for a reader that stopped reading
30
+
31
+ `edf2csv recording.edf --stdout | head -1` announced "Wrote 52,507 rows to stdout" for a
32
+ 102,400-row recording of which the reader took one line. That number is neither total. It is
33
+ however many rows had been formatted before the closed pipe was noticed — a figure with no
34
+ meaning outside the implementation, presented as the result of the run.
35
+
36
+ Piping to `head` is an ordinary thing to type and not a failure, so it still exits 0. It is
37
+ not a conversion either, so it no longer gets a conversion's summary: it says the reader
38
+ closed the pipe, after how many rows had been written, and that the recording was not
39
+ converted in full. How many reached the reader cannot be known from this side. That it
40
+ stopped early can.
41
+
42
+ `ConvertResult` gains `readerHungUp` for callers who need to tell the two apart.
43
+
44
+ ### Fixed: `--gzip` dropped the unit from every line of the summary
45
+
46
+ ```
47
+ Wrote out
48
+ signals.csv.gz 300
49
+ annotations.csv.gz 3
50
+ channels.csv.gz 1
51
+ ```
52
+
53
+ The unit was attached to names ending in `.csv`, and `.csv.gz` does not, so the counts stood
54
+ on their own with nothing saying what they counted — beside an uncompressed run of the same
55
+ recording that says `300 rows`. A compressed CSV's rows are still rows.
56
+
57
+ ## 0.5.11
58
+
59
+ ### Fixed: six documentation claims that contradicted the tool or each other
60
+
61
+ - **cli-reference explained the derived decimal ceiling as 20.** It has been 100 since
62
+ 0.4.74. The sentence was reasoning about a magnetometer needing more places than a
63
+ microvolt EEG and then giving the number that no longer applies — and 20 is still right
64
+ for `--decimals`, which made the two easy to conflate. Both are now stated, with what each
65
+ bounds.
66
+ - **The `--decimals` error example could never be printed.** It showed
67
+ `--decimals must be a whole number between 0 and 20, got "16"`. 16 is inside 0 to 20.
68
+ - **The exit-code list said "more than one input file" is a usage error.** Batch conversion
69
+ of several files is a documented feature of the same page.
70
+ - **api.md gave `ConversionError.code` two different value sets** thirty lines apart: seven
71
+ in the table, four in the prose.
72
+ - **The README's headline CSV sample was not output the tool can produce.** A 256 Hz
73
+ recording writes `time_s` to eight places, because 1/256 terminates at eight; the sample
74
+ showed six, and values to match. It is a real conversion now.
75
+ - **recipes.md showed a fifth `sleep-study.edf`** — four channels, 42.2 MB, plain EDF —
76
+ where the rest of the site shows one recording. 0.4.78 fixed exactly this and the guard it
77
+ added never looked at that page: it held a hard-coded list of three, and matched only the
78
+ exact spelling `File sleep-study.edf`, while recipes wrote `./sleep-study.edf`.
79
+
80
+ The guard now reads every page in `website/content` and accepts either spelling. A check
81
+ against drift with a hard-coded list of where drift can happen is a check against the drift
82
+ you already found.
83
+
84
+ Also: the correctness page's captured `npm test` block claimed 39 suites where the runner
85
+ reports 48. That number was the one thing in the block nothing was reading; it is counted
86
+ from the files now, like the test counts beside it.
87
+
88
+ ## 0.5.10
89
+
90
+ ### Fixed: `VALUE_RESOLUTION` reported `--decimals` back at the person who typed it
91
+
92
+ The warning 0.4.74 added is about a ceiling: a channel whose quantization step is below
93
+ 1e-98 needs more decimal places than `toFixed` will print, so consecutive digital codes come
94
+ out as the same text. The check asked "does this channel need more decimals than it is
95
+ getting", which is also true — deliberately — every time `--decimals` is used to ask for
96
+ fewer.
97
+
98
+ So an ordinary EEG at `--decimals 2` raised it on every channel. And because `--strict`
99
+ turns any diagnostic into a non-zero exit, `--decimals 2 --strict` could not succeed on any
100
+ recording at all: the flag and the flag were in a fight.
101
+
102
+ Raised only when the precision was derived now. `--decimals` is a choice, and the tool takes
103
+ it at its word. The ceiling case is unchanged, and still warns, because nobody chose 100.
104
+
105
+ ## 0.5.9
106
+
107
+ ### Fixed: the long layout ordered tied channels by sampling rate, not by the file's order
108
+
109
+ Documented as "within one time in the order the file declares its channels", which is also
110
+ what `channels.csv` lists and what the wide layout's columns do. What it actually did was
111
+ descending sampling rate: rate groups are sorted largest first, because that is how the wide
112
+ layout names its files, and emitting a tie one group at a time let that leak into the rows.
113
+
114
+ A recording declaring `slow, medium, fast` wrote `fast, medium, slow` at every instant where
115
+ all three had a sample. Most recordings hide it by declaring their fastest channels first,
116
+ which is why the fixtures did not catch it — a new one, `ascending-rates.edf`, declares them
117
+ the other way round.
118
+
119
+ Now every channel due at one instant is collected and emitted in signal-index order, which
120
+ is the file's own order and the only one a reader can predict. Checked across all 41
121
+ convertible fixtures: each channel's sequence of values is identical between the two
122
+ layouts.
123
+
124
+ ### Fixed: `onProgress` reported more bytes written than the file being written
125
+
126
+ `bytesWritten` summed each group's writer. The long layout's groups share one, so a
127
+ three-rate conversion reported three times the real figure — a progress meter that runs past
128
+ the end.
129
+
130
+ ## 0.5.8
131
+
132
+ ### Fixed: 0.5.4 fixed half of the stdout audit and left the compressed half
133
+
134
+ `--stdout --layout long --gzip` still failed, and louder than before. On a 40-rate recording
135
+ it claimed "606684 of 622240 bytes did not reach the destination" over a compressed stream
136
+ that decompresses to every row, and printed Node's `MaxListenersExceededWarning` to stderr
137
+ on the way past ten listeners.
138
+
139
+ Same arithmetic as 0.5.4, different shape, which is why it survived the fix. Uncompressed,
140
+ the audit adds up each writer's byte count — a sum, fixed by counting distinct writers.
141
+ Compressed, it subscribes to the compressor's `data` events — and the subscription was made
142
+ once per rate group, on the one compressor they share, so every chunk was counted once per
143
+ group.
144
+
145
+ Subscribed once per stream now. The stream is byte-identical to what `--out --gzip` writes.
146
+
147
+ ## 0.5.7
148
+
149
+ ### Fixed: a folder that could not be read was reported as a folder holding nothing
150
+
151
+ Both got the same exit 2 and the same sentence — "No EDF or BDF recordings found in
152
+ /data/locked" — printed directly beneath a line saying the folder could not be read. The two
153
+ lines contradicted each other, and the exit code sided with the wrong one.
154
+
155
+ Exit 2 is this tool's code for "the command itself was wrong". The command was fine; the
156
+ filesystem refused. A script reading the status was being told to fix its arguments when
157
+ what needed fixing was a permission, and the sentence stated a fact the run was in no
158
+ position to state: nothing was found because nothing was looked at.
159
+
160
+ An unreadable path now exits 1 and says so — "whether it holds recordings is unknown". An
161
+ empty folder is still exit 2 and still says it is empty, which it can, having looked.
162
+
163
+ ## 0.5.6
164
+
165
+ ### Fixed: memory followed the number of output tables, not the size of the recording
166
+
167
+ Every rate group opened its own writer at the 1 MiB flush threshold, so pending output was
168
+ group count times a megabyte before anything drained. A 6.5 MB recording with forty sampling
169
+ rates therefore needed forty megabytes of buffer and died with a raw V8 heap out-of-memory —
170
+ exit 134, a native stack, nothing written, no catchable error for a library caller — under a
171
+ 96 MB cap. The site advertises 48 MB.
172
+
173
+ Nothing about that recording is large. The fan-out is: an EDF header can declare thousands of
174
+ channels, and a research montage really does mix a dozen rates. The one number that mattered
175
+ was the one the design was not looking at.
176
+
177
+ The budget is one buffer for the conversion now, split across the tables, with a floor so a
178
+ run does not turn into a flush per row. Single-rate recordings — nearly all of them — keep
179
+ exactly the buffer they had, and forty tables cost 2.5 MB instead of 40. The same 6.5 MB
180
+ recording completes under a 32 MB cap, and its CSVs are byte-identical to a run with a
181
+ gigabyte. Throughput on an eight-hour single-rate conversion is unchanged.
182
+
183
+ The long layout was never affected: it shares one writer across the groups, which is what
184
+ 0.5.0 had to do to keep its rows in order.
185
+
186
+ ## 0.5.5
187
+
188
+ ### Fixed: three things `--stdout` said about itself that were not true
189
+
190
+ **The help forbade what the tool does.** `--help` and the README both described `--stdout`
191
+ as "(single-rate recordings only)" — twenty lines above the paragraph, in the same help text,
192
+ explaining that `--layout long` is how a mixed-rate recording streams. 0.5.0 lifted the
193
+ restriction and left the line describing it.
194
+
195
+ **`--out` and `--checksum` were accepted and dropped in silence.** `--out` named a directory
196
+ that was never created, so a run that wrote nowhere looked like it had written somewhere.
197
+ `--checksum` was worse than useless: the hash is computed before the first record is read,
198
+ which is a second full pass over the input, and the only file it is ever written to is the
199
+ `metadata.json` that `--stdout` does not write. A recording large enough to want a checksum
200
+ is large enough to notice being read twice for nothing. Both are usage errors now, which is
201
+ what `--stdout --json` and `--stdout --annotations-only` already were.
202
+
203
+ **A folder holding one recording was refused as "1 recordings".** "--stdout writes a single
204
+ CSV, so it cannot take 1 recordings" — ungrammatical, and wrong on its face, since one
205
+ recording is exactly what it can take. What it cannot take is a folder, whose contents are
206
+ not known until it is walked. It says that instead, and names the recording inside so you can
207
+ run that.
208
+
209
+ ## 0.5.4
210
+
211
+ ### Fixed: `--stdout --layout long` failed with a disk-full error on a file that was complete
212
+
213
+ The command the `--layout` documentation gives — `edf2csv recording.edf --stdout --layout
214
+ long > signals.csv` — exited 1 on every mixed-rate recording, saying "64086 of 96129 bytes
215
+ did not reach the destination" and advising that the disk was almost certainly full. The
216
+ file on disk was complete, every row present.
217
+
218
+ `--stdout` audits itself: a filesystem that fills up mid-write returns a short count rather
219
+ than an error, and stdout has nothing written after it to trip over, so the run compares how
220
+ far the file grew against how many bytes it handed over. That count was taken once per rate
221
+ group. 0.5.0's long layout gives every group the same writer, so a three-rate recording
222
+ counted its 32,043 bytes three times, was credited with 96,129, and concluded that two
223
+ thirds of them had been lost.
224
+
225
+ Counted once per writer now. It only bit when stdout was redirected to a regular file, which
226
+ is the one case the audit applies to and exactly what the documentation shows — through a
227
+ pipe the audit declines, so the feature looked fine everywhere it was demonstrated
228
+ interactively.
229
+
230
+ ## 0.5.3
231
+
232
+ ### Fixed: the long layout promised sorted rows for a file it cannot sort
233
+
234
+ 0.5.0 said, flatly, "rows come out sorted by `time_s`" — on two pages and in its own release
235
+ notes. The promise rests on something true but conditional: every sample of a record falls
236
+ inside that record's span, so writing records in file order gives times in order.
237
+
238
+ A discontinuous recording is free to store its records in a different order than it
239
+ timestamps them. Nothing in EDF+ forbids it. Then the rows come out 10s, 5s, 0s, and the
240
+ tool was already warning that they would — "2 data records start earlier than the record
241
+ before it. Rows are written in file order, so the time column will not increase
242
+ monotonically" — while the page for the new feature promised the opposite.
243
+
244
+ The claim is qualified now, in both places, and points at the warning. What has not changed
245
+ is the part that matters: every sample is written, once, in file order, with the time the
246
+ file gives it. A fixture, `records-backwards.edf`, holds all of that — including the check
247
+ that the times really do go backwards, so the test cannot quietly stop testing anything.
248
+
249
+ ## 0.5.2
250
+
251
+ ### Fixed: the disk-full tests destroyed any other run on the machine
252
+
253
+ `test/stdout-audit.test.js` needs a filesystem of a known small size, so it makes one with
254
+ `hdiutil`. The image and the volume were constants — `/tmp/edf2csv-audit.dmg` and
255
+ `/Volumes/edf2csvaudit` — and every run began by detaching that volume and deleting that
256
+ image, whoever they belonged to.
257
+
258
+ So two runs at once did not queue, they destroyed each other. Three concurrent copies of the
259
+ file fail 10 of their 12 tests, the second run pulling the disk out from under the first
260
+ mid-write. This is not exotic: `node --test` runs test files in parallel, re-running a suite
261
+ before the last one has finished is ordinary, and CI machines run more than one job. It
262
+ surfaced here as a single mystery failure in an otherwise green run, which is the worst way
263
+ for it to surface — a flaky test costs more than the one it fails, because it makes every
264
+ other result a question.
265
+
266
+ The image and volume are named for the process now, and the mount point is read from
267
+ `hdiutil` rather than assumed: macOS renames a volume whose name is already taken —
268
+ `edf2csvaudit 1` — so assuming the path meant a colliding run would have quietly written
269
+ into the other run's volume. Four concurrent copies now pass all sixteen and leave nothing
270
+ mounted.
271
+
272
+ ## 0.5.1
273
+
274
+ ### Fixed: 0.5.0 shipped a feature and told none of the pages that argue for it
275
+
276
+ `--layout long` is the answer to a question six pages ask, and every one of them still said
277
+ the split into a file per rate was the only outcome. sampling-rates.md spends a section
278
+ listing the three ways a wide table can fill the cells a slow channel never recorded, and
279
+ never mentioned the fourth option, which is not to make the table wide. faq.md's "why did I
280
+ get several signals files" gave no way to get one. cli-reference listed "more than one
281
+ sampling rate" as a flat exit-2 condition for `--stdout` — which `--layout long` makes false,
282
+ while the tool's own error message for that case already names the flag.
283
+
284
+ All six now say so, with real output. A test holds the rule: a page that tells the reader a
285
+ mixed-rate recording becomes several files has to also tell them about the layout that does
286
+ not.
287
+
288
+ ### Fixed: the link checker had its own idea of where links point
289
+
290
+ Added in 0.4.67 with its own copy of the site's slug rule — lowercase, then every run of
291
+ non-alphanumerics to a hyphen. The site's keeps hyphens as themselves, so `## --layout` is
292
+ `#--layout` on the page and was `#layout` here. It would have called the correct links added
293
+ above broken, and it would have passed a link to `#layout` that resolves to nothing.
294
+
295
+ It imports `slugify` from `website/src/lib/markdown.js` now, which is the function that
296
+ generates the ids, so a link checker and the links agree by construction.
297
+
6
298
  ## 0.5.0
7
299
 
8
300
  ### Added: `--layout long`, so a mixed-rate recording can be one table
package/README.md CHANGED
@@ -24,8 +24,8 @@ recording_csv/
24
24
 
25
25
  ```csv
26
26
  time_s,FP1-F7,F7-T7,T7-P7
27
- 0.000000,-17.778,39.267,-3.712
28
- 0.003906,0.195,0.195,0.195
27
+ 0.00000000,0.061,113.126,99.939
28
+ 0.00390625,37.546,123.871,84.188
29
29
  ```
30
30
 
31
31
  `time_s` is seconds from the start of the recording. The other columns are the
@@ -70,7 +70,8 @@ npx edf2csv recording.edf --start 30m --duration 5m
70
70
  -q, --quiet Less output
71
71
  --json Machine-readable JSON on stdout (works with --info too)
72
72
  --strict Exit 1 if the recording raised any warning
73
- --stdout Write the CSV to stdout (single-rate recordings only)
73
+ --stdout Write the CSV to stdout (one table only: one sampling
74
+ rate, or --layout long)
74
75
  -h, --help Help
75
76
  -V, --version Version
76
77
  ```
@@ -1 +1 @@
1
- {"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../../src/cli/report.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAGhD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAuBvD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAK9C;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,SAAK,GAAG,MAAM,CAKhE;AAED,0FAA0F;AAC1F,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,GAAG,MAAM,CAgHtE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,GAAE,MAAM,GAAG,IAAQ,GAAG,MAAM,CAwD/F;AAED,mEAAmE;AACnE,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,GAAG,MAAM,CAS5E;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAU3D;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,GAAE,MAAM,GAAG,IAAQ,GAAG,MAAM,CAcpF"}
1
+ {"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../../src/cli/report.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAGhD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAuBvD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAK9C;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,SAAK,GAAG,MAAM,CAKhE;AAED,0FAA0F;AAC1F,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,GAAG,MAAM,CAgHtE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,GAAE,MAAM,GAAG,IAAQ,GAAG,MAAM,CAwD/F;AAED,mEAAmE;AACnE,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,GAAG,MAAM,CAS5E;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAgB3D;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,GAAE,MAAM,GAAG,IAAQ,GAAG,MAAM,CAcpF"}
@@ -247,7 +247,13 @@ export function formatSummary(result) {
247
247
  const lines = [];
248
248
  const rows = [];
249
249
  for (const file of result.files) {
250
- rows.push([` ${file.name}`, file.rows.toLocaleString('en-US'), file.name.endsWith('.csv') ? 'rows' : '']);
250
+ // `.csv.gz` is still a CSV, and its rows are still rows. The suffix test dropped the
251
+ // unit from every line of a --gzip summary, so the numbers stood on their own.
252
+ rows.push([
253
+ ` ${file.name}`,
254
+ file.rows.toLocaleString('en-US'),
255
+ /\.csv(\.gz)?$/u.test(file.name) ? 'rows' : '',
256
+ ]);
251
257
  }
252
258
  lines.push(`Wrote ${result.outputDir}`);
253
259
  lines.push(table(rows, new Set([1])));
@@ -1 +1 @@
1
- {"version":3,"file":"report.js","sourceRoot":"","sources":["../../src/cli/report.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAElE,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAG5D,SAAS,KAAK,CAAC,IAAoC,EAAE,UAA+B;IAClF,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACjC,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE;YACtB,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,IAAI;SACR,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CACX,GAAG;SACA,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE;QACf,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACxB,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC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AAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACtC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAChE,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,MAAqB,EAAE,SAAwB,CAAC;IAC1E,OAAO,IAAI,CAAC,SAAS,CACnB;QACE,UAAU,EAAE,MAAM,CAAC,SAAS;QAC5B,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,WAAW,EAAE,MAAM,CAAC,eAAe;QACnC,gBAAgB,EAAE,MAAM,CAAC,IAAI,CAAC,eAAe;QAC7C,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,WAAW;QAChC,UAAU,EAAE,MAAM,CAAC,SAAS;QAC5B,QAAQ,EAAE,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;KACtG,EACD,IAAI,EACJ,MAAM,IAAI,SAAS,CACpB,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Human-readable output for the terminal.\n *\n * Everything here is plain text with no colour codes, so piping to a file or a log\n * produces exactly what appeared on screen.\n */\n\nimport type { Diagnostic } from '../edf/errors.js';\nimport type { EdfFile } from '../edf/reader.js';\nimport { describeFormat, formatRates, formatWallClock } from '../edf/header.js';\nimport { formatBytes, formatDuration } from '../format/number.js';\nimport type { ConversionPlan } from '../convert/plan.js';\nimport { withoutFileRateWarning } from '../convert/plan.js';\nimport type { ConvertResult } from '../convert/run.js';\n\nfunction table(rows: readonly (readonly string[])[], alignRight: ReadonlySet<number>): string {\n if (rows.length === 0) return '';\n const width: number[] = [];\n for (const row of rows) {\n row.forEach((cell, i) => {\n width[i] = Math.max(width[i] ?? 0, cell.length);\n });\n }\n return rows\n .map((row) =>\n row\n .map((cell, i) => {\n const w = width[i] ?? 0;\n return alignRight.has(i) ? cell.padStart(w) : cell.padEnd(w);\n })\n .join(' ')\n .trimEnd(),\n )\n .join('\\n');\n}\n\n/**\n * Make header text safe to print to a terminal.\n *\n * EDF identification fields and channel labels are free text copied verbatim out of the\n * file, and `--info` puts them straight on stdout. A header carrying ANSI escapes could\n * therefore drive the reader's terminal — `\\x1b[2J\\x1b[H` clears the screen and homes the\n * cursor, which is enough to hide the rest of the output or repaint it as something else.\n * Nobody writes an EDF header that way on purpose, which is exactly why a file that does\n * should not be trusted with the terminal.\n *\n * Control bytes are shown as their escape instead, so a corrupt field stays diagnosable\n * rather than being silently swallowed. This affects display only: `channels.csv` and\n * `metadata.json` still copy the field verbatim, and CSV quoting already makes that safe.\n */\nexport function printable(text: string): string {\n // eslint-disable-next-line no-control-regex\n return text.replace(/[\\u0000-\\u001f\\u007f-\\u009f]/gu, (c) =>\n `\\\\x${c.codePointAt(0)!.toString(16).padStart(2, '0')}`,\n );\n}\n\n/**\n * The same protection for text that is meant to span lines.\n *\n * `printable` escapes newlines along with everything else, which is right for a channel\n * label — one has no business containing a line break, and it would break the `--info`\n * table's alignment. It is wrong for a whole message: several are written on two lines,\n * and Node's own option errors run to three. Escaping those turned the break into text:\n *\n * error: No channel named \"ECQ\". Did you mean \"ECG\"?\\x0aRun with --info to list ...\n *\n * Each line is escaped on its own, so nothing here gains the ability to drive a terminal.\n * A carriage return is still escaped, so no line can be repainted after it is printed —\n * which is the property that mattered. A newline can only add a line, never overwrite one.\n */\nexport function printableLines(text: string, indent = ''): string {\n return text\n .split('\\n')\n .map((line, index) => (index === 0 ? '' : indent) + printable(line))\n .join('\\n');\n}\n\n/** The `--info` view: what is in this recording, and what would converting it produce. */\nexport function formatInfo(file: EdfFile, plan: ConversionPlan): string {\n const { header } = file;\n const lines: string[] = [];\n\n lines.push(`File ${file.path}`);\n lines.push(`Format ${describeFormat(header)}`);\n lines.push(\n `Recorded ${\n formatWallClock(header.startDateTime)?.replace('T', ' ') ??\n `${printable(header.startDateRaw)} ${printable(header.startTimeRaw)} (unparseable)`\n }`,\n );\n lines.push(\n `Duration ${formatDuration(file.durationSeconds)} (${file.recordCount} records of ${header.recordDuration}s)`,\n );\n const elapsedSpan = plan.range.recordingEndSeconds - plan.range.recordingStartSeconds;\n if (Math.abs(elapsedSpan - file.durationSeconds) > 1e-9) {\n lines.push(`Time span ${formatDuration(elapsedSpan)} (includes discontinuities)`);\n }\n lines.push(`Size ${formatBytes(file.fileSize)}`);\n if (header.patientId) lines.push(`Patient ${printable(header.patientId)}`);\n if (header.recordingId) lines.push(`Recording ${printable(header.recordingId)}`);\n\n const signals = file.dataSignals;\n lines.push('');\n // The signal count was pluralised but the annotation-channel count was not, so a file\n // carrying two of them read \"2 annotation channel\". EDF+ permits more than one.\n const annotationCount = file.annotationSignals.length;\n const annotationPart =\n annotationCount > 0\n ? ` + ${annotationCount} annotation channel${annotationCount === 1 ? '' : 's'}`\n : '';\n lines.push(\n `Channels ${signals.length} signal${signals.length === 1 ? '' : 's'}${annotationPart}`,\n );\n lines.push('');\n\n const rows: string[][] = [['#', 'COLUMN', 'LABEL', 'UNIT', 'RATE', 'RANGE', 'OUTPUT']];\n const fileFor = new Map<number, string>();\n for (const group of plan.groups) {\n for (const channel of group.channels) fileFor.set(channel.signal.index, group.fileName);\n }\n // Rendered as a group so that two channels recorded at different rates never show the\n // same figure in the RATE column, which is the one thing this table is asked to settle.\n const rateText = formatRates(signals.map((signal) => signal.samplingRate));\n for (const [row, signal] of signals.entries()) {\n rows.push([\n String(signal.index),\n printable(plan.columnNames.get(signal.index) ?? ''),\n printable(signal.label),\n printable(signal.physicalDimension),\n `${rateText[row]} Hz`,\n `${signal.physicalMin} to ${signal.physicalMax}`,\n /*\n A channel with no samples was reported as \"(not selected)\", which is a different\n thing and not true when it was named on --channels. `edf2csv rec.edf --info\n --channels unused` said the channel the command asked for had not been chosen, when\n what is actually the case is that the file gives it nothing to convert. The\n NO_SAMPLES warning below the table says so; the table contradicted it.\n */\n fileFor.get(signal.index) ??\n (signal.samplesPerRecord === 0 ? '(no samples)' : '(not selected)'),\n ]);\n }\n lines.push(table(rows, new Set([0])));\n\n lines.push('');\n if (plan.groups.length > 1) {\n lines.push(\n plan.layout === 'long'\n ? `Sampling rates differ, and the long layout puts them in one table anyway: each row ` +\n `carries its own time, so nothing has to line up. No channel is resampled.`\n : `Sampling rates differ, so channels are written to ${plan.groups.length} files, one per rate. ` +\n `No channel is resampled.`,\n );\n }\n /*\n The estimate describes the signal tables, and says so when that is not what will be\n written.\n\n Under --annotations-only there are no signal tables, and the line read \"Would write 0\n rows, roughly 0 B.\" for a conversion that goes on to write annotations.csv with three\n events in it. --info exists to say what a conversion will do; asserting it will write\n nothing, when it will write a file, is the one thing it must not do.\n\n How many events there are cannot be answered from the header — the annotation channel has\n to be read record by record, which is the scan --info is for avoiding. So it says which\n file, and that the count is not knowable this cheaply, rather than inventing a zero.\n */\n if (!plan.writeSignals) {\n // Named as they will be written. --info is read to find out what a run leaves behind,\n // and a script that opens the name it was given must find a file there.\n const suffix = plan.gzip ? '.csv.gz' : '.csv';\n lines.push(\n file.annotationSignals.length > 0\n ? `Would write annotations${suffix} and channels${suffix}, and no signal data. How ` +\n 'many events there are cannot be told from the header.'\n : `Would write channels${suffix} and no signal data — and no annotations${suffix} ` +\n 'either, since this recording has no annotation channel.',\n );\n return lines.join('\\n');\n }\n\n // The estimate counts the characters of the CSV, which is what --gzip then compresses.\n // Reporting it as the size on disk would overstate a compressed conversion several-fold.\n const compressing = plan.gzip;\n lines.push(\n `Would write ${plan.estimate.rows.toLocaleString('en-US')} rows, roughly ` +\n `${formatBytes(plan.estimate.bytes)}${compressing ? ' before compression' : ''}.`,\n );\n\n return lines.join('\\n');\n}\n\n/**\n * The `--info` view as JSON, for surveying files from a script.\n *\n * `indent` is 2 for a single recording, matching what this has always printed, and null for\n * a batch — several pretty-printed documents run together are readable by a streaming parser\n * but not by anything that expects one record per line, and a batch is exactly where\n * line-oriented reading is wanted. null rather than undefined because a default parameter\n * takes effect when undefined is passed, which quietly restored the indentation this was\n * meant to drop; JSON.stringify itself wants undefined, so it is translated at the call.\n *\n * `--info` answers \"what is in this recording and what would converting it cost\", which\n * is exactly the question you want to ask across a directory of hundreds of recordings —\n * and the text table is the wrong shape for that. `--json` previously applied only to\n * conversions, so scripts had to parse the aligned columns or convert files just to learn\n * what was in them.\n *\n * Field names match `metadata.json` where the two describe the same thing, so a survey and\n * a conversion can be read by the same code.\n */\nexport function infoJson(file: EdfFile, plan: ConversionPlan, indent: number | null = 2): string {\n const { header } = file;\n const fileFor = new Map<number, string>();\n for (const group of plan.groups) {\n for (const channel of group.channels) fileFor.set(channel.signal.index, group.fileName);\n }\n\n return JSON.stringify(\n {\n path: file.path,\n bytes: file.fileSize,\n format: describeFormat(header),\n start_datetime_local: formatWallClock(header.startDateTime),\n start_date_raw: header.startDateRaw,\n start_time_raw: header.startTimeRaw,\n patient_id: header.patientId,\n recording_id: header.recordingId,\n data_records: file.recordCount,\n data_records_declared: header.declaredRecordCount,\n record_duration_seconds: header.recordDuration,\n duration_seconds: file.durationSeconds,\n // For a discontinuous file this exceeds duration_seconds by the length of the gaps.\n time_span_seconds: plan.range.recordingEndSeconds - plan.range.recordingStartSeconds,\n annotation_channels: file.annotationSignals.length,\n channels: file.dataSignals.map((signal) => ({\n signal_index: signal.index,\n column: plan.columnNames.get(signal.index) ?? '',\n label: signal.label,\n unit: signal.physicalDimension,\n sampling_rate_hz: signal.samplingRate,\n samples_per_record: signal.samplesPerRecord,\n physical_min: signal.physicalMin,\n physical_max: signal.physicalMax,\n digital_min: signal.digitalMin,\n digital_max: signal.digitalMax,\n transducer: signal.transducer,\n prefiltering: signal.prefiltering,\n output_file: fileFor.get(signal.index) ?? null,\n })),\n estimate: {\n rows: plan.estimate.rows,\n // Character count of the CSV. With --gzip the file on disk is smaller than this.\n bytes: plan.estimate.bytes,\n exceeds_spreadsheet_limit: plan.estimate.exceedsSpreadsheetLimit,\n },\n // The plan's mixed-rate warning replaces the header parser's, as it does everywhere\n // else. This was the one consumer left out of that when 0.3.2 made the warning follow\n // --channels, so `--info --json` carried it twice: once counting the rates being\n // converted and once counting every rate in the file, with the same code and severity.\n warnings: plan.diagnostics\n .concat(withoutFileRateWarning(file.diagnostics))\n .map((d) => ({ code: d.code, severity: d.severity, message: d.message })),\n },\n null,\n indent ?? undefined,\n );\n}\n\n/** One line per diagnostic, prefixed so warnings are greppable. */\nexport function formatDiagnostics(diagnostics: readonly Diagnostic[]): string {\n return diagnostics\n .map((d) => {\n // Diagnostics quote channel labels, which come from the file, so they need the\n // same treatment as the --info table.\n const head = `${d.severity === 'warning' ? 'warning' : 'note'}: ${printable(d.message)}`;\n return d.hint ? `${head}\\n ${printable(d.hint)}` : head;\n })\n .join('\\n');\n}\n\nexport function formatSummary(result: ConvertResult): string {\n const lines: string[] = [];\n const rows: string[][] = [];\n for (const file of result.files) {\n rows.push([` ${file.name}`, file.rows.toLocaleString('en-US'), file.name.endsWith('.csv') ? 'rows' : '']);\n }\n lines.push(`Wrote ${result.outputDir}`);\n lines.push(table(rows, new Set([1])));\n lines.push(`Done in ${(result.elapsedMs / 1000).toFixed(1)}s.`);\n return lines.join('\\n');\n}\n\nexport function summaryJson(result: ConvertResult, indent: number | null = 2): string {\n return JSON.stringify(\n {\n output_dir: result.outputDir,\n files: result.files,\n annotations: result.annotationCount,\n duration_seconds: result.file.durationSeconds,\n records: result.file.recordCount,\n elapsed_ms: result.elapsedMs,\n warnings: result.diagnostics.map((d) => ({ code: d.code, severity: d.severity, message: d.message })),\n },\n null,\n indent ?? undefined,\n );\n}\n"]}
1
+ {"version":3,"file":"report.js","sourceRoot":"","sources":["../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K,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,MAAqB,EAAE,SAAwB,CAAC;IAC1E,OAAO,IAAI,CAAC,SAAS,CACnB;QACE,UAAU,EAAE,MAAM,CAAC,SAAS;QAC5B,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,WAAW,EAAE,MAAM,CAAC,eAAe;QACnC,gBAAgB,EAAE,MAAM,CAAC,IAAI,CAAC,eAAe;QAC7C,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,WAAW;QAChC,UAAU,EAAE,MAAM,CAAC,SAAS;QAC5B,QAAQ,EAAE,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;KACtG,EACD,IAAI,EACJ,MAAM,IAAI,SAAS,CACpB,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Human-readable output for the terminal.\n *\n * Everything here is plain text with no colour codes, so piping to a file or a log\n * produces exactly what appeared on screen.\n */\n\nimport type { Diagnostic } from '../edf/errors.js';\nimport type { EdfFile } from '../edf/reader.js';\nimport { describeFormat, formatRates, formatWallClock } from '../edf/header.js';\nimport { formatBytes, formatDuration } from '../format/number.js';\nimport type { ConversionPlan } from '../convert/plan.js';\nimport { withoutFileRateWarning } from '../convert/plan.js';\nimport type { ConvertResult } from '../convert/run.js';\n\nfunction table(rows: readonly (readonly string[])[], alignRight: ReadonlySet<number>): string {\n if (rows.length === 0) return '';\n const width: number[] = [];\n for (const row of rows) {\n row.forEach((cell, i) => {\n width[i] = Math.max(width[i] ?? 0, cell.length);\n });\n }\n return rows\n .map((row) =>\n row\n .map((cell, i) => {\n const w = width[i] ?? 0;\n return alignRight.has(i) ? cell.padStart(w) : cell.padEnd(w);\n })\n .join(' ')\n .trimEnd(),\n )\n .join('\\n');\n}\n\n/**\n * Make header text safe to print to a terminal.\n *\n * EDF identification fields and channel labels are free text copied verbatim out of the\n * file, and `--info` puts them straight on stdout. A header carrying ANSI escapes could\n * therefore drive the reader's terminal — `\\x1b[2J\\x1b[H` clears the screen and homes the\n * cursor, which is enough to hide the rest of the output or repaint it as something else.\n * Nobody writes an EDF header that way on purpose, which is exactly why a file that does\n * should not be trusted with the terminal.\n *\n * Control bytes are shown as their escape instead, so a corrupt field stays diagnosable\n * rather than being silently swallowed. This affects display only: `channels.csv` and\n * `metadata.json` still copy the field verbatim, and CSV quoting already makes that safe.\n */\nexport function printable(text: string): string {\n // eslint-disable-next-line no-control-regex\n return text.replace(/[\\u0000-\\u001f\\u007f-\\u009f]/gu, (c) =>\n `\\\\x${c.codePointAt(0)!.toString(16).padStart(2, '0')}`,\n );\n}\n\n/**\n * The same protection for text that is meant to span lines.\n *\n * `printable` escapes newlines along with everything else, which is right for a channel\n * label — one has no business containing a line break, and it would break the `--info`\n * table's alignment. It is wrong for a whole message: several are written on two lines,\n * and Node's own option errors run to three. Escaping those turned the break into text:\n *\n * error: No channel named \"ECQ\". Did you mean \"ECG\"?\\x0aRun with --info to list ...\n *\n * Each line is escaped on its own, so nothing here gains the ability to drive a terminal.\n * A carriage return is still escaped, so no line can be repainted after it is printed —\n * which is the property that mattered. A newline can only add a line, never overwrite one.\n */\nexport function printableLines(text: string, indent = ''): string {\n return text\n .split('\\n')\n .map((line, index) => (index === 0 ? '' : indent) + printable(line))\n .join('\\n');\n}\n\n/** The `--info` view: what is in this recording, and what would converting it produce. */\nexport function formatInfo(file: EdfFile, plan: ConversionPlan): string {\n const { header } = file;\n const lines: string[] = [];\n\n lines.push(`File ${file.path}`);\n lines.push(`Format ${describeFormat(header)}`);\n lines.push(\n `Recorded ${\n formatWallClock(header.startDateTime)?.replace('T', ' ') ??\n `${printable(header.startDateRaw)} ${printable(header.startTimeRaw)} (unparseable)`\n }`,\n );\n lines.push(\n `Duration ${formatDuration(file.durationSeconds)} (${file.recordCount} records of ${header.recordDuration}s)`,\n );\n const elapsedSpan = plan.range.recordingEndSeconds - plan.range.recordingStartSeconds;\n if (Math.abs(elapsedSpan - file.durationSeconds) > 1e-9) {\n lines.push(`Time span ${formatDuration(elapsedSpan)} (includes discontinuities)`);\n }\n lines.push(`Size ${formatBytes(file.fileSize)}`);\n if (header.patientId) lines.push(`Patient ${printable(header.patientId)}`);\n if (header.recordingId) lines.push(`Recording ${printable(header.recordingId)}`);\n\n const signals = file.dataSignals;\n lines.push('');\n // The signal count was pluralised but the annotation-channel count was not, so a file\n // carrying two of them read \"2 annotation channel\". EDF+ permits more than one.\n const annotationCount = file.annotationSignals.length;\n const annotationPart =\n annotationCount > 0\n ? ` + ${annotationCount} annotation channel${annotationCount === 1 ? '' : 's'}`\n : '';\n lines.push(\n `Channels ${signals.length} signal${signals.length === 1 ? '' : 's'}${annotationPart}`,\n );\n lines.push('');\n\n const rows: string[][] = [['#', 'COLUMN', 'LABEL', 'UNIT', 'RATE', 'RANGE', 'OUTPUT']];\n const fileFor = new Map<number, string>();\n for (const group of plan.groups) {\n for (const channel of group.channels) fileFor.set(channel.signal.index, group.fileName);\n }\n // Rendered as a group so that two channels recorded at different rates never show the\n // same figure in the RATE column, which is the one thing this table is asked to settle.\n const rateText = formatRates(signals.map((signal) => signal.samplingRate));\n for (const [row, signal] of signals.entries()) {\n rows.push([\n String(signal.index),\n printable(plan.columnNames.get(signal.index) ?? ''),\n printable(signal.label),\n printable(signal.physicalDimension),\n `${rateText[row]} Hz`,\n `${signal.physicalMin} to ${signal.physicalMax}`,\n /*\n A channel with no samples was reported as \"(not selected)\", which is a different\n thing and not true when it was named on --channels. `edf2csv rec.edf --info\n --channels unused` said the channel the command asked for had not been chosen, when\n what is actually the case is that the file gives it nothing to convert. The\n NO_SAMPLES warning below the table says so; the table contradicted it.\n */\n fileFor.get(signal.index) ??\n (signal.samplesPerRecord === 0 ? '(no samples)' : '(not selected)'),\n ]);\n }\n lines.push(table(rows, new Set([0])));\n\n lines.push('');\n if (plan.groups.length > 1) {\n lines.push(\n plan.layout === 'long'\n ? `Sampling rates differ, and the long layout puts them in one table anyway: each row ` +\n `carries its own time, so nothing has to line up. No channel is resampled.`\n : `Sampling rates differ, so channels are written to ${plan.groups.length} files, one per rate. ` +\n `No channel is resampled.`,\n );\n }\n /*\n The estimate describes the signal tables, and says so when that is not what will be\n written.\n\n Under --annotations-only there are no signal tables, and the line read \"Would write 0\n rows, roughly 0 B.\" for a conversion that goes on to write annotations.csv with three\n events in it. --info exists to say what a conversion will do; asserting it will write\n nothing, when it will write a file, is the one thing it must not do.\n\n How many events there are cannot be answered from the header — the annotation channel has\n to be read record by record, which is the scan --info is for avoiding. So it says which\n file, and that the count is not knowable this cheaply, rather than inventing a zero.\n */\n if (!plan.writeSignals) {\n // Named as they will be written. --info is read to find out what a run leaves behind,\n // and a script that opens the name it was given must find a file there.\n const suffix = plan.gzip ? '.csv.gz' : '.csv';\n lines.push(\n file.annotationSignals.length > 0\n ? `Would write annotations${suffix} and channels${suffix}, and no signal data. How ` +\n 'many events there are cannot be told from the header.'\n : `Would write channels${suffix} and no signal data — and no annotations${suffix} ` +\n 'either, since this recording has no annotation channel.',\n );\n return lines.join('\\n');\n }\n\n // The estimate counts the characters of the CSV, which is what --gzip then compresses.\n // Reporting it as the size on disk would overstate a compressed conversion several-fold.\n const compressing = plan.gzip;\n lines.push(\n `Would write ${plan.estimate.rows.toLocaleString('en-US')} rows, roughly ` +\n `${formatBytes(plan.estimate.bytes)}${compressing ? ' before compression' : ''}.`,\n );\n\n return lines.join('\\n');\n}\n\n/**\n * The `--info` view as JSON, for surveying files from a script.\n *\n * `indent` is 2 for a single recording, matching what this has always printed, and null for\n * a batch — several pretty-printed documents run together are readable by a streaming parser\n * but not by anything that expects one record per line, and a batch is exactly where\n * line-oriented reading is wanted. null rather than undefined because a default parameter\n * takes effect when undefined is passed, which quietly restored the indentation this was\n * meant to drop; JSON.stringify itself wants undefined, so it is translated at the call.\n *\n * `--info` answers \"what is in this recording and what would converting it cost\", which\n * is exactly the question you want to ask across a directory of hundreds of recordings —\n * and the text table is the wrong shape for that. `--json` previously applied only to\n * conversions, so scripts had to parse the aligned columns or convert files just to learn\n * what was in them.\n *\n * Field names match `metadata.json` where the two describe the same thing, so a survey and\n * a conversion can be read by the same code.\n */\nexport function infoJson(file: EdfFile, plan: ConversionPlan, indent: number | null = 2): string {\n const { header } = file;\n const fileFor = new Map<number, string>();\n for (const group of plan.groups) {\n for (const channel of group.channels) fileFor.set(channel.signal.index, group.fileName);\n }\n\n return JSON.stringify(\n {\n path: file.path,\n bytes: file.fileSize,\n format: describeFormat(header),\n start_datetime_local: formatWallClock(header.startDateTime),\n start_date_raw: header.startDateRaw,\n start_time_raw: header.startTimeRaw,\n patient_id: header.patientId,\n recording_id: header.recordingId,\n data_records: file.recordCount,\n data_records_declared: header.declaredRecordCount,\n record_duration_seconds: header.recordDuration,\n duration_seconds: file.durationSeconds,\n // For a discontinuous file this exceeds duration_seconds by the length of the gaps.\n time_span_seconds: plan.range.recordingEndSeconds - plan.range.recordingStartSeconds,\n annotation_channels: file.annotationSignals.length,\n channels: file.dataSignals.map((signal) => ({\n signal_index: signal.index,\n column: plan.columnNames.get(signal.index) ?? '',\n label: signal.label,\n unit: signal.physicalDimension,\n sampling_rate_hz: signal.samplingRate,\n samples_per_record: signal.samplesPerRecord,\n physical_min: signal.physicalMin,\n physical_max: signal.physicalMax,\n digital_min: signal.digitalMin,\n digital_max: signal.digitalMax,\n transducer: signal.transducer,\n prefiltering: signal.prefiltering,\n output_file: fileFor.get(signal.index) ?? null,\n })),\n estimate: {\n rows: plan.estimate.rows,\n // Character count of the CSV. With --gzip the file on disk is smaller than this.\n bytes: plan.estimate.bytes,\n exceeds_spreadsheet_limit: plan.estimate.exceedsSpreadsheetLimit,\n },\n // The plan's mixed-rate warning replaces the header parser's, as it does everywhere\n // else. This was the one consumer left out of that when 0.3.2 made the warning follow\n // --channels, so `--info --json` carried it twice: once counting the rates being\n // converted and once counting every rate in the file, with the same code and severity.\n warnings: plan.diagnostics\n .concat(withoutFileRateWarning(file.diagnostics))\n .map((d) => ({ code: d.code, severity: d.severity, message: d.message })),\n },\n null,\n indent ?? undefined,\n );\n}\n\n/** One line per diagnostic, prefixed so warnings are greppable. */\nexport function formatDiagnostics(diagnostics: readonly Diagnostic[]): string {\n return diagnostics\n .map((d) => {\n // Diagnostics quote channel labels, which come from the file, so they need the\n // same treatment as the --info table.\n const head = `${d.severity === 'warning' ? 'warning' : 'note'}: ${printable(d.message)}`;\n return d.hint ? `${head}\\n ${printable(d.hint)}` : head;\n })\n .join('\\n');\n}\n\nexport function formatSummary(result: ConvertResult): string {\n const lines: string[] = [];\n const rows: string[][] = [];\n for (const file of result.files) {\n // `.csv.gz` is still a CSV, and its rows are still rows. The suffix test dropped the\n // unit from every line of a --gzip summary, so the numbers stood on their own.\n rows.push([\n ` ${file.name}`,\n file.rows.toLocaleString('en-US'),\n /\\.csv(\\.gz)?$/u.test(file.name) ? 'rows' : '',\n ]);\n }\n lines.push(`Wrote ${result.outputDir}`);\n lines.push(table(rows, new Set([1])));\n lines.push(`Done in ${(result.elapsedMs / 1000).toFixed(1)}s.`);\n return lines.join('\\n');\n}\n\nexport function summaryJson(result: ConvertResult, indent: number | null = 2): string {\n return JSON.stringify(\n {\n output_dir: result.outputDir,\n files: result.files,\n annotations: result.annotationCount,\n duration_seconds: result.file.durationSeconds,\n records: result.file.recordCount,\n elapsed_ms: result.elapsedMs,\n warnings: result.diagnostics.map((d) => ({ code: d.code, severity: d.severity, message: d.message })),\n },\n null,\n indent ?? undefined,\n );\n}\n"]}
package/dist/cli.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;;;;GAOG;AAeH,OAAO,EAA+C,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AA6HjG,wBAAsB,IAAI,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CA0WnE;AA2xBD,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;;;;GAOG;AAeH,OAAO,EAA+C,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AA6HjG,wBAAsB,IAAI,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAkanE;AAyyBD,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
package/dist/cli.js CHANGED
@@ -57,7 +57,7 @@ Options
57
57
  --json Print machine-readable JSON to stdout (works with --info too)
58
58
  --strict Exit 1 if the recording raised any warning
59
59
  --stdout Write the signal CSV to stdout instead of a directory
60
- (single-rate recordings only)
60
+ (one table only: one sampling rate, or --layout long)
61
61
  -h, --help Show this help
62
62
  -V, --version Show the version
63
63
 
@@ -208,6 +208,24 @@ export async function main(argv) {
208
208
  process.stderr.write(`error: ${printable(entry)}: could not be read, so any recordings inside it were skipped.\n`);
209
209
  }
210
210
  if (expanded.length === 0) {
211
+ /*
212
+ "None here" and "could not look" are different answers, and so are their exit codes.
213
+
214
+ A folder the process cannot read gave the same exit 2 and the same "No EDF or BDF
215
+ recordings found" as an empty one — while the line above it said the folder could not
216
+ be read. Exit 2 is this tool's code for "the command itself was wrong", so a script
217
+ was being told to fix its arguments when what needed fixing was a permission. The
218
+ command was fine; the filesystem refused.
219
+
220
+ And the sentence itself claimed a fact the run is in no position to state: nothing was
221
+ found because nothing was looked at.
222
+ */
223
+ if (unreadable.length > 0) {
224
+ process.stderr.write(`Nothing could be converted: ${unreadable.length === 1 ? 'that path' : 'those paths'} ` +
225
+ `could not be read, so whether ${unreadable.length === 1 ? 'it holds' : 'they hold'} ` +
226
+ `recordings is unknown.\n`);
227
+ return EXIT_ERROR;
228
+ }
211
229
  process.stderr.write(`No EDF or BDF recordings found in ${listed(positionals.map((p) => `"${p}"`))}.\n`);
212
230
  return EXIT_USAGE;
213
231
  }
@@ -235,14 +253,47 @@ export async function main(argv) {
235
253
  'Use --stdout for the CSV, or --json for the summary.\n');
236
254
  return EXIT_USAGE;
237
255
  }
238
- // One stream holds one table, for the same reason it holds one recording: concatenating
239
- // them would give a CSV whose rows come from different files with nothing marking where
240
- // one ends. Naming the count makes it obvious a glob was the cause.
256
+ /*
257
+ One stream holds one table, for the same reason it holds one recording: concatenating
258
+ them would give a CSV whose rows come from different files with nothing marking where
259
+ one ends. Naming the count makes it obvious a glob was the cause — except when the count
260
+ is one, which happens for a folder holding a single recording. That read "--stdout writes
261
+ a single CSV, so it cannot take 1 recordings": ungrammatical, and wrong on its face, since
262
+ one recording is exactly what it can take. What it cannot take is a folder, whose contents
263
+ are not known until they are walked.
264
+ */
241
265
  if (toStdout && batch) {
242
- process.stderr.write(`--stdout writes a single CSV, so it cannot take ${inputs.length} recordings.\n` +
243
- `Convert them to directories instead, or run edf2csv once per file.\n`);
266
+ process.stderr.write(inputs.length === 1
267
+ ? `--stdout writes a single CSV, and a folder is converted as a batch even when it ` +
268
+ `holds one recording.\nName the recording itself — ${inputs[0]} — or convert to a ` +
269
+ `directory instead.\n`
270
+ : `--stdout writes a single CSV, so it cannot take ${inputs.length} recordings.\n` +
271
+ `Convert them to directories instead, or run edf2csv once per file.\n`);
244
272
  return EXIT_USAGE;
245
273
  }
274
+ /*
275
+ Flags that --stdout has nowhere to put.
276
+
277
+ Both were accepted and dropped in silence. `--out` names a directory that is never
278
+ created, so the run looked like it had written one. `--checksum` is worse than useless:
279
+ the hash is computed before the first record is read, which is a second full pass over
280
+ the input, and then the only file it is ever written to — metadata.json — is not written
281
+ at all. A recording large enough to want a checksum is large enough to notice reading it
282
+ twice for nothing.
283
+
284
+ Refusing rather than ignoring is what this tool already does for `--stdout --json` and
285
+ `--stdout --annotations-only`.
286
+ */
287
+ for (const [flag, given] of [
288
+ ['--out', values['out'] !== undefined],
289
+ ['--checksum', values['checksum'] === true],
290
+ ]) {
291
+ if (toStdout && given) {
292
+ process.stderr.write(`--stdout and ${flag} cannot be combined: --stdout writes no files, and ${flag} has ` +
293
+ `nothing to act on.\nDrop ${flag}, or drop --stdout and convert to a directory.\n`);
294
+ return EXIT_USAGE;
295
+ }
296
+ }
246
297
  /*
247
298
  One recording prints the document it always printed; several print one per line.
248
299
 
@@ -581,7 +632,18 @@ async function convertOne(input, destination, options, emit = writeThrough) {
581
632
  // thing worth saying — on stderr, so the CSV on stdout stays clean.
582
633
  if (toStdout) {
583
634
  const rows = result.files[0]?.rows ?? 0;
584
- emit('err', `Wrote ${rows.toLocaleString('en-US')} rows to stdout.\n`);
635
+ /*
636
+ A reader that closed the pipe did not receive a conversion, so it does not get a
637
+ conversion's summary. `edf2csv rec.edf --stdout | head -1` announced "Wrote 52,507
638
+ rows to stdout" — a number that is neither the recording's 102,400 nor the one row
639
+ head took, but however many had been formatted before the close was noticed. The
640
+ count that reached the reader is not knowable from this side; that it stopped early
641
+ is, so that is what is said.
642
+ */
643
+ emit('err', result.readerHungUp
644
+ ? `Stopped: the reader closed the pipe after ${rows.toLocaleString('en-US')} rows ` +
645
+ `had been written. The recording was not converted in full.\n`
646
+ : `Wrote ${rows.toLocaleString('en-US')} rows to stdout.\n`);
585
647
  }
586
648
  else {
587
649
  emit('err', `${formatSummary(result)}\n`);