Mercurial > lbo > hg > geohub
changeset 127:07984965bbb7
Merge
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Sat, 06 Mar 2021 14:49:00 +0100 |
parents | 8572be3ea3f1 (diff) 3798cd438c3c (current diff) |
children | 0fff2024f54a |
files | assets/livemap.html |
diffstat | 2 files changed, 23 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/assets/livemap.html Sat Mar 06 13:21:28 2021 +0100 +++ b/assets/livemap.html Sat Mar 06 14:49:00 2021 +0100 @@ -55,7 +55,6 @@ let accuracy = props.accuracy; var oldCoord = current_marker.getLatLng(); current_marker.setLatLng(L.latLng(lat, lng)); - console.log(current_marker); // Show accuracy of current location const currentCircleProps = { color: 'aqua', @@ -126,7 +125,7 @@ var coords = lastfeature['geometry']['coordinates']; - console.log('Received update:', coords, 'last:', response); + //console.log('Received update:', coords, 'last:', response); setCurrentLocation(coords[1], coords[0], lastfeature.properties); // 13 is a good default zoom for an updated point. mymap.setView([coords[1], coords[0]], mapZoomed ? mymap.getZoom() : 13); @@ -172,7 +171,7 @@ } var secretparam = secret == null ? '' : `secret=${secret}`; var url = `../../geo/${client}/retrieve/live?${secretparam}&timeout=30`; - console.log('Requesting URL ' + url); + //console.log('Requesting URL ' + url); xhr.responseType = 'json'; xhr.open('GET', url, true); xhr.onreadystatechange = function() { xhrcallback(xhr) };
--- a/examples/track_ICE/collect.py Sat Mar 06 13:21:28 2021 +0100 +++ b/examples/track_ICE/collect.py Sat Mar 06 14:49:00 2021 +0100 @@ -12,8 +12,13 @@ def eprint(*args): print(*args, file=sys.stderr) -def fetch_current(api): - return requests.get(api).json() +def fetch_current(sess, api): + while True: + try: + return requests.get(api).json() + except requests.exceptions.ConnectionError as e: + eprint('Retrying failed request:', e) + time.sleep(3) def format_server_time(servertime): return time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(servertime/1000)) @@ -42,7 +47,8 @@ return parser.parse_args() def run(args): - info = fetch_current(args.api) + session = requests.Session() + info = fetch_current(session, args.api) if not info: eprint('Empty info received!') return @@ -52,19 +58,23 @@ eprint('Running in train:', tzn) eprint('Go to LiveMap:', livemap_url); - 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(session, 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()