Mercurial > lbo > hg > geohub
changeset 120:5c68b135deef
track_ICE: enable deduplication and adaptive interval
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Sat, 16 Jan 2021 09:23:36 +0100 |
parents | 08caf18bd9ef |
children | cd36ca05c904 |
files | examples/track_ICE/collect.py |
diffstat | 1 files changed, 13 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/examples/track_ICE/collect.py Fri Jan 01 01:22:48 2021 +0100 +++ b/examples/track_ICE/collect.py Sat Jan 16 09:23:36 2021 +0100 @@ -54,17 +54,23 @@ session = requests.Session() + lastpoint = None + with open(args.outfile, 'w') as outfile: while True: - if info: - eprint('{} :: Sending point ({}, {}) to GeoHub.'.format(format_server_time(info['serverTime']), info['longitude'], info['latitude'])) - send_point(session, args, info) - outfile.write(json.dumps(info)) - outfile.write('\n') + info = fetch_current(args.api) + if lastpoint is None or lastpoint != (info['latitude'], info['longitude']): + lastpoint = (info['latitude'], info['longitude']) + if info: + eprint('{} :: Sending point ({}, {}) to GeoHub.'.format(format_server_time(info['serverTime']), info['longitude'], info['latitude'])) + send_point(session, args, info) + outfile.write(json.dumps(info)) + outfile.write('\n') + else: + eprint('{} :: Skipped point due to no API response.'.format(format_server_time(time.time_ns()/1e6))) else: - eprint('{} :: Skipped point due to no API response.'.format(format_server_time(time.time_ns()/1e6))) + eprint('{} :: Skipped duplicate point.'.format(format_server_time(time.time_ns()/1e6))) time.sleep(args.interval) - info = fetch_current(args.api) def main(): args = parse_args()