Skip to content

Commit

Permalink
Incorporate PR feedback
Browse files Browse the repository at this point in the history
* Add empty record type into conversion script
  • Loading branch information
DocGarbanzo committed Dec 23, 2020
1 parent 35d6ac8 commit 3b4e42a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 0 additions & 4 deletions donkeycar/parts/tub_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class Tub(object):
A datastore to store sensor data in a key, value format. \n
Accepts str, int, float, image_array, image, and array data types.
"""
# static variable for empty records
empty_record = {'__empty__': True}

def __init__(self, base_path, inputs=[], types=[], metadata=[],
max_catalog_len=1000, read_only=False):
Expand All @@ -35,8 +33,6 @@ def write_record(self, record=None):
"""
Can handle various data types including images.
"""
if not record:
record = self.empty_record
contents = dict()
for key, value in record.items():
if value is None:
Expand Down
11 changes: 8 additions & 3 deletions scripts/convert_to_tub_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@


def convert_to_tub_v2(paths, output_path):
empty_record = {'__empty__': True}

if type(paths) is str:
paths = [paths]
legacy_tubs = [LegacyTub(path) for path in paths]
Expand All @@ -30,8 +32,11 @@ def convert_to_tub_v2(paths, output_path):

for legacy_tub in legacy_tubs:
if not output_tub:
output_tub = Tub(output_path, legacy_tub.inputs,
legacy_tub.types, list(legacy_tub.meta.items()))
# add input and type for empty records recording
inputs = legacy_tub.inputs + ['__empty__']
types = legacy_tub.types + ['boolean']
output_tub = Tub(output_path, inputs, types,
list(legacy_tub.meta.items()))

record_paths = legacy_tub.gather_records()
bar = IncrementalBar('Converting', max=len(record_paths))
Expand All @@ -58,7 +63,7 @@ def convert_to_tub_v2(paths, output_path):
# until the next valid record.
while previous_index < current_index:
idx = output_tub.manifest.current_index
output_tub.write_record()
output_tub.write_record(empty_record)
output_tub.delete_record(idx)
previous_index += 1
bar.next()
Expand Down

0 comments on commit 3b4e42a

Please sign in to comment.