@@ -5,6 +5,7 @@ var receivers_url = "https://api.v2.sondehub.org/listeners/telemetry";
55var predictions_url = "https://api.v2.sondehub.org/predictions?vehicles=" ;
66var launch_predictions_url = "https://api.v2.sondehub.org/predictions/reverse" ;
77var recovered_sondes_url = "https://api.v2.sondehub.org/recovered" ;
8+ var recovered_sondes_stats_url = "https://api.v2.sondehub.org/recovered/stats" ;
89var launches_url = "https://api.v2.sondehub.org/sites" ;
910
1011var livedata = "wss://ws-reader.v2.sondehub.org/" ;
@@ -4307,20 +4308,30 @@ function refreshRecoveries() {
43074308 $ . ajax ( {
43084309 type : "GET" ,
43094310 url : recovered_sondes_url ,
4310- //data: "last=0",
43114311 dataType : "json" ,
43124312 success : function ( response , textStatus ) {
4313- if ( offline . get ( 'opt_hide_recoveries' ) ) {
4314- updateRecoveryPane ( response ) ;
4315- updateLeaderboardPane ( response ) ;
4316- } else {
4317- updateRecoveryPane ( response ) ;
4318- updateLeaderboardPane ( response ) ;
4313+ updateRecoveryPane ( response ) ;
4314+ if ( ! offline . get ( 'opt_hide_recoveries' ) ) {
43194315 updateRecoveries ( response ) ;
43204316 }
43214317 } ,
43224318 error : function ( ) {
43234319 updateRecoveryPane ( [ ] ) ;
4320+ }
4321+ } ) ;
4322+
4323+ }
4324+
4325+ function refreshRecoveryStats ( ) {
4326+
4327+ $ . ajax ( {
4328+ type : "GET" ,
4329+ url : recovered_sondes_stats_url ,
4330+ dataType : "json" ,
4331+ success : function ( response , textStatus ) {
4332+ updateLeaderboardPane ( response ) ;
4333+ } ,
4334+ error : function ( ) {
43244335 updateLeaderboardPane ( [ ] ) ;
43254336 }
43264337 } ) ;
@@ -4352,7 +4363,7 @@ function refreshPredictions() {
43524363 }
43534364 } ) ;
43544365
4355- var data_str = "duration=" + wvar . mode ;
4366+ var data_str = "duration=" + wvar . mode + "&vehicles=" + encodeURIComponent ( wvar . query ) ;
43564367
43574368 ajax_predictions = $ . ajax ( {
43584369 type : "GET" ,
@@ -4443,6 +4454,7 @@ function startAjax() {
44434454
44444455 refreshPatreons ( ) ;
44454456 refreshRecoveries ( ) ;
4457+ refreshRecoveryStats ( ) ;
44464458}
44474459
44484460function stopAjax ( ) {
@@ -4834,42 +4846,26 @@ function updateLeaderboardPane(r){
48344846 if ( ! r ) return ;
48354847
48364848 html = "" ;
4837- var leaderboard = { } ;
4838- var recovered = 0 ;
4849+ var recovered = r . recovered ;
4850+ var total = r . total ;
4851+ var hunters = r . chaser_count ;
4852+ var top = r . top_chasers ;
48394853
4840- var i = 0 , ii = r . length ;
4841- for ( ; i < ii ; i ++ ) {
4842- if ( r [ i ] . recovered ) {
4843- recovered += 1 ;
4844- if ( leaderboard . hasOwnProperty ( r [ i ] . recovered_by ) ) {
4845- leaderboard [ r [ i ] . recovered_by ] = leaderboard [ r [ i ] . recovered_by ] + 1 ;
4846- } else {
4847- leaderboard [ r [ i ] . recovered_by ] = 1
4848- }
4849- }
4850- }
48514854
4852- var sortable = [ ] ;
4853- for ( var score in leaderboard ) {
4854- sortable . push ( [ score , leaderboard [ score ] ] ) ;
4855- }
4856-
4857- sortable . sort ( function ( a , b ) {
4858- return b [ 1 ] - a [ 1 ] ;
4859- } ) ;
4860-
4861- var list = sortable . slice ( 0 , 5 ) ;
4862-
4863- html += "<div><b>Total sondes recovered: " + recovered + "/" + r . length + "</b></div>" ;
4864- html += "<div><b>Total hunters: " + sortable . length + "</b></div><br>" ;
4855+ html += "<div><b>Total sondes recovered: " + recovered + "/" + total + "</b></div>" ;
4856+ html += "<div><b>Total hunters: " + hunters + "</b></div><br>" ;
48654857 html += "<div><b>Leaderboard: </b></div>" ;
48664858
4867- for ( var i = 0 ; i < list . length ; i ++ ) {
4868- html += "<div><b>" + ( parseInt ( i ) + 1 ) + ". </b>" + list [ i ] [ 0 ] + " - " + list [ i ] [ 1 ] + "</div>" ;
4859+ var i = 1 ;
4860+ for ( let chaser in top ) {
4861+ if ( top . hasOwnProperty ( chaser ) ) {
4862+ html += "<div><b>" + parseInt ( i ) + ". </b>" + chaser + " - " + top [ chaser ] + "</div>" ;
4863+ i += 1 ;
4864+ }
48694865 }
48704866
48714867 if ( r . length == 0 ) {
4872- html = "<div>No recent recoveries :-(</div>"
4868+ html = "<div>Error :-(</div>"
48734869 }
48744870
48754871 $ ( "#leaderboard-list" ) . html ( html ) ;
0 commit comments