Moved a load of functions to pred.js

pull/73/head
jonsowman 2010-05-31 08:14:04 +01:00
rodzic ca40a84fe5
commit 35f5b46ab1
2 zmienionych plików z 196 dodań i 195 usunięć

Wyświetl plik

@ -1,13 +1,5 @@
<?php
// if the form was submitted we should
// 1. sanity check inputs
// 2. generate an ini file
// 3. start prediction running
// 4. start ajax server poller
// 5. display the prediction data when run is complete
// 6. make the ini and the csv/kml available for download
//
// get the time for populating the form
// get the time for pre-populating the form
$time = time() + 3600;
?>
@ -36,92 +28,6 @@ if ( isset($_GET['uuid']) ) {
}
?>';
function predSub() {
appendDebug(null, 1); // clear debug window
appendDebug("Sending data to server...");
// initialise progress bar
$("#prediction_progress").progressbar({ value: 0 });
$("#prediction_status").html("Sending data to server...");
$("#status_message").fadeIn(250);
}
function handlePred(pred_uuid) {
$("#prediction_status").html("Searching for wind data...");
$("#input_form").hide("slide", { direction: "down" }, 500);
$("#map_canvas").fadeTo(1000, 0.2);
// ajax to poll for progress
ajaxEventHandle = setInterval("getJSONProgress('"+pred_uuid+"')", 2000);
//getCSV(pred_uuid);
}
function getCSV(pred_uuid) {
$.get("ajax.php", { "action":"getCSV", "uuid":pred_uuid }, function(data) {
appendDebug("Got JSON response from server for flight path, parsing...");
if (parseCSV(data) ) {
appendDebug("Parsing function returned successfully.");
appendDebug("Done, AJAX functions quitting.");
} else {
appendDebug("The parsing function failed.");
}
}, 'json');
}
function getJSONProgress(pred_uuid) {
$.ajax({
url:"preds/"+pred_uuid+"/progress.json",
dataType:'json',
timeout: 500,
// complete: function(data, httpstatus) {
// appendDebug(httpstatus);
// },
success: processProgress
});
}
function processProgress(progress) {
if ( progress['error'] ) {
clearInterval(ajaxEventHandle);
appendDebug("There was an error in running the prediction: "+progress['error']);
} else {
// get the progress of the wind data
if ( progress['gfs_complete'] == true ) {
if ( progress['pred_complete'] == true ) { // pred has finished
$("#prediction_status").html("Prediction finished.");
$("#status_message").fadeOut(500);
// now clear the status window
$("#prediction_status").html("");
$("#prediction_progress").progressbar("options", "value", 0);
$("#prediction_percent").html("");
// bring the input form back up
$("#input_form").show("slide", { direction: "down" }, 500);
// un-fade the map canvas
$("#map_canvas").fadeTo(1500, 1);
appendDebug("Server says: the predictor finished running.");
appendDebug("Attemping to retrieve flight path from server");
// stop polling for JSON
clearInterval(ajaxEventHandle);
// parse the data
getCSV(running_uuid);
} else if ( progress['pred_running'] != true ) {
$("#prediction_status").html("Waiting for predictor to run...");
appendDebug("Server says: predictor not yet running...");
} else if ( progress['pred_running'] == true ) {
$("#prediction_status").html("Predictor running...");
appendDebug("Server says: predictor currently running");
}
} else {
$("#prediction_status").html("Downloading wind data");
$("#prediction_progress").progressbar("option", "value",
progress['gfs_percent']);
$("#prediction_percent").html(progress['gfs_percent'] +
"% - Estimated time remaining: " + progress['gfs_timeremaining']);
appendDebug("Server says: downloaded " +
progress['gfs_percent'] + "% of GFS files");
}
}
return true;
}
var map;
var map_items = [];
var launch_img = "images/marker-sm-red.png";
@ -165,104 +71,6 @@ function initialize() {
}
function parseCSV(lines) {
if(lines.length <= 0) {
appendDebug("The server returned an empty CSV file");
return false;
}
var path = [];
var max_height = -10; //just any -ve number
var max_point = null;
var launch_pt;
var land_pt;
$.each(lines, function(idx, line) {
entry = line.split(',');
if(entry.length >= 4) { // check valid entry length
var point = new google.maps.LatLng( parseFloat(entry[1]), parseFloat(entry[2]) );
if ( idx == 0 ) { // get the launch lat/long for marker
var launch_lat = entry[1];
var launch_lon = entry[2];
launch_pt = point;
}
// set on every iteration, last valid entry
// gives landing position
var land_lat = entry[1];
var land_lon = entry[2];
land_pt = point;
if(parseFloat(entry[3]) > max_height) {
max_height = parseFloat(entry[3]);
max_point = point;
}
path.push(point);
}
});
appendDebug("Flight data parsed, creating map plot...");
clearMapItems();
// make some nice icons
var launch_icon = new google.maps.MarkerImage(launch_img,
new google.maps.Size(16,16),
new google.maps.Point(0, 0),
new google.maps.Point(8, 8)
);
var land_icon = new google.maps.MarkerImage(land_img,
new google.maps.Size(16,16),
new google.maps.Point(0, 0),
new google.maps.Point(8, 8)
);
var launch_marker = new google.maps.Marker({
position: launch_pt,
map: map,
icon: launch_icon,
title: 'Balloon launch'
});
var land_marker = new google.maps.Marker({
position: land_pt,
map:map,
icon: land_icon,
title: 'Predicted Landing'
});
var path_polyline = new google.maps.Polyline({
path:path,
map: map,
strokeColor: '#000000',
strokeWeight: 3,
strokeOpacity: 0.75
});
var pop_marker = new google.maps.Marker({
position: max_point,
map: map,
icon: burst_img,
title: 'Balloon burst (max. altitude: ' + max_height + 'm)',
});
// now add the launch/land markers to map
map_items.push(launch_marker);
map_items.push(land_marker);
map_items.push(pop_marker);
map_items.push(path_polyline);
return true;
}
function clearMapItems() {
appendDebug("Clearing previous map trace");
if(map_items) {
for(i in map_items) {
map_items[i].setMap(null);
}
}
map_items = [];
}
</script>
</head>

Wyświetl plik

@ -1,7 +1,202 @@
/*
* CUSF Landing Prediction Version 2
* Jon Sowman 2010
* jon@hexoc.com
* http://www.hexoc.com
*
* http://github.com/jonsowman/cusf-standalone-predictor
*
*/
$(document).ready(function() {
// do nothing
});
function predSub() {
appendDebug(null, 1); // clear debug window
appendDebug("Sending data to server...");
// initialise progress bar
$("#prediction_progress").progressbar({ value: 0 });
$("#prediction_status").html("Sending data to server...");
$("#status_message").fadeIn(250);
}
function handlePred(pred_uuid) {
$("#prediction_status").html("Searching for wind data...");
$("#input_form").hide("slide", { direction: "down" }, 500);
$("#map_canvas").fadeTo(1000, 0.2);
// ajax to poll for progress
ajaxEventHandle = setInterval("getJSONProgress('"+pred_uuid+"')", 2000);
//getCSV(pred_uuid);
}
function getCSV(pred_uuid) {
$.get("ajax.php", { "action":"getCSV", "uuid":pred_uuid }, function(data) {
appendDebug("Got JSON response from server for flight path, parsing...");
if (parseCSV(data) ) {
appendDebug("Parsing function returned successfully.");
appendDebug("Done, AJAX functions quitting.");
} else {
appendDebug("The parsing function failed.");
}
}, 'json');
}
function getJSONProgress(pred_uuid) {
$.ajax({
url:"preds/"+pred_uuid+"/progress.json",
dataType:'json',
timeout: 500,
// complete: function(data, httpstatus) {
// appendDebug(httpstatus);
// },
success: processProgress
});
}
function processProgress(progress) {
if ( progress['error'] ) {
clearInterval(ajaxEventHandle);
appendDebug("There was an error in running the prediction: "+progress['error']);
} else {
// get the progress of the wind data
if ( progress['gfs_complete'] == true ) {
if ( progress['pred_complete'] == true ) { // pred has finished
$("#prediction_status").html("Prediction finished.");
$("#status_message").fadeOut(500);
// now clear the status window
$("#prediction_status").html("");
$("#prediction_progress").progressbar("options", "value", 0);
$("#prediction_percent").html("");
// bring the input form back up
$("#input_form").show("slide", { direction: "down" }, 500);
// un-fade the map canvas
$("#map_canvas").fadeTo(1500, 1);
appendDebug("Server says: the predictor finished running.");
appendDebug("Attemping to retrieve flight path from server");
// stop polling for JSON
clearInterval(ajaxEventHandle);
// parse the data
getCSV(running_uuid);
} else if ( progress['pred_running'] != true ) {
$("#prediction_status").html("Waiting for predictor to run...");
appendDebug("Server says: predictor not yet running...");
} else if ( progress['pred_running'] == true ) {
$("#prediction_status").html("Predictor running...");
appendDebug("Server says: predictor currently running");
}
} else {
$("#prediction_status").html("Downloading wind data");
$("#prediction_progress").progressbar("option", "value",
progress['gfs_percent']);
$("#prediction_percent").html(progress['gfs_percent'] +
"% - Estimated time remaining: " + progress['gfs_timeremaining']);
appendDebug("Server says: downloaded " +
progress['gfs_percent'] + "% of GFS files");
}
}
return true;
}
function parseCSV(lines) {
if(lines.length <= 0) {
appendDebug("The server returned an empty CSV file");
return false;
}
var path = [];
var max_height = -10; //just any -ve number
var max_point = null;
var launch_pt;
var land_pt;
$.each(lines, function(idx, line) {
entry = line.split(',');
if(entry.length >= 4) { // check valid entry length
var point = new google.maps.LatLng( parseFloat(entry[1]), parseFloat(entry[2]) );
if ( idx == 0 ) { // get the launch lat/long for marker
var launch_lat = entry[1];
var launch_lon = entry[2];
launch_pt = point;
}
// set on every iteration, last valid entry
// gives landing position
var land_lat = entry[1];
var land_lon = entry[2];
land_pt = point;
if(parseFloat(entry[3]) > max_height) {
max_height = parseFloat(entry[3]);
max_point = point;
}
path.push(point);
}
});
appendDebug("Flight data parsed, creating map plot...");
clearMapItems();
// make some nice icons
var launch_icon = new google.maps.MarkerImage(launch_img,
new google.maps.Size(16,16),
new google.maps.Point(0, 0),
new google.maps.Point(8, 8)
);
var land_icon = new google.maps.MarkerImage(land_img,
new google.maps.Size(16,16),
new google.maps.Point(0, 0),
new google.maps.Point(8, 8)
);
var launch_marker = new google.maps.Marker({
position: launch_pt,
map: map,
icon: launch_icon,
title: 'Balloon launch'
});
var land_marker = new google.maps.Marker({
position: land_pt,
map:map,
icon: land_icon,
title: 'Predicted Landing'
});
var path_polyline = new google.maps.Polyline({
path:path,
map: map,
strokeColor: '#000000',
strokeWeight: 3,
strokeOpacity: 0.75
});
var pop_marker = new google.maps.Marker({
position: max_point,
map: map,
icon: burst_img,
title: 'Balloon burst (max. altitude: ' + max_height + 'm)',
});
// now add the launch/land markers to map
map_items.push(launch_marker);
map_items.push(land_marker);
map_items.push(pop_marker);
map_items.push(path_polyline);
return true;
}
function clearMapItems() {
appendDebug("Clearing previous map trace");
if(map_items) {
for(i in map_items) {
map_items[i].setMap(null);
}
}
map_items = [];
}
function appendDebug(appendage, clear) {
if ( clear == null ){
var curr = $("#debuginfo").html();
@ -57,5 +252,3 @@ function SetSiteOther() {
optOther.selected = true;
}
// vim:et:ts=8:sw=8:autoindent