Skip to content

Commit

Permalink
fix unordered header in parsed files
Browse files Browse the repository at this point in the history
  • Loading branch information
ewancook committed Apr 20, 2020
1 parent d7d1312 commit 087cc1d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions transcriber/converter/workers/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ def work(self):

def convert(self):
with open(self.filename) as file:
lines = set([self.tag_lookup.index(t) for t in self.tags])
lines = sorted([self.tag_lookup.index(t) for t in self.tags])
lines_set = set(lines)

total_tags = self.total_tags

with open(utils.transcribed_filename(self.filename), "w") as out:
Expand All @@ -29,7 +31,7 @@ def convert(self):
)
)
for i, line in enumerate(islice(file, 1, None)):
if i % total_tags not in lines:
if i % total_tags not in lines_set:
continue
if tags_written == num_tags:
date, time, _, val = utils.data_from_line(line)
Expand All @@ -45,15 +47,15 @@ def __init__(self, filename, tags, tag_lookup):
super(DBFWorker, self).__init__(filename, tags, tag_lookup)
self.parser = Parser(
required_fields=["Date", "Time", "Value"],
required_tags=set([self.tag_lookup.index(t) for t in self.tags]),
required_tags=[self.tag_lookup.index(t) for t in self.tags],
total_tags=self.total_tags,
)

def convert(self):
table = self.parser.parse_selection(self.filename)
double_struct = Struct("<d")

lines = set([self.tag_lookup.index(t) for t in self.tags])
lines = sorted([self.tag_lookup.index(t) for t in self.tags])

with open(utils.transcribed_filename(self.filename), "w") as out:
out.write(
Expand Down
2 changes: 1 addition & 1 deletion transcriber/dbf/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def __init__(
):
self.required_fields = set(required_fields)
self.encoding = encoding
self.required_tags = required_tags
self.required_tags = set(required_tags)
self.total_tags = total_tags

@property
Expand Down

0 comments on commit 087cc1d

Please sign in to comment.