kopia lustrzana https://github.com/projecthorus/chasemapper
Update to new sondehub report recovery system
rodzic
d3cf470cc8
commit
847d32b18d
|
@ -8,4 +8,4 @@
|
|||
|
||||
# Now using Semantic Versioning (https://semver.org/) MAJOR.MINOR.PATCH
|
||||
|
||||
__version__ = "1.2.3"
|
||||
__version__ = "1.3.0"
|
||||
|
|
|
@ -205,12 +205,21 @@ class HabitatChaseUploader(object):
|
|||
""" Set the callsign """
|
||||
self.callsign = call
|
||||
|
||||
def mark_payload_recovered(self, callsign, latitude, longitude, altitude, message):
|
||||
#def mark_payload_recovered(self, callsign, latitude, longitude, altitude, message):
|
||||
def mark_payload_recovered(self, serial=None, callsign=None, lat=0.0, lon=0.0, alt=0.0, message="", recovered=True):
|
||||
""" Upload an indication that a payload (radiosonde or otherwise) has been recovered """
|
||||
|
||||
if serial is None:
|
||||
return
|
||||
|
||||
if recovered:
|
||||
_call = serial + " recovered by " + callsign
|
||||
else:
|
||||
_call = serial + " not recovered by " + callsign
|
||||
|
||||
try:
|
||||
initListenerCallsign(callsign, radio="", antenna=message)
|
||||
uploadListenerPosition(callsign, latitude, longitude, altitude, chase=False)
|
||||
initListenerCallsign(_call, radio="", antenna=message)
|
||||
uploadListenerPosition(_call, lat, lon, alt, chase=False)
|
||||
except Exception as e:
|
||||
logging.error(
|
||||
"Habitat - Unable to mark payload as recovered - %s" % (str(e))
|
||||
|
|
|
@ -29,6 +29,7 @@ class SondehubChaseUploader(object):
|
|||
""" Upload supplied chase car positions to Sondehub on a regular basis """
|
||||
|
||||
SONDEHUB_STATION_POSITION_URL = "https://api.v2.sondehub.org/listeners"
|
||||
SONDEHUB_SONDE_RECOVERED_URL = "https://api.v2.sondehub.org/recovered"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
@ -172,10 +173,83 @@ class SondehubChaseUploader(object):
|
|||
)
|
||||
logging.debug(f"Attempted to upload {json.dumps(_position)}")
|
||||
|
||||
def mark_payload_recovered(self, callsign, latitude, longitude, altitude, message):
|
||||
|
||||
def mark_payload_recovered(self, serial=None, callsign=None, lat=0.0, lon=0.0, alt=0.0, message="", recovered=True):
|
||||
""" Upload an indication that a payload (radiosonde or otherwise) has been recovered """
|
||||
# TODO
|
||||
pass
|
||||
|
||||
if serial is None:
|
||||
return
|
||||
|
||||
_doc = {
|
||||
"serial": serial,
|
||||
"lat": lat,
|
||||
"lon": lon,
|
||||
"alt": alt,
|
||||
"recovered": recovered,
|
||||
"recovered_by": callsign,
|
||||
"description": message
|
||||
}
|
||||
|
||||
_retries = 0
|
||||
_upload_success = False
|
||||
|
||||
_start_time = time.time()
|
||||
|
||||
while _retries < self.upload_retries:
|
||||
# Run the request.
|
||||
try:
|
||||
headers = {
|
||||
"User-Agent": "chasemapper-" + chasemapper.__version__,
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
_req = requests.put(
|
||||
self.SONDEHUB_SONDE_RECOVERED_URL,
|
||||
json=_doc,
|
||||
# TODO: Revisit this second timeout value.
|
||||
timeout=(self.upload_timeout, 6.1),
|
||||
headers=headers,
|
||||
)
|
||||
except Exception as e:
|
||||
logging.error("Sondehub - Recovery Upload Failed: %s" % str(e))
|
||||
return
|
||||
|
||||
if _req.status_code == 200:
|
||||
# 200 is the only status code that we accept.
|
||||
_upload_time = time.time() - _start_time
|
||||
logging.info("Sondehub - Uploaded recovery notification to Sondehub.")
|
||||
_upload_success = True
|
||||
break
|
||||
|
||||
elif _req.status_code == 400:
|
||||
try:
|
||||
_resp = json.loads(_req.text)
|
||||
logging.info(f"Sondehub - {_resp['message']}")
|
||||
except:
|
||||
logging.info(f"Sondehub - Got code 400 from Sondehub.")
|
||||
|
||||
_upload_success = True
|
||||
break
|
||||
|
||||
elif _req.status_code == 500:
|
||||
# Server Error, Retry.
|
||||
_retries += 1
|
||||
continue
|
||||
|
||||
else:
|
||||
logging.error(
|
||||
"Sondehub - Error uploading recovery notification to Sondehub. Status Code: %d %s."
|
||||
% (_req.status_code, _req.text)
|
||||
)
|
||||
break
|
||||
|
||||
if not _upload_success:
|
||||
logging.error(
|
||||
"Sondehub - Recovery notification upload failed after %d retries"
|
||||
% (_retries)
|
||||
)
|
||||
logging.debug(f"Attempted to upload {json.dumps(_doc)}")
|
||||
|
||||
|
||||
|
||||
def close(self):
|
||||
self.uploader_thread_running = False
|
||||
|
|
|
@ -707,18 +707,24 @@ def mark_payload_recovered(data):
|
|||
""" Mark a payload as recovered, by uploading a station position """
|
||||
global online_uploader
|
||||
|
||||
_callsign = data["recovery_title"]
|
||||
_serial = data["payload_call"]
|
||||
_callsign = data["my_call"]
|
||||
_lat = data["last_pos"][0]
|
||||
_lon = data["last_pos"][1]
|
||||
_alt = data["last_pos"][2]
|
||||
_msg = (
|
||||
data["message"]
|
||||
+ " Recovered at "
|
||||
+ datetime.utcnow().strftime("%Y-%m-%d %H:%MZ")
|
||||
)
|
||||
_msg = data["message"]
|
||||
_recovered = data["recovered"]
|
||||
|
||||
if online_uploader != None:
|
||||
online_uploader.mark_payload_recovered(_callsign, _lat, _lon, _alt, _msg)
|
||||
online_uploader.mark_payload_recovered(
|
||||
serial = _serial,
|
||||
callsign = _callsign,
|
||||
lat = _lat,
|
||||
lon = _lon,
|
||||
alt = _alt,
|
||||
message = _msg,
|
||||
recovered=_recovered
|
||||
)
|
||||
else:
|
||||
logging.error("No Online Tracker enabled, could not mark payload as recovered.")
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ function updateRangeRings(){
|
|||
|
||||
}
|
||||
|
||||
function reconfigureCarMarker(profile_name){
|
||||
var reconfigureCarMarker = function(profile_name){
|
||||
// Remove chase-car marker if it exists, and is not used.
|
||||
if( (chase_config.profiles[profile_name].car_source_type === "none") || (chase_config.profiles[profile_name].car_source_type === "station")){
|
||||
if (chase_car_position.marker !== "NONE"){
|
||||
|
|
|
@ -40,7 +40,8 @@ function markPayloadRecovered(callsign){
|
|||
var _recovery_data = {
|
||||
my_call: chase_config.habitat_call,
|
||||
payload_call: callsign,
|
||||
recovery_title: callsign + " recovered by " + chase_config.habitat_call,
|
||||
recovered: $("#recoverySuccessful").is(':checked'),
|
||||
recovery_title: callsign,
|
||||
last_pos: balloon_positions[callsign].latest_data.position,
|
||||
message: ""
|
||||
};
|
||||
|
@ -49,6 +50,13 @@ function markPayloadRecovered(callsign){
|
|||
$('#customRecoveryTitle').val(_recovery_data.recovery_title);
|
||||
$('#recoveryPosition').html(_recovery_data.last_pos[0].toFixed(5) + ", " + _recovery_data.last_pos[1].toFixed(5));
|
||||
|
||||
if (chase_config.profiles[chase_config.selected_profile].online_tracker === "sondehub"){
|
||||
// Only allow the serial number for sondehub uploads
|
||||
$('#customRecoveryTitle').prop('disabled', true);
|
||||
} else {
|
||||
$('#customRecoveryTitle').prop('disabled', false);
|
||||
}
|
||||
|
||||
// Pop up a dialog box so the user can enter a custom message if they want.
|
||||
var divObj = $('#mark-recovered-dialog');
|
||||
divObj.dialog({
|
||||
|
@ -64,6 +72,7 @@ function markPayloadRecovered(callsign){
|
|||
$( this ).dialog( "close" );
|
||||
_recovery_data.message = $('#customRecoveryMessage').val();
|
||||
_recovery_data.recovery_title = $('#customRecoveryTitle').val();
|
||||
_recovery_data.recovered = $("#recoverySuccessful").is(':checked');
|
||||
|
||||
// If the user has requested to use the chase car position, override the last position with it.
|
||||
if(document.getElementById("recoveryCarPosition").checked == true){
|
||||
|
|
|
@ -706,6 +706,9 @@
|
|||
<div class="paramRow">
|
||||
<b>Last Position:</b> <div style='float:right;' id='recoveryPosition'></div><br/>
|
||||
</div>
|
||||
<div class="paramRow">
|
||||
<b>Recovery Successful:</b> <input type="checkbox" class="paramSelector" id="recoverySuccessful" checked><br/>
|
||||
</div>
|
||||
<div class="paramRow">
|
||||
<b>Use Car Position:</b> <input type="checkbox" class="paramSelector" id="recoveryCarPosition" onclick='setRecoveryCarPosition();'><br/>
|
||||
</div>
|
||||
|
|
Ładowanie…
Reference in New Issue