Skip to content

Commit 81bd550

Browse files
authored
Merge pull request #20 from cmu-delphi/sgatzl/upload_fix
fix upload for simple cases
2 parents 1fd3e95 + 8d0d655 commit 81bd550

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

samples/simple.csv

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
a,date,v
2+
1,2022-01-01,1
3+
1,2022-01-02,2
4+
1,2022-01-03,3
5+
1,2022-01-04,4
6+
1,2022-01-05,3

src/components/dialogs/ImportCSVDialog.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
transpose,
3333
hasHeader,
3434
dateType: dateType == 'none' ? null : dateType,
35-
dateFormat: dateType == 'simple' ? 'YYYY-MM-DD' : 'undefined',
35+
dateFormat: dateType == 'simple' ? 'yyyy-MM-dd' : 'undefined',
3636
dateCol1: Number.parseInt(dateColumn, 10),
3737
dateCol2: Number.parseInt(dateColumn1, 10),
3838
hasGroup,

src/data/importCSV.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,27 @@ function asDataGroup(group: IDataGroup): DataGroup {
3737
}
3838

3939
export default function importCSV(file: File, fileContent: string, options: CSVOptions): DataGroup {
40-
let lines = '';
40+
const lines: string[] = [];
4141
for (const row of fileContent.split('\n')) {
4242
const trimmed = row.trim();
4343
if (trimmed[0] === '#') {
4444
continue;
4545
}
46-
lines += trimmed;
46+
lines.push(trimmed);
4747
}
48-
let rows = csvParseRows(lines);
48+
let rows = csvParseRows(lines.join('\n'));
4949
let numColumns = rows.reduce((acc, v) => Math.max(acc, v.length), 0);
5050
if (options.transpose) {
5151
numColumns = rows.length;
5252
rows = transpose(rows, numColumns);
5353
}
5454

55-
let labels = Array(numColumns).map((_, i) => `Column ${i}`);
55+
let labels = Array(numColumns)
56+
.fill(0)
57+
.map((_, i) => `Column ${i}`);
5658

5759
let groups: { label: string; level: number; rows: string[][] }[] = [{ label: file.name, level: 0, rows: [] }];
5860
let activeGroup = groups[0];
59-
groups.push(activeGroup);
6061

6162
let foundHeader = false;
6263
for (const row of rows) {
@@ -207,7 +208,7 @@ function parseDate(values: string[], lineIndex: number, options: CSVOptions): Ep
207208
}
208209
return new EpiDate(2000, 1, 1).addDays(lineIndex);
209210
} catch (error) {
210-
console.error('invalid date in row', values, options);
211+
console.error('invalid date in row', values, options, error);
211212
return null;
212213
}
213214
}

0 commit comments

Comments
 (0)