Skip to content
Snippets Groups Projects
Verified Commit 294ea1d9 authored by David Hoese's avatar David Hoese
Browse files

Fix symbol renaming in frame generation for legacy db

parent 7d2b1e37
No related branches found
No related tags found
No related merge requests found
...@@ -64,17 +64,18 @@ class LineParseError(Exception): ...@@ -64,17 +64,18 @@ class LineParseError(Exception):
raise exc raise exc
def _make_frame(data, rename_timestamp=False): def _make_frame(data, new_symbols=None, rename_timestamp=False):
"""Construct a frame from a list of tuples. """Construct a frame from a list of tuples.
""" """
frame = {} frame = {}
for key, value in data: for idx, (key, value) in enumerate(data):
if key in ['stamp', 'timestamp']: if key in ['stamp', 'timestamp']:
frame['stamp' if rename_timestamp else key] = value frame['stamp' if rename_timestamp else key] = value
continue continue
if key in database: if key in database:
try: try:
frame[key] = database[key].type(value) new_key = new_symbols[idx] if new_symbols and len(new_symbols) > idx else key
frame[new_key] = database[key].type(value)
except (ValueError, TypeError): except (ValueError, TypeError):
raise LineParseError("error converting '%s' using %s", raise LineParseError("error converting '%s' using %s",
value, database[key].type) value, database[key].type)
...@@ -218,7 +219,8 @@ def read_frames(source, error_handler=lambda *a: None, tail=False): ...@@ -218,7 +219,8 @@ def read_frames(source, error_handler=lambda *a: None, tail=False):
def loggernet_to_tower(rec_dict, symbol_names): def loggernet_to_tower(rec_dict, symbol_names):
"""Convert loggernet record dictionary to our standard naming""" """Convert loggernet record dictionary to our standard naming"""
# assume that the next record after the traditional frame is the timestamp # assume that the next record after the traditional frame is the timestamp
return _make_frame(zip(['timestamp'] + symbol_names, rec_dict.values()), rename_timestamp=True) new_symbols = ['timestamp'] + symbol_names
return _make_frame(zip(new_symbols, rec_dict.values()), new_symbols, rename_timestamp=True)
def ldmp_generator(station_name, tables, symbol_names=ParserV1V2.names): def ldmp_generator(station_name, tables, symbol_names=ParserV1V2.names):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment