kopia lustrzana https://github.com/projecthorus/chasemapper
commit
a2c082a169
|
@ -54,6 +54,9 @@ default_config = {
|
|||
'bearing_color': 'black',
|
||||
'bearing_custom_color': '#FF0000',
|
||||
|
||||
# History
|
||||
'reload_last_position': False
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -179,11 +182,16 @@ def parse_config_file(filename):
|
|||
logging.critical("Default profile selection does not exist.")
|
||||
return None
|
||||
|
||||
# History
|
||||
|
||||
chase_config['reload_last_position'] = config.getboolean('history', 'reload_last_position', fallback=False)
|
||||
|
||||
return chase_config
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def read_config(filename, default_cfg="horusmapper.cfg.example"):
|
||||
""" Read in a Horus Mapper configuration file,and return as a dict. """
|
||||
|
||||
|
|
|
@ -193,3 +193,6 @@ class GenericTrack(object):
|
|||
_track_points = np.column_stack((_track_data_np[:,1], _track_data_np[:,2], _track_data_np[:,3]))
|
||||
|
||||
return _track_points.tolist()
|
||||
|
||||
def length(self):
|
||||
return len(self.track_history)
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# Project Horus - Log read operations
|
||||
#
|
||||
# Copyright (C) 2019 Mark Jessop <vk5qi@rfhead.net>
|
||||
# Released under GNU GPL v3 or later
|
||||
#
|
||||
import datetime
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import pytz
|
||||
import time
|
||||
#from datetime import datetime
|
||||
from dateutil.parser import parse
|
||||
|
||||
|
||||
|
||||
def read_file(filename):
|
||||
""" Read log file, and output an array of dicts. """
|
||||
_output = []
|
||||
|
||||
_f = open(filename, 'r')
|
||||
for _line in _f:
|
||||
try:
|
||||
_data = json.loads(_line)
|
||||
_output.append(_data)
|
||||
except Exception as e:
|
||||
logging.debug("Error reading line: %s" % str(e))
|
||||
if len(_output) != 0 :
|
||||
logging.info("Read %d log entries from %s" % (len(_output), filename))
|
||||
|
||||
return _output
|
||||
|
||||
|
||||
|
||||
def read_last_balloon_telemetry():
|
||||
""" Read last balloon telemetry. Need to work back from last file to find balloon telemetry and read the last entry - don't return until whole file scanned
|
||||
"""
|
||||
_lasttelemetry = []
|
||||
dirs = sorted(os.listdir("./log_files"),reverse = True) # Generate a reverse sorted list - will have to look through to find last log_file with telemetry
|
||||
for file in dirs:
|
||||
if file.endswith(".log"):
|
||||
telemetry_found = False
|
||||
try:
|
||||
log = read_file("./log_files/" + file)
|
||||
except Exception as e:
|
||||
logging.debug("Error reading file - maybe in use")
|
||||
for _entry in log:
|
||||
if _entry['log_type'] == "BALLOON TELEMETRY":
|
||||
telemetry_found = True
|
||||
_last_telemetry = _entry
|
||||
if telemetry_found == True:
|
||||
_last_telemetry['time_dt'] = parse(_last_telemetry.pop('time'))
|
||||
return _last_telemetry
|
|
@ -243,6 +243,9 @@ unitselection = metric
|
|||
switch_miles_feet = 400
|
||||
|
||||
|
||||
|
||||
[history]
|
||||
|
||||
# Enable load of last position from log files (True/False)
|
||||
reload_last_position = False
|
||||
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ from chasemapper.listeners import OziListener, UDPListener, fix_datetime
|
|||
from chasemapper.predictor import predictor_spawn_download, model_download_running
|
||||
from chasemapper.habitat import HabitatChaseUploader, initListenerCallsign, uploadListenerPosition
|
||||
from chasemapper.logger import ChaseLogger
|
||||
from chasemapper.logread import read_last_balloon_telemetry
|
||||
from chasemapper.bearings import Bearings
|
||||
from chasemapper.tawhiri import get_tawhiri_prediction
|
||||
|
||||
|
@ -125,7 +126,7 @@ def flask_server_tiles(filename):
|
|||
|
||||
def flask_emit_event(event_name="none", data={}):
|
||||
""" Emit a socketio event to any clients. """
|
||||
socketio.emit(event_name, data, namespace='/chasemapper')
|
||||
socketio.emit(event_name, data, namespace='/chasemapper')
|
||||
|
||||
|
||||
@socketio.on('client_settings_update', namespace='/chasemapper')
|
||||
|
@ -158,7 +159,7 @@ def client_settings_update(data):
|
|||
# Wait until any current predictions have finished.
|
||||
while predictor_semaphore:
|
||||
time.sleep(0.1)
|
||||
|
||||
|
||||
predictor = None
|
||||
|
||||
# Start or Stop the Habitat Chase-Car Uploader.
|
||||
|
@ -182,7 +183,7 @@ def client_settings_update(data):
|
|||
|
||||
|
||||
|
||||
def handle_new_payload_position(data):
|
||||
def handle_new_payload_position(data, log_position = True):
|
||||
|
||||
_lat = data['lat']
|
||||
_lon = data['lon']
|
||||
|
@ -270,9 +271,10 @@ def handle_new_payload_position(data):
|
|||
flask_emit_event('telemetry_event', current_payloads[_callsign]['telem'])
|
||||
|
||||
# Add the position into the logger
|
||||
if chase_logger:
|
||||
if chase_logger and log_position:
|
||||
chase_logger.add_balloon_telemetry(data)
|
||||
|
||||
else :
|
||||
logging.info("Point not logged")
|
||||
|
||||
def handle_modem_stats(data):
|
||||
""" Basic handling of modem statistics data. If it matches a known payload, send the info to the client. """
|
||||
|
@ -310,7 +312,7 @@ def run_prediction():
|
|||
|
||||
if (chasemapper_config['pred_enabled'] == False):
|
||||
return
|
||||
|
||||
|
||||
if (chasemapper_config['offline_predictions'] == True) and (predictor == None):
|
||||
return
|
||||
|
||||
|
@ -326,8 +328,13 @@ def run_prediction():
|
|||
logging.debug("Skipping prediction for %s due to old data." % _payload)
|
||||
continue
|
||||
|
||||
|
||||
|
||||
_current_pos = current_payload_tracks[_payload].get_latest_state()
|
||||
_current_pos_list = [0,_current_pos['lat'], _current_pos['lon'], _current_pos['alt']]
|
||||
if current_payload_tracks[_payload].length() <= 1:
|
||||
logging.info("Only %i point in this payload's track, skipping prediction.", current_payload_tracks[_payload].length())
|
||||
continue
|
||||
|
||||
_pred_ok = False
|
||||
_abort_pred_ok = False
|
||||
|
@ -998,6 +1005,18 @@ if __name__ == "__main__":
|
|||
habitat_uploader = HabitatChaseUploader(update_rate = chasemapper_config['habitat_update_rate'],
|
||||
callsign=chasemapper_config['habitat_call'])
|
||||
|
||||
# Read in last known position, if enabled
|
||||
|
||||
if chasemapper_config['reload_last_position']:
|
||||
logging.info("Read in last position requested")
|
||||
try:
|
||||
handle_new_payload_position(read_last_balloon_telemetry(),False);
|
||||
except Exception as e:
|
||||
logging.info("Unable to read in last position")
|
||||
else:
|
||||
logging.info("Read in last position not requested")
|
||||
|
||||
|
||||
# Start up the data age monitor thread.
|
||||
_data_age_monitor = Thread(target=check_data_age)
|
||||
_data_age_monitor.start()
|
||||
|
|
Ładowanie…
Reference in New Issue