Skip to content

Commit a09b9e3

Browse files
committed
better filtering
1 parent 7f19043 commit a09b9e3

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

js/tracker.js

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,16 +2583,42 @@ function addPosition(position) {
25832583

25842584
if(dt >= 0) {
25852585
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
25902590
}
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+
}
25912603

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+
}
25962622
}
25972623
}
25982624

0 commit comments

Comments
 (0)