|
@@ -52,7 +52,11 @@ window.onload = function() {
|
|
importFiles(fileList)
|
|
importFiles(fileList)
|
|
})
|
|
})
|
|
|
|
|
|
- document.getElementById("upload-btn").addEventListener('click', (event) => {
|
|
|
|
|
|
+ const button = document.getElementById("upload-btn");
|
|
|
|
+ const responseP = document.getElementById("response");
|
|
|
|
+ button.addEventListener('click', (event) => {
|
|
|
|
+ button.disabled = true;
|
|
|
|
+ responseP.textContent = "waiting for response..."
|
|
const xmlhttp = new XMLHttpRequest()
|
|
const xmlhttp = new XMLHttpRequest()
|
|
xmlhttp.open("POST", "markers/create", true);
|
|
xmlhttp.open("POST", "markers/create", true);
|
|
xmlhttp.setRequestHeader("Content-type", "application/json")
|
|
xmlhttp.setRequestHeader("Content-type", "application/json")
|
|
@@ -60,7 +64,14 @@ window.onload = function() {
|
|
xmlhttp.setRequestHeader('X-CSRFToken', token)
|
|
xmlhttp.setRequestHeader('X-CSRFToken', token)
|
|
xmlhttp.onreadystatechange = () => {
|
|
xmlhttp.onreadystatechange = () => {
|
|
if(xmlhttp.readyState == 4) {
|
|
if(xmlhttp.readyState == 4) {
|
|
- alert(xmlhttp.responseText)
|
|
|
|
|
|
+ if(xmlhttp.status == 201)
|
|
|
|
+ responseP.textContent = "Markers created!"
|
|
|
|
+ else if(xmlhttp.status == 204)
|
|
|
|
+ responseP.textContent = "Nothing to change!"
|
|
|
|
+ else
|
|
|
|
+ responseP.textContent = `Error code ${xmlhttp.status}`
|
|
|
|
+ button.disabled = false;
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
xmlhttp.send(JSON.stringify(markersToUpload))
|
|
xmlhttp.send(JSON.stringify(markersToUpload))
|
|
@@ -69,7 +80,7 @@ window.onload = function() {
|
|
function importFiles(fileList) {
|
|
function importFiles(fileList) {
|
|
d = []
|
|
d = []
|
|
plot = $.plot("#placeholder", d, options);
|
|
plot = $.plot("#placeholder", d, options);
|
|
- markersToUpload = []
|
|
|
|
|
|
+ markersToUpload = {}
|
|
for (const file of fileList) {
|
|
for (const file of fileList) {
|
|
if(file.name?.toLowerCase().endsWith(".txt"))
|
|
if(file.name?.toLowerCase().endsWith(".txt"))
|
|
readTxtFile(file)
|
|
readTxtFile(file)
|
|
@@ -117,9 +128,9 @@ function parseNmeaFile(file) {
|
|
if(ggaObj.time != oldTime) {
|
|
if(ggaObj.time != oldTime) {
|
|
oldTime = ggaObj.time
|
|
oldTime = ggaObj.time
|
|
result.push({
|
|
result.push({
|
|
- timestamp: ggaObj.time,
|
|
|
|
- lat: ggaObj.lat,
|
|
|
|
- lng: ggaObj.lon,
|
|
|
|
|
|
+ timestamp: obj.time,
|
|
|
|
+ lat: obj.lat,
|
|
|
|
+ lng: obj.lon,
|
|
alt: ggaObj.alt,
|
|
alt: ggaObj.alt,
|
|
hdop: ggaObj.hdop,
|
|
hdop: ggaObj.hdop,
|
|
speed: Math.round(obj.speed)
|
|
speed: Math.round(obj.speed)
|
|
@@ -149,7 +160,7 @@ function parseNmeaFile(file) {
|
|
reader.readAsText(file)
|
|
reader.readAsText(file)
|
|
}
|
|
}
|
|
|
|
|
|
-let markersToUpload = [];
|
|
|
|
|
|
+let markersToUpload;
|
|
|
|
|
|
function process(name, markers) {
|
|
function process(name, markers) {
|
|
d.push({
|
|
d.push({
|
|
@@ -165,8 +176,8 @@ function process(name, markers) {
|
|
const dx23 = distance(m2, m3)
|
|
const dx23 = distance(m2, m3)
|
|
const dx13 = distance(m2, m3)
|
|
const dx13 = distance(m2, m3)
|
|
const dt12 = (m2.timestamp - m1.timestamp) / 1000
|
|
const dt12 = (m2.timestamp - m1.timestamp) / 1000
|
|
- const dt23 = (m2.timestamp - m1.timestamp) / 1000
|
|
|
|
- const dt13 = (m3.timestamp - m1.timestamp) / 1000
|
|
|
|
|
|
+ const dt23 = (m3.timestamp - m2.timestamp) / 1000
|
|
|
|
+ const dt13 = dt12 + dt23
|
|
|
|
|
|
if(dt12 > 0 && dx12/dt12 > 50) {// > 50 m/s = 180 km/h
|
|
if(dt12 > 0 && dx12/dt12 > 50) {// > 50 m/s = 180 km/h
|
|
console.log(`n=${i} ${m1.timestamp} too fast: ${dx12/dt12} m/s`)
|
|
console.log(`n=${i} ${m1.timestamp} too fast: ${dx12/dt12} m/s`)
|
|
@@ -204,7 +215,7 @@ function process(name, markers) {
|
|
plot.setupGrid() //only necessary if your new data will change the axes or grid
|
|
plot.setupGrid() //only necessary if your new data will change the axes or grid
|
|
plot.draw()
|
|
plot.draw()
|
|
|
|
|
|
- markersToUpload = markersToUpload.concat(markers)
|
|
|
|
|
|
+ markersToUpload[name] = markers
|
|
}
|
|
}
|
|
|
|
|
|
function clean(markers) {
|
|
function clean(markers) {
|