153 lines
5.4 KiB
JavaScript
153 lines
5.4 KiB
JavaScript
var trackingdata = null;
|
|
let indexes
|
|
|
|
function composeTimestamp(servertime){
|
|
var composed;
|
|
composed = servertime.slice(11,25).split(':').join("").split('.').join("");
|
|
return composed;
|
|
}
|
|
|
|
function calculateDistSerialTCP(coordsSerial, coordsTCP) {
|
|
let long = Math.abs(coordsSerial[0] - coordsTCP[0])
|
|
let lat = Math.abs(coordsSerial[1] - coordsTCP[1])
|
|
let squareDist = Math.pow(long, 2) + Math.pow(lat, 2)
|
|
return (Math.sqrt(squareDist))
|
|
}
|
|
|
|
function findBestTimeMatch(num, arr) {
|
|
var mid;
|
|
var lo = 0;
|
|
var hi = arr.length - 1;
|
|
while (hi - lo > 1) {
|
|
mid = Math.floor ((lo + hi) / 2);
|
|
if (arr[mid] < num) {
|
|
lo = mid;
|
|
} else {
|
|
hi = mid;
|
|
}
|
|
}
|
|
if (num - arr[lo] <= arr[hi] - num) {
|
|
return [arr[lo], lo];
|
|
}
|
|
return [arr[hi], hi];
|
|
}
|
|
|
|
function findSerialDataIndex(tcpdataList, serialdataList) {
|
|
let allSerialTimes = []
|
|
|
|
serialdataList.forEach(sensordata => {
|
|
if (!(sensordata.Speed === 0) && !(sensordata.HAcc === 0)) {
|
|
allSpeedsSerial.push(sensordata.Speed)
|
|
allAccSerial.push(sensordata.HAcc)
|
|
if(!(sensordata.Position[1] === 0) && !(sensordata.Position[0] === 0)){
|
|
allSerialCoords.push([sensordata.Position[1], sensordata.Position[0]])
|
|
}
|
|
let serialTimestamp = composeTimestamp(sensordata.Timestamp)
|
|
allSerialTimes.push(serialTimestamp)
|
|
}
|
|
})
|
|
|
|
tcpdataList.forEach(sensordata => {
|
|
if (!(sensordata.Speed === 0) && !(sensordata.HAcc === 0)) {
|
|
let tcpTimestamp = composeTimestamp(sensordata.Timestamp)
|
|
let index = findBestTimeMatch(tcpTimestamp, allSerialTimes)[1]
|
|
|
|
indexes.push(index)
|
|
}
|
|
})
|
|
console.log("indexes: " + indexes)
|
|
}
|
|
|
|
window.addEventListener("load", function(evt) {
|
|
//------------------------Buttons------------------------------
|
|
|
|
var trackings = null;
|
|
document.getElementById("messungladen").onclick = function(evt) {
|
|
fetch('http://localhost:3011/trackings/', { method: 'GET'}).then(results => {
|
|
return results.json()
|
|
}).then(r => {
|
|
console.log(r)
|
|
if (!'data' in r) {
|
|
return
|
|
}
|
|
trackings = r.data
|
|
let sel = document.getElementById("meas")
|
|
sel.innerHTML = ''
|
|
r.data.forEach(tracking => {
|
|
console.log(tracking)
|
|
var option = document.createElement("option");
|
|
option.text = tracking.TimeCreated + " Size: " + tracking.Size
|
|
sel.add(option)
|
|
})
|
|
sel.disabled = false
|
|
document.getElementById("replaystarten").disabled = false
|
|
|
|
})
|
|
};
|
|
|
|
document.getElementById("replaystarten").onclick = function(evt) {
|
|
indexes = []
|
|
allSpeedsSerial = []
|
|
allAccSerial = []
|
|
allSerialCoords = []
|
|
|
|
let sel = document.getElementById("meas")
|
|
console.log(trackings[sel.selectedIndex].UUID)
|
|
fetch(`http://localhost:3011/trackings/${trackings[sel.selectedIndex].UUID}`, { method: 'GET'}).then(results => {
|
|
return results.json()
|
|
}).then(r => {
|
|
console.log(r.data.Data)
|
|
console.log(r.data)
|
|
// if('SOURCE_TCP' in r.data.Data && r.data.Data.SOURCE_TCP.length > 0 && 'SOURCE_SERIAL' in r.data.Data && r.data.Data.SOURCE_SERIAL.length > 0){
|
|
// findSerialDataIndex(r.data.Data.SOURCE_TCP, r.data.Data.SOURCE_SERIAL)
|
|
// addDistances(r.data.Data.SOURCE_TCP, r.data.Data.SOURCE_SERIAL)
|
|
// }
|
|
if ('SOURCE_TCP' in r.data.Data && r.data.Data.SOURCE_TCP.length > 0) {
|
|
updateMapTCPbulk(r.data.Data.SOURCE_TCP)
|
|
addTCPSpeedData(r.data.Data.SOURCE_TCP)
|
|
}
|
|
if ('SOURCE_SERIAL' in r.data.Data && r.data.Data.SOURCE_SERIAL.length > 0) {
|
|
updateMapSERIALbulk(r.data.Data.SOURCE_SERIAL)
|
|
addSerialSpeedData()
|
|
}
|
|
addDistancesNew(prepareForDistanceCalc(r.data.Data))
|
|
|
|
})
|
|
|
|
}
|
|
});
|
|
|
|
function prepareForDistanceCalc(data) {
|
|
if('SOURCE_TCP' in data && data.SOURCE_TCP.length > 0 && 'SOURCE_SERIAL' in data && data.SOURCE_SERIAL.length > 0) {
|
|
let sensorPoints = [];
|
|
data.SOURCE_TCP.forEach(element => {
|
|
// let ts = Date.parse(element.Timestamp)
|
|
if (element.Position[0] !== 0 && element.Position[1] !== 0) {
|
|
sensorPoints.push({
|
|
differenceMs: Number.MAX_VALUE,
|
|
tcp: element,
|
|
ser: null,
|
|
speed: null
|
|
})
|
|
}
|
|
})
|
|
sensorPoints.forEach((el, index, arr) => {
|
|
let tcpTS = Date.parse(el.tcp.Timestamp)
|
|
data.SOURCE_SERIAL.forEach(serElement => {
|
|
let serTS = Date.parse(serElement.Timestamp)
|
|
if (Math.abs(tcpTS - serTS) < el.differenceMs && serElement.Position[0] !== 0 && serElement.Position[1] !== 0) {
|
|
el.differenceMs = tcpTS - serTS
|
|
arr[index].ser = serElement
|
|
}
|
|
})
|
|
})
|
|
// filter differences with more than 50 ms
|
|
let newSensorPoints = sensorPoints.filter(el => {
|
|
return Math.abs(el.differenceMs) < 50
|
|
})
|
|
console.log("SENSORPOINTs", newSensorPoints)
|
|
return newSensorPoints
|
|
}
|
|
return null
|
|
}
|