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

Fix influxdb conversion to tower frame

parent e4fdc182
No related branches found
No related tags found
No related merge requests found
......@@ -52,6 +52,8 @@ def main():
import argparse
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--logfn', help='Log to rotating file')
parser.add_argument('--debug', action='store_true',
help='Don\'t submit records to the database, print them to stdout')
parser.add_argument('-t', '--tail', action='store_true',
help=('Tail file forever, not returning. This will start at the end '
'of the file and insert any new data added after starting'))
......@@ -92,11 +94,14 @@ def main():
for idx, record in enumerate(record_gen):
LOG.info("Inserting records for frame %d", idx)
record = {symbols[k] or k: v for k, v in record.items() if k in symbols}
lines = influxdb.frame_records(record, **station_tags)
resp = requests.post(
'http://{host}:{port:d}/write?db={dbname}'.format(host=args.host, port=args.port, dbname=args.dbname),
data='\n'.join(lines))
resp.raise_for_status()
if args.debug:
print(idx, record)
else:
lines = influxdb.frame_records(record, **station_tags)
resp = requests.post(
'http://{host}:{port:d}/write?db={dbname}'.format(host=args.host, port=args.port, dbname=args.dbname),
data='\n'.join(lines))
resp.raise_for_status()
if args.sleep_interval:
time.sleep(args.sleep_interval)
......
......@@ -64,13 +64,13 @@ class LineParseError(Exception):
raise exc
def _make_frame(data):
def _make_frame(data, rename_timestamp=False):
"""Construct a frame from a list of tuples.
"""
frame = {}
for key, value in data:
if key == 'stamp':
frame[key] = value
if key in ['stamp', 'timestamp']:
frame['stamp' if rename_timestamp else key] = value
continue
if key in database:
try:
......@@ -217,7 +217,7 @@ def read_frames(source, error_handler=lambda *a: None, tail=False):
def loggernet_to_tower(rec_dict):
"""Convert loggernet record dictionary to our standard naming"""
return _make_frame(zip(ParserV1V2.names, rec_dict.values()))
return _make_frame(zip(ParserV1V2.names, rec_dict.values()), rename_timestamp=True)
def ldmp_generator(station_name, tables):
......
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