Skip to content

Commit a495f24

Browse files
Mark JessopMark Jessop
authored andcommitted
Persistant store for data fields, only updated if newer than current.
Old data (>20s) has the age added to the field name.
1 parent d43bbba commit a495f24

File tree

1 file changed

+51
-6
lines changed

1 file changed

+51
-6
lines changed

js/tracker.js

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,7 @@ function guess_name(key) {
12541254
return title_case(key.replace(/_/g, " "));
12551255
}
12561256

1257-
function habitat_data(jsondata, alternative) {
1257+
function habitat_data(jsondata, data_ages, current_timestamp, alternative) {
12581258
var keys = globalKeys;
12591259

12601260
var tooltips = {
@@ -1300,7 +1300,12 @@ function habitat_data(jsondata, alternative) {
13001300

13011301
for(var key in data) {
13021302
if ((key === "frequency" && txFreq) || (key === "xdata" && xdataFound)) {} else {
1303-
array.push([key, data[key]]);
1303+
if(data_ages.hasOwnProperty(key)){
1304+
key_age = data_ages[key];
1305+
} else {
1306+
key_age = current_timestamp;
1307+
}
1308+
array.push([key, data[key], key_age]);
13041309
}
13051310
}
13061311

@@ -1311,6 +1316,7 @@ function habitat_data(jsondata, alternative) {
13111316
for(var i = 0, ii = array.length; i < ii; i++) {
13121317
var k = array[i][0]; // key
13131318
var v = array[i][1]; // value
1319+
var ka = array[i][2]; // age
13141320
if (hide_keys[k] === true)
13151321
continue;
13161322

@@ -1350,8 +1356,18 @@ function habitat_data(jsondata, alternative) {
13501356
}
13511357
}
13521358

1359+
// Check if data is considered to be 'old'
1360+
// Need to think about how to style old data.
1361+
// Maybe make the text grey?
1362+
// At what point should we consider the data to be old?
1363+
if (ka < (current_timestamp - 20000)){
1364+
ka_age = (current_timestamp - ka)/1000;
1365+
name += " (" + ka_age.toFixed(0) + "s old)" ;
1366+
}
1367+
13531368
if(typeof alternative == 'boolean' && alternative) {
1354-
output += "<div><b>" + name + ":&nbsp;</b>" + v + suffix + "</div>";
1369+
// This never gets called? We never seem to pass the alternative argument...
1370+
output += "<div><b>" + name + ":&nbsp;</b>" + v + suffix + "</div>";
13551371
} else {
13561372
if (tooltip != "") {
13571373
output += "<dt>" + v + suffix + "</dt><dd>" + name + ' <div class="tooltip">🛈<span class="tooltiptext">' + tooltip + '</span></div></dd>';
@@ -1596,7 +1612,27 @@ function formatDate(date,utc) {
15961612
}
15971613

15981614
function updateVehicleInfo(vcallsign, newPosition) {
1615+
1616+
// Note - at this point, vehicles[vcallsign].curr_position has already been set to the values in newPosition
1617+
// so the newPosition argument is kind of redundant, we could just extract curr_position and use that.
15991618
var vehicle = vehicles[vcallsign];
1619+
1620+
1621+
// Update data fields only if they are newer than whats already in the store.
1622+
for (var data_field_name in newPosition.data){
1623+
1624+
if(!vehicle.data_fields_age.hasOwnProperty(data_field_name)){
1625+
// Haven't seen this field name before, add it to the age object.
1626+
vehicle.data_fields_age[data_field_name] = 0;
1627+
}
1628+
1629+
if(newPosition.gps_timestamp > vehicle.data_fields_age[data_field_name]){
1630+
vehicle.data_fields[data_field_name] = newPosition.data[data_field_name];
1631+
vehicle.data_fields_age[data_field_name] = newPosition.gps_timestamp;
1632+
}
1633+
1634+
}
1635+
16001636
if (!isNaN(newPosition.gps_lat) && !isNaN(newPosition.gps_lon)){
16011637
var latlng = new L.LatLng(newPosition.gps_lat, newPosition.gps_lon);
16021638
}
@@ -1650,13 +1686,16 @@ function updateVehicleInfo(vcallsign, newPosition) {
16501686
}
16511687

16521688
// indicates whenever a payload has landed
1689+
// Ideally we'd be using some kind of ground level check for this.
1690+
// We might be able to pull out an estimate of landing ground level from the last position in the latest prediction?
16531691
var landed = (
16541692
vehicle.max_alt > 1500 && // if it has gone up
16551693
vehicle.ascent_rate < 1.0 && // and has negative ascent_rate, aka is descending
16561694
newPosition.gps_alt < 350 // and is under 350 meters altitude
16571695
) || ( // or
16581696
newPosition.gps_alt < 600 && // under 600m and has no position update for more than 30 minutes
1659-
(new Date().getTime() - convert_time(newPosition.gps_time)) > 1800000
1697+
//(new Date().getTime() - convert_time(newPosition.gps_time)) > 1800000
1698+
(new Date().getTime() - newPosition.gps_timestamp) > 1800000
16601699
);
16611700

16621701
if(landed) {
@@ -1743,7 +1782,7 @@ function updateVehicleInfo(vcallsign, newPosition) {
17431782
elm.attr('data-vcallsign', vcallsign);
17441783
}
17451784

1746-
// decides how to dispaly the horizonal speed
1785+
// decides how to display the horizonal speed
17471786
var imp = offline.get('opt_imperial'), hrate_text;
17481787
var ascent_text = imp ? (vehicle.ascent_rate * 196.850394).toFixed(1) + ' ft/min' : vehicle.ascent_rate.toFixed(1) + ' m/s';
17491788
if (offline.get('opt_haxis_hours')) {
@@ -1951,7 +1990,9 @@ function updateVehicleInfo(vcallsign, newPosition) {
19511990
'<dt>'+text_alt+' ('+text_alt_max+')</dt><dd>altitude (max)</dd>' +
19521991
'<dt>'+formatDate(stringToDateUTC(newPosition.gps_time))+'</dt><dd>datetime (local)</dd>' +
19531992
'<dt>'+coords_text+'</dt><dd>coordinates</dd>' +
1954-
habitat_data(newPosition.data) +
1993+
// Enabling use of the larger data store
1994+
habitat_data(vehicle.data_fields, vehicle.data_fields_age, newPosition.gps_timestamp) +
1995+
//habitat_data(newPosition.data, vehicle.data_fields_age, newPosition.gps_timestamp) +
19551996
c + // receivers if any
19561997
'';
19571998

@@ -3245,6 +3286,7 @@ function addPosition(position) {
32453286
title = null;
32463287
}
32473288

3289+
32483290
var vehicle_info = {
32493291
callsign: vcallsign,
32503292
uuid: elm_uuid++,
@@ -3267,6 +3309,8 @@ function addPosition(position) {
32673309
positions_alts: [],
32683310
path_length: 0,
32693311
curr_position: position,
3312+
data_fields: {},
3313+
data_fields_age: {},
32703314
line: [],
32713315
polyline_visible: polyline_visible,
32723316
polyline: polyline !== null ? polyline : [
@@ -3379,6 +3423,7 @@ function addPosition(position) {
33793423

33803424
var new_latlng = new L.LatLng(position.gps_lat, position.gps_lon);
33813425
var new_ts = convert_time(position.gps_time);
3426+
position.gps_timestamp = new_ts;
33823427
var curr_ts = convert_time(vehicle.curr_position.gps_time);
33833428
var new_alt = position.gps_alt;
33843429
var dt = (new_ts - curr_ts) / 1000; // convert to seconds

0 commit comments

Comments
 (0)