Skip to content

Commit 73b710b

Browse files
correctly splice position data for telemtry graph
* this completes the splicing implementation * the order of packets of processing position packets is irrelevant TODO: * revise altitude profile code to accomodate this changes
1 parent 53d7354 commit 73b710b

File tree

1 file changed

+60
-12
lines changed

1 file changed

+60
-12
lines changed

js/tracker.js

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,39 +1308,75 @@ function graphAddPosition(idx, new_data) {
13081308

13091309
var data = vehicles[idx].graph_data;
13101310
var ts = convert_time(new_data.gps_time);
1311-
var splice_idx = 0;
13121311
var splice = false;
1312+
var splice_idx = 0;
1313+
var splice_remove = 0;
1314+
var splice_pad = false;
1315+
var gap_size = 180000; // 3 mins in milis
1316+
var pad_size = 120000; // 2 min
13131317

13141318
if(data.length) {
13151319
var ts_last_idx = data[0].data.length - 1;
13161320
var ts_last = data[0].data[ts_last_idx][0];
13171321

13181322
if(data[0].data.length) {
1319-
if(data[0].data[ts_last_idx][0] >= ts) splice = true;
1323+
if(data[0].data[ts_last_idx][0] > ts) splice = true;
13201324
}
13211325

13221326
if(splice) {
1323-
// adjust splice_idx to account for null entries
1327+
// Good luck figuring out the following code. -Rossen
1328+
1329+
// find an insertion point for the new datum
13241330
var xref = data[0].data;
1325-
var i = xref.length - 1;
1331+
var i = max = xref.length - 1;
13261332
for(; i >= 0; i--) {
13271333
if(ts > xref[i][0]) break;
13281334
}
13291335
splice_idx = i+1;
13301336

1331-
//TODO: correct/adjust null entries
1337+
1338+
if(i > -1) {
1339+
// this is if new datum hits padded area
1340+
if((xref[i][1] == null && xref[i][0] - 1 + (gap_size - pad_size) >= ts)) {
1341+
splice_remove = 2;
1342+
splice_idx = i-1;
1343+
}
1344+
else if(i+1 <= max && xref[i+1][1] == null) {
1345+
splice_remove = 2;
1346+
splice_idx = i;
1347+
}
1348+
else if(i+2 <= max && xref[i+2][1] == null) {
1349+
splice_remove = 2;
1350+
splice_idx = i+1;
1351+
1352+
}
1353+
// should we pad before the new datum
1354+
else if (xref[i][1] != null && xref[i][0] + gap_size < ts) {
1355+
// pad with previous datum
1356+
$.each(data, function(k,v) {
1357+
v.data.splice(i+1, 0, [xref[i][0]+pad_size, v.data[i][1]], [xref[i][0]+pad_size+1, null]);
1358+
v.nulls += 2;
1359+
});
1360+
1361+
splice_idx += 2;
1362+
}
1363+
1364+
}
1365+
1366+
// should we pad after
1367+
if(ts + gap_size < xref[splice_idx+splice_remove][0]) {
1368+
splice_pad = true;
1369+
}
1370+
13321371
}
13331372
else {
13341373
//insert gap when there are 3mins, or more, without telemetry
1335-
var gap_size = 180000; // 3 mins in milis
1336-
var pad_size = 120000; // 2 min
1337-
13381374
if(ts_last + gap_size < ts) {
13391375
$.each(data, function(k,v) {
1340-
v.data.push([ts_last+pad_size, v.data[v.data.length - 1][1]]);
1376+
v.data.push([ts_last+pad_size, v.data[ts_last_idx][1]]);
13411377
v.data.push([ts_last+pad_size+1, null]);
13421378
v.nulls += 2;
1343-
})
1379+
});
13441380
}
13451381
}
13461382
// update the selection upper limit to the latest timestamp, only if the upper limit is equal to the last timestamp
@@ -1363,7 +1399,13 @@ function graphAddPosition(idx, new_data) {
13631399

13641400
// push latest altitude
13651401
if(splice) {
1366-
data[0].data.splice(splice_idx, 0, [ts, parseInt(new_data.gps_alt)]);
1402+
if(splice_pad) {
1403+
data[0].data.splice(splice_idx, splice_remove, [ts, parseInt(new_data.gps_alt)], [ts+pad_size, parseInt(new_data.gps_alt)], [ts+pad_size+1, null]);
1404+
data[0].nulls += 2;
1405+
} else {
1406+
data[0].data.splice(splice_idx, splice_remove, [ts, parseInt(new_data.gps_alt)]);
1407+
}
1408+
data[0].nulls -= splice_remove;
13671409
} else {
13681410
data[0].data.push([ts, parseInt(new_data.gps_alt)]);
13691411
}
@@ -1407,7 +1449,13 @@ function graphAddPosition(idx, new_data) {
14071449

14081450
for(var k in data_matrix) {
14091451
if(splice) {
1410-
data[k].data.splice(splice_idx, 0, data_matrix[k]);
1452+
if(splice_pad) {
1453+
data[k].data.splice(splice_idx, splice_remove, data_matrix[k], [ts+pad_size, data_matrix[k][1]], [ts+pad_size+1, null]);
1454+
data[k].nulls += 2;
1455+
} else {
1456+
data[k].data.splice(splice_idx, splice_remove, data_matrix[k]);
1457+
}
1458+
data[k].nulls -= splice_remove;
14111459
} else {
14121460
data[k].data.push(data_matrix[k]);
14131461
}

0 commit comments

Comments
 (0)