|
@ -1,12 +1,6 @@ |
|
|
// needed for instantiation of ipfs
|
|
|
// needed for instantiation of ipfs
|
|
|
const initIPFS = async (IPFS, ORBITDB) => { |
|
|
const initIPFS = async (IPFS, ORBITDB) => { |
|
|
|
|
|
|
|
|
// Create IPFS instance
|
|
|
|
|
|
// const ipfsOptions = { repo: '/orbitdb/examples/browser/new/ipfs/0.33.1', }
|
|
|
|
|
|
//const ipfs = await Ipfs.create(ipfsOptions)
|
|
|
|
|
|
|
|
|
|
|
|
// Create OrbitDB instance
|
|
|
|
|
|
//const orbitdb = await OrbitDB.createInstance(ipfs)
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
initIPFS() |
|
|
initIPFS() |
|
@ -15,12 +9,9 @@ async function createDb(){ |
|
|
|
|
|
|
|
|
// Create database instance
|
|
|
// Create database instance
|
|
|
const orbitdb = await OrbitDB.createInstance(ipfs) |
|
|
const orbitdb = await OrbitDB.createInstance(ipfs) |
|
|
//const ipfsOptions = { repo: '/orbitdb/createdb1', }
|
|
|
|
|
|
|
|
|
|
|
|
const db = await orbitdb.keyvalue('routes') |
|
|
const db = await orbitdb.keyvalue('routes') |
|
|
const address = db.address |
|
|
const address = db.address |
|
|
//console.log(address)
|
|
|
|
|
|
//console.log(db.address.toString())
|
|
|
|
|
|
await db.put('2022-07-01T10:49:07', '49.41185089/8.67646861',{pin: true}) |
|
|
await db.put('2022-07-01T10:49:07', '49.41185089/8.67646861',{pin: true}) |
|
|
await db.put('2022-07-01T10:49:12', '49.41166303/8.67652893') |
|
|
await db.put('2022-07-01T10:49:12', '49.41166303/8.67652893') |
|
|
await db.put('2022-07-01T10:49:20','49.41123636/8.67652849') |
|
|
await db.put('2022-07-01T10:49:20','49.41123636/8.67652849') |
|
@ -54,9 +45,7 @@ async function createDb(){ |
|
|
await db.put('2022-07-01T11:06:03','49.39010871/8.68987621') |
|
|
await db.put('2022-07-01T11:06:03','49.39010871/8.68987621') |
|
|
let csv = "./new.csv" |
|
|
let csv = "./new.csv" |
|
|
const value = db.all |
|
|
const value = db.all |
|
|
//console.log(value)
|
|
|
|
|
|
console.log('database connected!') |
|
|
console.log('database connected!') |
|
|
//console.log(value)
|
|
|
|
|
|
await db.close() |
|
|
await db.close() |
|
|
return db |
|
|
return db |
|
|
} |
|
|
} |
|
@ -66,30 +55,21 @@ async function createDb(){ |
|
|
await db.load() |
|
|
await db.load() |
|
|
console.log("loadroute ausgeführt") |
|
|
console.log("loadroute ausgeführt") |
|
|
const value = db.all |
|
|
const value = db.all |
|
|
//console.log(value)
|
|
|
|
|
|
return value; |
|
|
return value; |
|
|
} |
|
|
} |
|
|
async function connectDB(){ |
|
|
async function connectDB(){ |
|
|
//const ipfsOptions = { repo: '/orbitdb/los', }
|
|
|
|
|
|
//const ipfs = await Ipfs.create(ipfsOptions)
|
|
|
|
|
|
const ipfs = await Ipfs.create() |
|
|
const ipfs = await Ipfs.create() |
|
|
const orbitdb = await OrbitDB.createInstance(ipfs) |
|
|
const orbitdb = await OrbitDB.createInstance(ipfs) |
|
|
const db_route2 = await orbitdb.open('/orbitdb/zdpuApZ7pMKupZjmxPQk8xp34QdAEXHFFjmA3EPWuACN88DwB/coordinates'); |
|
|
const db_route2 = await orbitdb.open('/orbitdb/zdpuApZ7pMKupZjmxPQk8xp34QdAEXHFFjmA3EPWuACN88DwB/coordinates'); |
|
|
//const route2 = db_route2.all
|
|
|
|
|
|
//console.log(OrbitDB.isValidAddress('/orbitdb/zdpuAqETvwNibieag6o5ahX4d6WKXi6QZvbar3XZPJEXz3vSE/coordinates'));
|
|
|
|
|
|
//console.log(db_route2.all);
|
|
|
|
|
|
//console.log(db_route2.address.toString())
|
|
|
|
|
|
return db_route2; |
|
|
return db_route2; |
|
|
} |
|
|
} |
|
|
async function getCurrentCoordinate(){ |
|
|
async function getCurrentCoordinate(){ |
|
|
var db_conn = await createDb() |
|
|
var db_conn = await createDb() |
|
|
const currentCoordinate = db_conn.all |
|
|
const currentCoordinate = db_conn.all |
|
|
//console.log(currentCoordinate)
|
|
|
|
|
|
var latest_coord_string = (currentCoordinate[Object.keys(currentCoordinate)[Object.keys(currentCoordinate).length - 1]]) |
|
|
var latest_coord_string = (currentCoordinate[Object.keys(currentCoordinate)[Object.keys(currentCoordinate).length - 1]]) |
|
|
var latest_coordinate_str = latest_coord_string.split("/") |
|
|
var latest_coordinate_str = latest_coord_string.split("/") |
|
|
latest_coordinate_str[0] = parseFloat(latest_coordinate_str[0]) |
|
|
latest_coordinate_str[0] = parseFloat(latest_coordinate_str[0]) |
|
|
latest_coordinate_str[1] = parseFloat(latest_coordinate_str[1]) |
|
|
latest_coordinate_str[1] = parseFloat(latest_coordinate_str[1]) |
|
|
//console.log(latest_coordinate_str)
|
|
|
|
|
|
|
|
|
|
|
|
return latest_coordinate_str; |
|
|
return latest_coordinate_str; |
|
|
} |
|
|
} |
|
@ -98,10 +78,8 @@ async function createDb(){ |
|
|
|
|
|
|
|
|
var db_conn = await createDb() |
|
|
var db_conn = await createDb() |
|
|
const currentCoordinate = db_conn.all |
|
|
const currentCoordinate = db_conn.all |
|
|
//console.log(currentCoordinate)
|
|
|
|
|
|
var all_times = (Object.keys(currentCoordinate)) |
|
|
var all_times = (Object.keys(currentCoordinate)) |
|
|
var lasttime = all_times[(all_times.length-1)] |
|
|
var lasttime = all_times[(all_times.length-1)] |
|
|
//console.log(lasttime)
|
|
|
|
|
|
return lasttime; |
|
|
return lasttime; |
|
|
} |
|
|
} |
|
|
async function getAllCoordinates(){ |
|
|
async function getAllCoordinates(){ |
|
@ -182,25 +160,16 @@ async function getAllRoutes(){ |
|
|
return parseFloat(elem2); |
|
|
return parseFloat(elem2); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
//console.log("route0")
|
|
|
|
|
|
//console.log(route0)
|
|
|
|
|
|
//route 1
|
|
|
|
|
|
for (var i = buffer_for_i; i < comma_string.length; i++) { |
|
|
for (var i = buffer_for_i; i < comma_string.length; i++) { |
|
|
console.log(buffer_for_i) |
|
|
console.log(buffer_for_i) |
|
|
if (comma_string[i] == "00"){ |
|
|
if (comma_string[i] == "00"){ |
|
|
//console.log("00 gefunden")
|
|
|
|
|
|
//console.log(buffer_for_i)
|
|
|
|
|
|
break; |
|
|
break; |
|
|
}else if(comma_string[i] == "11"){ |
|
|
}else if(comma_string[i] == "11"){ |
|
|
noroutes = 1; |
|
|
noroutes = 1; |
|
|
//console.log("Ende gefunden")
|
|
|
|
|
|
} |
|
|
} |
|
|
route1.push([comma_string[i], comma_string[i+1]]) |
|
|
route1.push([comma_string[i], comma_string[i+1]]) |
|
|
i = i+1 |
|
|
i = i+1 |
|
|
} |
|
|
} |
|
|
//console.log("route1")
|
|
|
|
|
|
//console.log(route1)
|
|
|
|
|
|
// its only for converting the string array to a float array, because leaflethjs wants only a float array
|
|
|
|
|
|
(function(elem) { |
|
|
(function(elem) { |
|
|
var callee = arguments.callee; |
|
|
var callee = arguments.callee; |
|
|
return elem instanceof Array ? elem.map(function(elem2) { return callee(elem2); }) |
|
|
return elem instanceof Array ? elem.map(function(elem2) { return callee(elem2); }) |
|
@ -212,7 +181,6 @@ async function getAllRoutes(){ |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
//console.log(route)
|
|
|
|
|
|
return [route0, route1]; |
|
|
return [route0, route1]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -250,17 +218,14 @@ async function allRoutes(number_of_ze_route) { |
|
|
let current = await prepare(); |
|
|
let current = await prepare(); |
|
|
const current_route = current[number_of_ze_route]; |
|
|
const current_route = current[number_of_ze_route]; |
|
|
clearMap() |
|
|
clearMap() |
|
|
//var marker = L.marker([49.41607523,8.67220049]).addTo(map);
|
|
|
|
|
|
polyline = L.polyline(current_route, {color: color[i]}).addTo(map); |
|
|
polyline = L.polyline(current_route, {color: color[i]}).addTo(map); |
|
|
var currentime = await getCurrentTime(); |
|
|
var currentime = await getCurrentTime(); |
|
|
// does stuff ??
|
|
|
|
|
|
var ul = document.getElementById("list"); |
|
|
var ul = document.getElementById("list"); |
|
|
var li = document.createElement("li"); |
|
|
var li = document.createElement("li"); |
|
|
li.appendChild(document.createTextNode("Route "+ (number_of_ze_route + 1) + " was travelled on: " + currentime + "" )); |
|
|
li.appendChild(document.createTextNode("Route "+ (number_of_ze_route + 1) + " was travelled on: " + currentime + "" )); |
|
|
ul.appendChild(li); |
|
|
ul.appendChild(li); |
|
|
|
|
|
|
|
|
//important for maps
|
|
|
//important for maps
|
|
|
|
|
|
|
|
|
map.fitBounds(polyline.getBounds()); |
|
|
map.fitBounds(polyline.getBounds()); |
|
|
map.fitBounds(polyline.getBounds()); |
|
|
map.fitBounds(polyline.getBounds()); |
|
|
|
|
|
|
|
@ -272,27 +237,7 @@ async function showRoutes(){ |
|
|
console.log("Gotten all routes"); |
|
|
console.log("Gotten all routes"); |
|
|
console.log(len); |
|
|
console.log(len); |
|
|
var i = 0; |
|
|
var i = 0; |
|
|
/* Doesnt work yet |
|
|
|
|
|
var btn = []; |
|
|
|
|
|
console.log("Beginning while with i = " + i) |
|
|
|
|
|
while (i < len){ |
|
|
|
|
|
console.log("this is i: " + i) |
|
|
|
|
|
console.log("this is len: " + len) |
|
|
|
|
|
|
|
|
|
|
|
btn[i] = document.createElement("button"); |
|
|
|
|
|
btn[i].innerHTML = ("Route " + (i + 1)); |
|
|
|
|
|
btn[i].onclick = function () { |
|
|
|
|
|
console.log("i is " + i) |
|
|
|
|
|
console.log("setting allroutes with i as " + (i-1)); |
|
|
|
|
|
allRoutes((i-1)); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
document.body.appendChild(btn[i]); |
|
|
|
|
|
console.log("Button generated with i = "+ i) |
|
|
|
|
|
i = i + 1; |
|
|
|
|
|
} |
|
|
|
|
|
*/ |
|
|
|
|
|
// WORKS
|
|
|
|
|
|
|
|
|
|
|
|
console.log("this is i: " + i) |
|
|
console.log("this is i: " + i) |
|
|
console.log("this is len: " + len) |
|
|
console.log("this is len: " + len) |
|
@ -311,6 +256,5 @@ async function showRoutes(){ |
|
|
document.body.appendChild(btn0); |
|
|
document.body.appendChild(btn0); |
|
|
document.body.appendChild(document.createElement('br')); |
|
|
document.body.appendChild(document.createElement('br')); |
|
|
document.body.appendChild(btn1); |
|
|
document.body.appendChild(btn1); |
|
|
//*/
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|