Skip to content

Commit f66deeb

Browse files
added functionality to view past flights
1 parent c0e898a commit f66deeb

File tree

2 files changed

+122
-8
lines changed

2 files changed

+122
-8
lines changed

js/app.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ var embed = {
2121
graph: true,
2222
graph_exapnded: false,
2323
latestonly: is_mobile,
24-
focus: ""
24+
focus: "",
25+
docid: ""
2526
}
2627
var params = window.location.search.substring(1).split('&');
2728

@@ -38,6 +39,7 @@ for(var idx in params) {
3839
case "nyan": nyan_mode = true; break;
3940
case "latestonly": embed.latestonly = (parseInt(line[1]) == 1) ? true : false; break;
4041
case "focus": embed.focus = line[1]; break;
42+
case "docid": embed.docid = line[1]; break;
4143
}
4244
}
4345

js/tracker.js

Lines changed: 119 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ var position_id = 0;
33
var data_url = "http://spacenear.us/tracker/datanew.php";
44
var receivers_url = "http://spacenear.us/tracker/receivers.php";
55
var predictions_url = "http://spacenear.us/tracker/get_predictions.php";
6+
7+
var habitat_max = 200;
8+
var habitat_url = "http://habitat.habhub.org/habitat/";
9+
var habitat_url_payload_telemetry = habitat_url + "_design/payload_telemetry/_view/payload_time?startkey=[%22{ID}%22,{START}]&endkey=[%22{ID}%22,{END}]&include_docs=true&limit=" + habitat_max + "&skip=";
10+
611
var host_url = "";
712
var markers_url = "img/markers/";
813
var vehicle_names = [];
@@ -1685,6 +1690,108 @@ function refreshPredictions() {
16851690
});
16861691
}
16871692

1693+
function habitat_translation_layer(json_result, url, skip) {
1694+
if(json_result.rows == 0) return;
1695+
1696+
json_result = json_result.rows;
1697+
1698+
var result = {positions: { position: [] }};
1699+
var blacklist = {
1700+
altitude: 1,
1701+
date: 1,
1702+
latitude: 1,
1703+
longitude: 1,
1704+
payload: 1,
1705+
sentence_id: 1,
1706+
time: 1,
1707+
}
1708+
1709+
for(var i in json_result) {
1710+
var doc = json_result[i].doc;
1711+
if(doc.data.latitude == 0 && doc.data.longitude == 0) continue;
1712+
1713+
var row = {
1714+
'position_id': 0,
1715+
'vehicle': doc.data.payload,
1716+
'server_time': doc.data._parsed.time_parsed,
1717+
'sequence': doc.data.sentence_id,
1718+
'gps_lat': doc.data.latitude,
1719+
'gps_lon': doc.data.longitude,
1720+
'gps_alt': doc.data.altitude,
1721+
'callsign': "HABITAT ARCHIVE",
1722+
'data': {}
1723+
}
1724+
1725+
try {
1726+
row['gps_time'] = "20" + doc.data.date.replace(/([0-9]{2})/g, "$1-") + doc.data.time;
1727+
} catch (e) {
1728+
row['gps_time'] = row['server_time'];
1729+
}
1730+
1731+
// move all other properties as data
1732+
for(var x in doc.data) {
1733+
// skip internal and reserved vars
1734+
if(x[0] == '_' || blacklist.hasOwnProperty(x)) continue;
1735+
1736+
row.data[x] = doc.data[x];
1737+
}
1738+
row.data = JSON.stringify(row.data);
1739+
1740+
// append the packet
1741+
result.positions.position.push(row);
1742+
}
1743+
1744+
if(result.positions.position.length) update(result);
1745+
1746+
skip += habitat_max;
1747+
var req_url = url + skip;
1748+
1749+
setTimeout(function() {
1750+
$.getJSON(req_url, function(response) {
1751+
habitat_translation_layer(response, url, skip);
1752+
});
1753+
}, 1000);
1754+
}
1755+
1756+
function initHabitat() {
1757+
$.ajax({
1758+
type: "GET",
1759+
url: habitat_url + embed.docid,
1760+
data: "",
1761+
dataType: "json",
1762+
success: function(response, textStatus) {
1763+
if(response.type == "flight") {
1764+
if(response.payloads.length == 0) {
1765+
alert("no payloads for that flight doc")
1766+
return;
1767+
}
1768+
1769+
ts_start = convert_time(response.start) / 1000;
1770+
ts_end = convert_time(response.end) / 1000;
1771+
1772+
response.payloads.forEach( function(payload_id) {
1773+
1774+
var url = habitat_url_payload_telemetry.replace(/\{ID\}/g, payload_id);
1775+
url = url.replace("{START}", ts_start).replace("{END}", ts_end);
1776+
1777+
$.getJSON(url+0, function(response) {
1778+
habitat_translation_layer(response, url, 0);
1779+
});
1780+
});
1781+
}
1782+
else {
1783+
alert("docid is not a flight doc");
1784+
}
1785+
},
1786+
error: function() {
1787+
alert("Unable to load flight doc");
1788+
},
1789+
complete: function(request, textStatus) {
1790+
}
1791+
});
1792+
}
1793+
1794+
16881795
var periodical, periodical_receivers, periodical_predictions;
16891796
var timer_seconds = 15;
16901797

@@ -1696,14 +1803,19 @@ function startAjax() {
16961803

16971804
// the periodical starts here, the * 1000 is because milliseconds required
16981805

1699-
//periodical = setInterval(refresh, timer_seconds * 1000);
1700-
refresh();
1806+
if(embed.docid != "") {
1807+
initHabitat();
1808+
}
1809+
else {
1810+
//periodical = setInterval(refresh, timer_seconds * 1000);
1811+
refresh();
17011812

1702-
//periodical_listeners = setInterval(refreshReceivers, 60 * 1000);
1703-
refreshReceivers();
1813+
//periodical_listeners = setInterval(refreshReceivers, 60 * 1000);
1814+
refreshReceivers();
17041815

1705-
//periodical_predictions = setInterval(refreshPredictions, 2 * timer_seconds * 1000);
1706-
refreshPredictions();
1816+
//periodical_predictions = setInterval(refreshPredictions, 2 * timer_seconds * 1000);
1817+
refreshPredictions();
1818+
}
17071819
}
17081820

17091821
function stopAjax() {
@@ -1926,7 +2038,7 @@ function update(response) {
19262038
if(follow_vehicle != -1 && vehicles[follow_vehicle].graph_data_updated) updateGraph(follow_vehicle, false);
19272039

19282040
// store in localStorage
1929-
offline.set('positions', ctx.lastPositions);
2041+
if(embed.docid == "") offline.set('positions', ctx.lastPositions);
19302042

19312043
if (got_positions && !zoomed_in && vehicles.length) {
19322044
zoom_on_payload();

0 commit comments

Comments
 (0)