gyrogpsc/static/scripts/accChart.js
2021-01-07 17:18:05 +01:00

104 lines
2.6 KiB
JavaScript

var arrayTCP = [];
var arraySERIAL = [];
var ctx = document.getElementById('accChart').getContext('2d');
var accChart = new Chart(ctx, {
type: 'line',
data: {
labels: new Array(),
datasets: [{
label: 'Ublox VAcc',
backgroundColor: 'rgba(214, 69, 65, 1)',
borderColor: 'rgba(214, 69, 65, 1)',
borderWidth: 1,
fill: false,
pointRadius: 1,
lineTension: 0.5,
data: arraySERIAL
},
{
label: 'Smartphone VAcc',
backgroundColor: 'rgba(30, 139, 195, 1)',
borderColor: 'rgba(30, 139, 195, 1)',
borderWidth: 1,
fill: false,
pointRadius: 1,
lineTension: 0.5,
data: arrayTCP
}]
},
options: {
scales: {
yAxes: [{
ticks: {
min: 0,
max: 10,
}
}],
xAxes: [{
type: 'time',
time: {
unit: 'second'
}
}]
},
animation: {
duration: 0
}
}
});
/*function addSerialSpeedData() {
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) {
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)
}*/