117 lines
3.9 KiB
JavaScript
117 lines
3.9 KiB
JavaScript
var trackingdata = null;
|
|
let indexes
|
|
|
|
function composeServertime(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)) {
|
|
let serialTimestamp;
|
|
allSpeedsSerial.push(sensordata.Speed)
|
|
allAccSerial.push(sensordata.HAcc)
|
|
allSerialCoords.push([sensordata.Position[1], sensordata.Position[0]])
|
|
serialTimestamp = composeServertime(sensordata.Servertime)
|
|
allSerialTimes.push(serialTimestamp)
|
|
}
|
|
})
|
|
|
|
tcpdataList.forEach(sensordata => {
|
|
if (!(sensordata.Speed === 0)) {
|
|
let tcpTimestamp = composeServertime(sensordata.Servertime)
|
|
let index = findBestTimeMatch(tcpTimestamp, allSerialTimes)[1]
|
|
|
|
indexes.push(index)
|
|
}
|
|
})
|
|
}
|
|
|
|
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()
|
|
addSerialHAccData()
|
|
}
|
|
})
|
|
|
|
}
|
|
});
|
|
|