biketrack-plainjs/functions.js

91 lines
2.8 KiB
JavaScript
Raw Normal View History

2022-07-18 15:18:07 +02:00
// needed for instantiation of ipfs
const initIPFS = async (IPFS, ORBITDB) => {
2022-07-13 13:16:24 +02:00
// Create IPFS instance
2022-07-18 15:18:07 +02:00
// const ipfsOptions = { repo: '/orbitdb/examples/browser/new/ipfs/0.33.1', }
//const ipfs = await Ipfs.create(ipfsOptions)
2022-07-13 13:16:24 +02:00
// Create OrbitDB instance
//const orbitdb = await OrbitDB.createInstance(ipfs)
2022-07-18 15:18:07 +02:00
2022-07-13 13:16:24 +02:00
}
2022-07-18 15:18:07 +02:00
initIPFS()
async function createDb(db_name){
// Create database instance
2022-07-13 13:16:24 +02:00
2022-07-18 15:18:07 +02:00
const ipfsOptions = { repo: '/orbitdb/examples/browser/new/ipfs/0.33.1', }
const ipfs = await Ipfs.create(ipfsOptions)
const orbitdb = await OrbitDB.createInstance(ipfs)
2022-07-13 13:16:24 +02:00
// Create IPFS instance
2022-07-18 15:18:07 +02:00
const db = await orbitdb.keyvalue(db_name)
const address = db.address
console.log(address)
console.log(db.address.toString())
2022-07-18 16:53:53 +02:00
await db.put('2022-07-01T10:49:07', '49.41185089/8.67646861')
await db.put('2022-07-01T10:49:12', '49.41166303/8.67652893')
2022-07-18 15:18:07 +02:00
let csv = "./new.csv"
const value = db.all
//console.log(value)
console.log('datenbank erstellt danke')
//console.log(value)
await db.close()
return db
}
2022-07-13 13:16:24 +02:00
2022-07-18 15:18:07 +02:00
async function loadRoute(db_name){
const ipfsOptions = { repo: '/orbitdb/los', }
const ipfs = await Ipfs.create(ipfsOptions)
const orbitdb = await OrbitDB.createInstance(ipfs)
const db = await orbitdb.keyvalue(db_name)
await db.load()
console.log("loadroute ausgeführt")
const value = db.all
console.log(value)
return value;
}
async function connectDB(dbname){
const ipfsOptions = { repo: '/orbitdb/los', }
const ipfs = await Ipfs.create(ipfsOptions)
2022-07-13 13:16:24 +02:00
const orbitdb = await OrbitDB.createInstance(ipfs)
2022-07-18 15:18:07 +02:00
const db_route2 = await orbitdb.open('/orbitdb/zdpuAoog9p95yvwyGcL3xJsGcdMkxVdEDRwYwba1JrKNEgQod/'+dbname);
const route2 = db_route2.all
console.log(route2);
}
2022-07-18 16:53:53 +02:00
async function getActualCoordinates(){
}
async function getAllCoordinates(dbname){
// creater db with name db2
var db2 = await createDb(dbname)
const all_coordinates = db2.all
// coordinates in this schema 49.123/8.2311
var coordinates = Object.values(all_coordinates)
// parse to string for split and then split by /
var coordinate_string = coordinates.toString()
var between_string = coordinate_string.split("/")
var final_string = between_string.toString()
//comma string looks now like this : 49.1212,8.1231,49.1231, ...
var comma_string = final_string.split(',')
// create new Array and put string back in to array for using paths/polylines with leafleat
var newArray =[];
// use for loop for iterating over string and put it in the right order
for (var i = 0; i < comma_string.length; i++) {
var increment = i+1;
newArray.push([comma_string[i], comma_string[increment]])
increment = increment+1
i = i+1
}
console.log(newArray);
return newArray;
}
2022-07-18 15:18:07 +02:00