gyrogpsc/static/scripts/accChart.js
2021-01-15 12:18:09 +01:00

110 lines
3.5 KiB
JavaScript

/**
* This file defines a line chart used in the full replay page, showing Ublox horizontal accuracy,
* smartphone horizontal accuracy and distance between the positions of the Ublox
* and the Smartphone at a same time in meters, over time.
*
* @authors Timo Volkmann, Frank Herkommer.
*/
//list of all horizontal accuracies sent in by the Ublox
let allAccSerial = []
//list of all coordinates sent in by the Ublox
let allSerialCoords = []
//Defines the chart and its properties
let ctx1 = document.getElementById('accChart').getContext('2d');
let accChart = new Chart(ctx1, {
type: 'line',
data: {
labels: [],
datasets: [{
label: 'Ublox Horizontal acc. (m)',
backgroundColor: 'rgba(255, 255, 255, 1)',
borderColor: 'rgba(255, 255, 255, 1)',
borderWidth: 1,
fill: false,
pointRadius: 0.5,
lineTension: 0.5,
data: []
},
{
label: 'Smartphone Horizontal acc. (m)',
backgroundColor: 'rgb(185,190,45)',
borderColor: 'rgb(185,190,45)',
borderWidth: 1,
fill: false,
pointRadius: 0.5,
lineTension: 0.5,
data: []
},
{
label: 'Distance Ublox - Smartphone (m)',
backgroundColor: 'rgba(30, 130, 76, 1)',
borderColor: 'rgba(30, 130, 76, 1)',
borderWidth: 1,
fill: false,
pointRadius: 0.5,
lineTension: 0.5,
data: []
}]
},
options: {
scales: {
yAxes: [{
ticks: {
min: 0,
max: 20,
}
}],
xAxes: [{
type: 'time',
time: {
unit: 'second'
}
}]
},
animation: {
duration: 0
}
}
});
/**
* Function to calculate the distance between to coordinates at a same time using the vincenty algorithm.
*
* @param data all collected data.
*/
function addDistances(data){
//collect all horizontal accuracies from serial source and tcp source.
let serialHAccs = data.map(el => {
return el.ser.HAcc
})
let tcpHAccs = data.map(el => {
return el.tcp.HAcc
})
//apply vincenty algorithm on coordinates from serial and tcp source.
let distances = data.map((el, i, arr) => {
// return distVincenty(el.ser.Position, el.tcp.Position)
const plaindist = distVincenty(el.ser.Position, el.tcp.Position)
arr[i]['distance'] = plaindist
// if closest measurements not happening in the exact same millisecond,
// calculate traveled distance for the time difference and substract it from result
// bear in mind that this is not exact because the two measurements are not always exactly aligned with
// the direction of motion. that's okay because we only need to estimate the accuracy
arr[i]['distanceCleanAbs'] = plaindist - Math.abs(el.ser.Speed / 1000 * el.differenceMs)
return arr[i].distanceCleanAbs // plaindist - Math.abs(el.ser.Speed / 1000 * el.differenceMs)
})
let tcpTimes = data.map(el => {
return el.tcp.Timestamp
})
//add the data to the chart and update the hart
accChart.data.labels = tcpTimes
accChart.data.datasets[0].data = serialHAccs
accChart.data.datasets[1].data = tcpHAccs
accChart.data.datasets[2].data = distances
accChart.update()
}