@@ -4,7 +4,7 @@ var 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" ;
66
7- var habitat_max = 200 ;
7+ var habitat_max = 400 ;
88var habitat_url = "http://habitat.habhub.org/habitat/" ;
99var 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=" ;
1010
@@ -2213,12 +2213,18 @@ function refreshPredictions() {
22132213 } ) ;
22142214}
22152215
2216- function habitat_translation_layer ( json_result , url , skip ) {
2217- if ( json_result . rows === 0 ) return ;
2216+ function habitat_translation_layer ( json_result ) {
2217+ if ( json_result . rows . length === 0 ) {
2218+ habitat_step ( true ) ;
2219+ return ;
2220+ }
22182221
22192222 json_result = json_result . rows ;
22202223
22212224 var result = { positions : { position : [ ] } } ;
2225+ result . fetch_timestamp = Date . now ( ) ;
2226+ $ ( "#stTimer" ) . attr ( "data-timestamp" , result . fetch_timestamp ) ;
2227+
22222228 var blacklist = {
22232229 altitude : 1 ,
22242230 date : 1 ,
@@ -2266,17 +2272,43 @@ function habitat_translation_layer(json_result, url, skip) {
22662272
22672273 if ( result . positions . position . length ) update ( result ) ;
22682274
2269- skip += habitat_max ;
2270- var req_url = url + skip ;
2271-
2275+ // next step
22722276 periodical = setTimeout ( function ( ) {
2273- ajax_positions = $ . getJSON ( req_url , function ( response ) {
2274- habitat_translation_layer ( response , url , skip ) ;
2275- } ) ;
2276- } , 1000 ) ;
2277+ habitat_step ( ) ;
2278+ } , 500 ) ;
2279+ }
2280+
2281+ var habitat_step_data ;
2282+
2283+ function habitat_step ( remove_current ) {
2284+ remove_current = ! ! remove_current ;
2285+
2286+ if ( remove_current ) {
2287+ habitat_step_data . payloads . splice ( habitat_step_data . idx , 1 ) ;
2288+ }
2289+
2290+ if ( habitat_step_data . payloads . length === 0 ) {
2291+ $ ( "#stText" ) . text ( "" ) ;
2292+ return ;
2293+ }
2294+
2295+ habitat_step_data . idx += 1 ;
2296+ habitat_step_data . idx = habitat_step_data . idx % habitat_step_data . payloads . length ;
2297+
2298+ var url = habitat_step_data . payloads [ habitat_step_data . idx ] . url ;
2299+ url += habitat_step_data . payloads [ habitat_step_data . idx ] . skip ;
2300+ habitat_step_data . payloads [ habitat_step_data . idx ] . skip += habitat_max ;
2301+
2302+ console . log ( url ) ;
2303+
2304+ ajax_positions = $ . getJSON ( url , function ( response ) {
2305+ habitat_translation_layer ( response ) ;
2306+ } ) ;
22772307}
22782308
22792309function initHabitat ( ) {
2310+ $ ( "#stText" ) . text ( "loading |" ) ;
2311+
22802312 ajax_positions = $ . ajax ( {
22812313 type : "GET" ,
22822314 url : habitat_url + wvar . query ,
@@ -2285,22 +2317,30 @@ function initHabitat() {
22852317 success : function ( response , textStatus ) {
22862318 if ( response . type == "flight" ) {
22872319 if ( response . payloads . length === 0 ) {
2288- alert ( "no payloads for that flight doc" ) ;
2320+ update ( null ) ;
2321+ $ ( "#stText" ) . text ( "no payloads in doc |" ) ;
22892322 return ;
22902323 }
22912324
22922325 ts_start = convert_time ( response . start ) / 1000 ;
22932326 ts_end = convert_time ( response . end ) / 1000 ;
22942327
2295- response . payloads . forEach ( function ( payload_id ) {
2328+ habitat_step_data = {
2329+ idx : 0 ,
2330+ payloads : [ ] ,
2331+ } ;
22962332
2333+ response . payloads . forEach ( function ( payload_id ) {
22972334 var url = habitat_url_payload_telemetry . replace ( / \{ I D \} / g, payload_id ) ;
22982335 url = url . replace ( "{START}" , ts_start ) . replace ( "{END}" , ts_end ) ;
22992336
2300- $ . getJSON ( url + 0 , function ( response ) {
2301- habitat_translation_layer ( response , url , 0 ) ;
2337+ habitat_step_data . payloads . push ( {
2338+ url : url ,
2339+ skip : 0 ,
23022340 } ) ;
23032341 } ) ;
2342+
2343+ habitat_step ( ) ;
23042344 }
23052345 else {
23062346 update ( null ) ;
@@ -2555,6 +2595,8 @@ function update(response) {
25552595 var vcallsign = ctx . list . shift ( ) ;
25562596 var vehicle = vehicles [ vcallsign ] ;
25572597
2598+ if ( vehicle === undefined ) return ;
2599+
25582600 if ( vehicle . updated ) {
25592601 updatePolyline ( vcallsign ) ;
25602602 updateVehicleInfo ( vcallsign , vehicle . curr_position ) ;
0 commit comments