Skip to content

Commit

Permalink
add detection of header line
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Blumentrath committed Mar 27, 2019
1 parent abbaf1b commit 3bed98a
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions scripts/csv2dat.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,23 @@ def csv2dat(path, observationColumns, timestampColumn, timestampFormat, offset,
datPath = get_dat_filepath(path[:-4], procedure)
o = open(datPath, 'w')

header, columnsIndexes = get_header(i.readline(),
for line in i:
if all(col in line for col in observationColumns.split(',') + [timestampColumn]):
headerLine = line
break
else:
headerLine = None

if not headerLine:
print('ERROR: Could not find header line in file {}'.format(i.name))
exit(0)

header, columnsIndexes = get_header(headerLine,
timestampColumn,
observationColumns)
o.write(header)

for line in i.readlines():
for line in i:
o.write(get_observations(line, timestampFormat, offset,
columnsIndexes))

Expand All @@ -65,12 +76,23 @@ def csv2dat(path, observationColumns, timestampColumn, timestampFormat, offset,
datPath = get_dat_filepath(file[:-4], procedure)
o = open(datPath, 'w')

header, columnsIndexes = get_header(i.readline(),
for line in i:
if all(col in line for col in observationColumns.split(',') + [timestampColumn]):
headerLine = line
break
else:
headerLine = None

if not headerLine:
print('ERROR: Could not find header line in file {}'.format(i.name))
exit(0)

header, columnsIndexes = get_header(headerLine,
timestampColumn,
observationColumns)
o.write(header)

for line in i.readlines():
for line in i:
o.write(get_observations(line, timestampFormat, offset,
columnsIndexes))

Expand Down

0 comments on commit 3bed98a

Please sign in to comment.