fix no serial data error on tracking analysis page

This commit is contained in:
unknown 2021-01-15 17:06:24 +01:00
parent 32bb0e7785
commit b303568a0f
2 changed files with 30 additions and 11 deletions

View File

@ -97,16 +97,18 @@ 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(r.data.Data.SOURCE_SERIAL > 0 && r.data.Data.SOURCE_TCP > 0) {
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) { 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)
} }
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(r.data.Data.SOURCE_SERIAL)
} }
addDistances(prepareForDistanceCalc(r.data.Data)) addDistances(prepareForDistanceCalc(r.data.Data))
}) })
} }

View File

@ -63,14 +63,31 @@ let speedChart = new Chart(ctx, {
* As there is less smartphone data collected, we only want the Ublox speeds that come in at the moment with the * As there is less smartphone data collected, we only want the Ublox speeds that come in at the moment with the
* smallest time difference between the TCP message and the Serial message. * smallest time difference between the TCP message and the Serial message.
*/ */
function addSerialSpeedData() { function addSerialSpeedData(sensordataList) {
let speeds = [] let speedsSerial = []
let times = []
indexes.forEach(index => { if(indexes.length > 0){
speeds.push((allSpeedsSerial[index] * 3.6).toFixed(2)) indexes.forEach(index => {
}) speedsSerial.push((allSpeedsSerial[index] * 3.6).toFixed(2))
speedChart.data.datasets[0].data = speeds; })
speedChart.update(); speedChart.data.datasets[0].data = speedsSerial;
speedChart.update();
} else {
sensordataList.forEach(sensordata => {
if (sensordata.Speed === 0) {
return;
}
let speed = sensordata.Speed
speedsSerial.push((speed * 3.6).toFixed(2));
let time = sensordata.Timestamp
times.push(time)
})
speedChart.data.labels = times;
speedChart.data.datasets[0].data = speedsSerial;
speedChart.update();
}
} }
/** /**
@ -88,7 +105,7 @@ function addTCPSpeedData(sensordataList) {
} }
let speed = sensordata.Speed let speed = sensordata.Speed
speedsTCP.push((speed * 3.6).toFixed(2)); speedsTCP.push((speed * 3.6).toFixed(2));
let time = sensordata.Servertime let time = sensordata.Timestamp
times.push(time) times.push(time)
}) })