Calculate properly first / last timestamps of vessel tracks

This commit is contained in:
D. Berge
2025-08-11 01:56:46 +02:00
parent aabcc74891
commit 1c5fd2e34d
2 changed files with 18 additions and 5 deletions

View File

@@ -305,14 +305,21 @@ export default {
const paths = [];
let prevTstamp;
paths.push({path: [], timestamps: [], num: 0});
paths.push({path: [], timestamps: [], num: 0, ts0: +Infinity, ts1: -Infinity});
for (const el of data) {
const tstamp = new Date(el.tstamp).valueOf();
const curPath = () => paths[paths.length-1];
if (prevTstamp && Math.abs(tstamp - prevTstamp) > breakLimit) {
// Start a new path
console.log(`Breaking path on interval ${Math.abs(tstamp - prevTstamp)} > ${breakLimit}`);
paths.push({path: [], timestamps: [], num: paths.length});
paths.push({path: [], timestamps: [], num: paths.length, ts0: +Infinity, ts1: -Infinity});
}
if (tstamp < curPath().ts0) {
curPath().ts0 = tstamp;
}
if (tstamp > curPath().ts1) {
curPath().ts1 = tstamp;
}
curPath().path.push([el.x, el.y]);
@@ -320,6 +327,12 @@ export default {
prevTstamp = tstamp;
}
paths.forEach (path => {
path.nums = paths.length;
path.ts0 = new Date(path.ts0);
path.ts1 = new Date(path.ts1);
});
return paths;
},
getPath: d => d.path,

View File

@@ -244,10 +244,10 @@ export default {
console.log("track lines tooltip", p);
if (p) {
const ts1 = new Date(p.timestamps[0] * 1000);
const ts0 = new Date(p.timestamps[p.timestamps.length-1] * 1000);
let html = `${ts0.toISOString()}<br/>\n${ts1.toISOString()}<br/>\n`
let html = `Segment ${p.num+1} / ${p.nums}<br/>\n`
html += `${p.ts0.toISOString()}<br/>\n`
html += `${p.ts1.toISOString()}<br/>\n`;
return {html, style: this.tooltipDefaultStyle};
}