140 lines
4.8 KiB
JavaScript
140 lines
4.8 KiB
JavaScript
let indexes
|
|
|
|
function composeTimestamp(servertime){
|
|
let composed;
|
|
composed = servertime.slice(11,25).split(':').join("").split('.').join("");
|
|
return composed;
|
|
}
|
|
|
|
function findBestTimeMatch(num, arr) {
|
|
let mid;
|
|
let lo = 0;
|
|
let 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)
|
|
}
|
|
})
|
|
}
|
|
|
|
window.addEventListener("load", function(evt) {
|
|
|
|
//------------------------Buttons------------------------------
|
|
|
|
let 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.sort((a,b) => new Date(b.TimeCreated).getTime() - new Date(a.TimeCreated).getTime());
|
|
r.data.forEach(tracking => {
|
|
console.log(tracking)
|
|
let 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)
|
|
findSerialDataIndex(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()
|
|
}
|
|
addDistances(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 => {
|
|
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
|
|
} |