@@ -2583,16 +2583,42 @@ function addPosition(position) {
2583
2583
2584
2584
if ( dt >= 0 ) {
2585
2585
if ( vehicle . num_positions > 0 && dt > 0 ) {
2586
- // calculate vertical rate
2587
- var rate = ( position . gps_alt - vehicle . curr_position . gps_alt ) / dt ;
2588
- if ( ! isNaN ( rate ) && isFinite ( rate ) ) {
2589
- vehicle . ascent_rate = 0.7 * rate + 0.3 * vehicle . ascent_rate ;
2586
+ var search_ts = new_ts - 10000
2587
+
2588
+ function searchPositions ( time ) {
2589
+ return time <= search_ts
2590
2590
}
2591
+
2592
+ var search_matches = vehicle . positions_ts . filter ( searchPositions )
2593
+
2594
+ if ( search_matches . length > 0 && search_matches [ search_matches . length - 1 ] >= search_ts - 5000 ) {
2595
+ var search_match = search_matches [ search_matches . length - 1 ]
2596
+ var dtt = ( curr_ts - search_match ) / 1000 ;
2597
+
2598
+ // calculate vertical rate
2599
+ var rate = ( position . gps_alt - vehicle . positions_alts [ search_matches . length ] ) / dtt ;
2600
+ if ( ! isNaN ( rate ) && isFinite ( rate ) ) {
2601
+ vehicle . ascent_rate = 0.5 * rate + 0.5 * vehicle . ascent_rate ;
2602
+ }
2591
2603
2592
- // calculate horizontal rate
2593
- horizontal_rate_temp = new_latlng . distanceTo ( new L . LatLng ( vehicle . curr_position . gps_lat , vehicle . curr_position . gps_lon ) ) / dt ;
2594
- if ( ! isNaN ( horizontal_rate_temp ) && isFinite ( horizontal_rate_temp ) ) {
2595
- vehicle . horizontal_rate = horizontal_rate_temp ;
2604
+ // calculate horizontal rate
2605
+ horizontal_rate_temp = new_latlng . distanceTo ( vehicle . positions [ search_matches . length ] ) / dtt ;
2606
+ if ( ! isNaN ( horizontal_rate_temp ) && isFinite ( horizontal_rate_temp ) ) {
2607
+ vehicle . horizontal_rate = horizontal_rate_temp ;
2608
+ }
2609
+
2610
+ } else {
2611
+ // calculate vertical rate
2612
+ var rate = ( position . gps_alt - vehicle . curr_position . gps_alt ) / dt ;
2613
+ if ( ! isNaN ( rate ) && isFinite ( rate ) ) {
2614
+ vehicle . ascent_rate = 0.7 * rate + 0.3 * vehicle . ascent_rate ;
2615
+ }
2616
+
2617
+ // calculate horizontal rate
2618
+ horizontal_rate_temp = new_latlng . distanceTo ( new L . LatLng ( vehicle . curr_position . gps_lat , vehicle . curr_position . gps_lon ) ) / dt ;
2619
+ if ( ! isNaN ( horizontal_rate_temp ) && isFinite ( horizontal_rate_temp ) ) {
2620
+ vehicle . horizontal_rate = horizontal_rate_temp ;
2621
+ }
2596
2622
}
2597
2623
}
2598
2624
0 commit comments