implements chart for ublox accuracy and distance between ublox and smartphone pos. in fullreplay
This commit is contained in:
parent
e74f0fd895
commit
ec11f2541d
@ -1,30 +1,30 @@
|
|||||||
var arrayTCP = [];
|
let allAccSerial = []
|
||||||
var arraySERIAL = [];
|
let allSerialCoords = []
|
||||||
|
|
||||||
var ctx = document.getElementById('accChart').getContext('2d');
|
var ctx = document.getElementById('accChart').getContext('2d');
|
||||||
var accChart = new Chart(ctx, {
|
var accChart = new Chart(ctx, {
|
||||||
type: 'line',
|
type: 'line',
|
||||||
data: {
|
data: {
|
||||||
labels: new Array(),
|
labels: [],
|
||||||
datasets: [{
|
datasets: [{
|
||||||
label: 'Ublox VAcc',
|
label: 'Ublox Horizontal acc. (m)',
|
||||||
backgroundColor: 'rgba(214, 69, 65, 1)',
|
backgroundColor: 'rgba(255, 255, 255, 1)',
|
||||||
borderColor: 'rgba(214, 69, 65, 1)',
|
borderColor: 'rgba(255, 255, 255, 1)',
|
||||||
borderWidth: 1,
|
borderWidth: 1,
|
||||||
fill: false,
|
fill: false,
|
||||||
pointRadius: 1,
|
pointRadius: 0.5,
|
||||||
lineTension: 0.5,
|
lineTension: 0.5,
|
||||||
data: arraySERIAL
|
data: []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Smartphone VAcc',
|
label: 'Distance Ublox - Smartphone (m)',
|
||||||
backgroundColor: 'rgba(30, 139, 195, 1)',
|
backgroundColor: 'rgba(30, 130, 76, 1)',
|
||||||
borderColor: 'rgba(30, 139, 195, 1)',
|
borderColor: 'rgba(30, 130, 76, 1)',
|
||||||
borderWidth: 1,
|
borderWidth: 1,
|
||||||
fill: false,
|
fill: false,
|
||||||
pointRadius: 1,
|
pointRadius: 0.5,
|
||||||
lineTension: 0.5,
|
lineTension: 0.5,
|
||||||
data: arrayTCP
|
data: []
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
@ -32,7 +32,7 @@ var accChart = new Chart(ctx, {
|
|||||||
yAxes: [{
|
yAxes: [{
|
||||||
ticks: {
|
ticks: {
|
||||||
min: 0,
|
min: 0,
|
||||||
max: 10,
|
max: 20,
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
xAxes: [{
|
xAxes: [{
|
||||||
@ -48,56 +48,62 @@ var accChart = new Chart(ctx, {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/*function addSerialSpeedData() {
|
function addSerialHAccData(){
|
||||||
let speeds = []
|
|
||||||
|
|
||||||
indexes.forEach(index => {
|
|
||||||
speeds.push((allSpeedsSerial[index] * 3.6).toFixed(2))
|
|
||||||
})
|
|
||||||
accChart.data.datasets[0].data = speeds;
|
|
||||||
accChart.update();
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
function addTCPSpeedData(sensordataList) {
|
|
||||||
let speedsTCP = []
|
|
||||||
let times = []
|
|
||||||
|
|
||||||
sensordataList.forEach(sensordata => {
|
|
||||||
if (sensordata.Speed === 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let speed = sensordata.Speed
|
|
||||||
speedsTCP.push((speed * 3.6).toFixed(2));
|
|
||||||
let time = sensordata.Servertime
|
|
||||||
times.push(time)
|
|
||||||
|
|
||||||
})
|
|
||||||
accChart.data.labels = times;
|
|
||||||
accChart.data.datasets[1].data = speedsTCP;
|
|
||||||
|
|
||||||
accChart.update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function findSerialDataIndex(tcpdataList, serialdataList) {
|
function addDistances(tcpDataList, serialDataList){
|
||||||
let allSerialTimes = []
|
let tcpCoords = []
|
||||||
|
let serialCoords = []
|
||||||
|
|
||||||
serialdataList.forEach(sensordata => {
|
let tcpTimes = []
|
||||||
if (!(sensordata.Speed === 0)) {
|
let serialHAccs = []
|
||||||
let serialTimestamp;
|
let distances = []
|
||||||
allSpeedsSerial.push(sensordata.Speed)
|
|
||||||
serialTimestamp = composeServertime(sensordata.Servertime)
|
indexes.forEach(index => {
|
||||||
allSerialTimes.push(serialTimestamp)
|
serialHAccs.push(allAccSerial[index].toFixed(2))
|
||||||
|
serialCoords.push(allSerialCoords[index])
|
||||||
|
})
|
||||||
|
|
||||||
|
tcpDataList.forEach(sensordata => {
|
||||||
|
if (!(sensordata.Position[0] === 0) && !(sensordata.Position[1] === 0)) {
|
||||||
|
let tcpCoord = [sensordata.Position[1], sensordata.Position[0]]
|
||||||
|
tcpCoords.push(tcpCoord)
|
||||||
|
|
||||||
|
let time = sensordata.Servertime
|
||||||
|
tcpTimes.push(time)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
tcpdataList.forEach(sensordata => {
|
for(let i = 0; i < tcpCoords.length; i++){
|
||||||
if (!(sensordata.Speed === 0)) {
|
let distance = distanceInMetersBetweenEarthCoordinates
|
||||||
let tcpTimestamp = composeServertime(sensordata.Servertime)
|
(serialCoords[i][1],serialCoords[i][0],tcpCoords[i][1],tcpCoords[i][0])
|
||||||
let index = findBestTimeMatch(tcpTimestamp, allSerialTimes)[1]
|
distances.push(distance)
|
||||||
|
}
|
||||||
|
|
||||||
indexes.push(index)
|
console.log("distances: " + distances)
|
||||||
}
|
|
||||||
})
|
accChart.data.labels = tcpTimes
|
||||||
console.log("indexes: " + indexes)
|
accChart.data.datasets[0].data = serialHAccs
|
||||||
}*/
|
accChart.data.datasets[1].data = distances
|
||||||
|
accChart.update()
|
||||||
|
}
|
||||||
|
|
||||||
|
function degreesToRadians(degrees) {
|
||||||
|
return degrees * Math.PI / 180;
|
||||||
|
}
|
||||||
|
|
||||||
|
function distanceInMetersBetweenEarthCoordinates(lat1, lon1, lat2, lon2) {
|
||||||
|
var earthRadiusKm = 6371
|
||||||
|
|
||||||
|
var dLat = degreesToRadians(lat2-lat1)
|
||||||
|
var dLon = degreesToRadians(lon2-lon1)
|
||||||
|
|
||||||
|
lat1 = degreesToRadians(lat1)
|
||||||
|
lat2 = degreesToRadians(lat2)
|
||||||
|
|
||||||
|
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
|
||||||
|
Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2)
|
||||||
|
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a))
|
||||||
|
return (earthRadiusKm * c) * 1000
|
||||||
|
}
|
||||||
@ -1,5 +1,4 @@
|
|||||||
let allSpeedsSerial = []
|
let allSpeedsSerial = []
|
||||||
let indexes = []
|
|
||||||
|
|
||||||
var ctx = document.getElementById('speedChart').getContext('2d');
|
var ctx = document.getElementById('speedChart').getContext('2d');
|
||||||
var speedChart = new Chart(ctx, {
|
var speedChart = new Chart(ctx, {
|
||||||
@ -14,7 +13,7 @@ var speedChart = new Chart(ctx, {
|
|||||||
fill: false,
|
fill: false,
|
||||||
pointRadius: 1,
|
pointRadius: 1,
|
||||||
lineTension: 0.5,
|
lineTension: 0.5,
|
||||||
data: arraySERIAL
|
data: []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Smartphone speed',
|
label: 'Smartphone speed',
|
||||||
@ -24,7 +23,7 @@ var speedChart = new Chart(ctx, {
|
|||||||
fill: false,
|
fill: false,
|
||||||
pointRadius: 1,
|
pointRadius: 1,
|
||||||
lineTension: 0.5,
|
lineTension: 0.5,
|
||||||
data: arrayTCP
|
data: []
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
@ -77,27 +76,4 @@ function addTCPSpeedData(sensordataList) {
|
|||||||
speedChart.data.datasets[1].data = speedsTCP;
|
speedChart.data.datasets[1].data = speedsTCP;
|
||||||
|
|
||||||
speedChart.update();
|
speedChart.update();
|
||||||
}
|
|
||||||
|
|
||||||
function findSerialDataIndex(tcpdataList, serialdataList) {
|
|
||||||
let allSerialTimes = []
|
|
||||||
|
|
||||||
serialdataList.forEach(sensordata => {
|
|
||||||
if (!(sensordata.Speed === 0)) {
|
|
||||||
let serialTimestamp;
|
|
||||||
allSpeedsSerial.push(sensordata.Speed)
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
console.log("indexes: " + indexes)
|
|
||||||
}
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
var trackingdata = null;
|
var trackingdata = null;
|
||||||
|
let indexes
|
||||||
|
|
||||||
function composeServertime(servertime){
|
function composeServertime(servertime){
|
||||||
var composed;
|
var composed;
|
||||||
@ -6,6 +7,13 @@ function composeServertime(servertime){
|
|||||||
return composed;
|
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) {
|
function findBestTimeMatch(num, arr) {
|
||||||
var mid;
|
var mid;
|
||||||
var lo = 0;
|
var lo = 0;
|
||||||
@ -24,6 +32,30 @@ function findBestTimeMatch(num, arr) {
|
|||||||
return [arr[hi], hi];
|
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) {
|
window.addEventListener("load", function(evt) {
|
||||||
//------------------------Buttons------------------------------
|
//------------------------Buttons------------------------------
|
||||||
|
|
||||||
@ -52,6 +84,11 @@ window.addEventListener("load", function(evt) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
document.getElementById("replaystarten").onclick = function(evt) {
|
document.getElementById("replaystarten").onclick = function(evt) {
|
||||||
|
indexes = []
|
||||||
|
allSpeedsSerial = []
|
||||||
|
allAccSerial = []
|
||||||
|
allSerialCoords = []
|
||||||
|
|
||||||
let sel = document.getElementById("meas")
|
let sel = document.getElementById("meas")
|
||||||
console.log(trackings[sel.selectedIndex].UUID)
|
console.log(trackings[sel.selectedIndex].UUID)
|
||||||
fetch(`http://localhost:3011/trackings/${trackings[sel.selectedIndex].UUID}`, { method: 'GET'}).then(results => {
|
fetch(`http://localhost:3011/trackings/${trackings[sel.selectedIndex].UUID}`, { method: 'GET'}).then(results => {
|
||||||
@ -59,7 +96,10 @@ window.addEventListener("load", function(evt) {
|
|||||||
}).then(r => {
|
}).then(r => {
|
||||||
console.log(r.data.Data)
|
console.log(r.data.Data)
|
||||||
console.log(r.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 && '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) {
|
if ('SOURCE_TCP' in r.data.Data && r.data.Data.SOURCE_TCP.length > 0) {
|
||||||
updateMapTCPbulk(r.data.Data.SOURCE_TCP)
|
updateMapTCPbulk(r.data.Data.SOURCE_TCP)
|
||||||
addTCPSpeedData(r.data.Data.SOURCE_TCP)
|
addTCPSpeedData(r.data.Data.SOURCE_TCP)
|
||||||
@ -67,6 +107,7 @@ window.addEventListener("load", function(evt) {
|
|||||||
if ('SOURCE_SERIAL' in r.data.Data && r.data.Data.SOURCE_SERIAL.length > 0) {
|
if ('SOURCE_SERIAL' in r.data.Data && r.data.Data.SOURCE_SERIAL.length > 0) {
|
||||||
updateMapSERIALbulk(r.data.Data.SOURCE_SERIAL)
|
updateMapSERIALbulk(r.data.Data.SOURCE_SERIAL)
|
||||||
addSerialSpeedData()
|
addSerialSpeedData()
|
||||||
|
addSerialHAccData()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user