@@ -3,6 +3,11 @@ var position_id = 0;
33var data_url = "http://spacenear.us/tracker/datanew.php" ;
44var receivers_url = "http://spacenear.us/tracker/receivers.php" ;
55var 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+
611var host_url = "" ;
712var markers_url = "img/markers/" ;
813var 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 ( / \{ I D \} / 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+
16881795var periodical , periodical_receivers , periodical_predictions ;
16891796var 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
17091821function 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