gyrogpsc/static/scripts/chartfull.js

136 lines
3.3 KiB
JavaScript

/*var tcpServertimesSpeedsPos = {
data: [
{
dataset: {
times: [],
speeds: [],
positions: []
}
}
]
}
var serialServertimesSpeedsPos = {
data: [
{
dataset: {
times: [],
speeds: [],
positions: []
}
}
]
}*/
let allSpeedsSerial = []
let indexes = []
var arrayTCP = [];
var arraySERIAL = [];
var ctx = document.getElementById('myChart').getContext('2d');
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: new Array(),
datasets: [{
label: 'Ublox',
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',
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: 250,
stepSize: 25
}
}],
xAxes: [{
type: 'time',
time: {
unit: 'second'
}
}]
},
animation: {
duration: 0
}
}
});
//myChart.data.labels.fill("", 0, GRAPH_RES);
//myChart.data.datasets.forEach((dataset) => dataset.data.fill(0, 0, GRAPH_RES))
function addSerialSpeedData() {
let speeds = []
indexes.forEach(index => {
speeds.push((allSpeedsSerial[index].toFixed(2) * 3.6 * 3.6))
})
myChart.data.datasets[0].data = speeds;
myChart.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);
let time = sensordata.Servertime
times.push(time)
})
myChart.data.labels = times;
myChart.data.datasets[1].data = speedsTCP;
/*while (myChart.data.labels.length >= GRAPH_RES) {
myChart.data.labels.shift();
myChart.data.datasets.forEach((dataset) => dataset.data.shift())
}*/
myChart.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)
};