From bad67e5fc84239de6dee57f507b97f58cead50c7 Mon Sep 17 00:00:00 2001 From: jeanz6 Date: Wed, 17 Aug 2022 16:43:02 +0200 Subject: [PATCH] refurbished code --- execution.js | 6 ---- functions.js | 58 +-------------------------------- index.html | 90 +--------------------------------------------------- 3 files changed, 2 insertions(+), 152 deletions(-) delete mode 100644 execution.js diff --git a/execution.js b/execution.js deleted file mode 100644 index 495f93a..0000000 --- a/execution.js +++ /dev/null @@ -1,6 +0,0 @@ -(async () =>{ -//displayRoute(); -//showBike() -//createDb() -//getCurrentTime() -})(); diff --git a/functions.js b/functions.js index 804a9c6..d691914 100644 --- a/functions.js +++ b/functions.js @@ -1,12 +1,6 @@ // needed for instantiation of ipfs 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() @@ -15,12 +9,9 @@ async function createDb(){ // Create database instance const orbitdb = await OrbitDB.createInstance(ipfs) - //const ipfsOptions = { repo: '/orbitdb/createdb1', } const db = await orbitdb.keyvalue('routes') 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:12', '49.41166303/8.67652893') 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') let csv = "./new.csv" const value = db.all - //console.log(value) console.log('database connected!') - //console.log(value) await db.close() return db } @@ -66,30 +55,21 @@ async function createDb(){ await db.load() console.log("loadroute ausgeführt") const value = db.all - //console.log(value) return value; } async function connectDB(){ - //const ipfsOptions = { repo: '/orbitdb/los', } - //const ipfs = await Ipfs.create(ipfsOptions) const ipfs = await Ipfs.create() const orbitdb = await OrbitDB.createInstance(ipfs) 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; } async function getCurrentCoordinate(){ var db_conn = await createDb() const currentCoordinate = db_conn.all - //console.log(currentCoordinate) var latest_coord_string = (currentCoordinate[Object.keys(currentCoordinate)[Object.keys(currentCoordinate).length - 1]]) var latest_coordinate_str = latest_coord_string.split("/") latest_coordinate_str[0] = parseFloat(latest_coordinate_str[0]) latest_coordinate_str[1] = parseFloat(latest_coordinate_str[1]) - //console.log(latest_coordinate_str) return latest_coordinate_str; } @@ -98,10 +78,8 @@ async function createDb(){ var db_conn = await createDb() const currentCoordinate = db_conn.all - //console.log(currentCoordinate) var all_times = (Object.keys(currentCoordinate)) var lasttime = all_times[(all_times.length-1)] - //console.log(lasttime) return lasttime; } async function getAllCoordinates(){ @@ -182,25 +160,16 @@ async function getAllRoutes(){ return parseFloat(elem2); }); }); - //console.log("route0") - //console.log(route0) - //route 1 for (var i = buffer_for_i; i < comma_string.length; i++) { console.log(buffer_for_i) if (comma_string[i] == "00"){ - //console.log("00 gefunden") - //console.log(buffer_for_i) break; }else if(comma_string[i] == "11"){ noroutes = 1; - //console.log("Ende gefunden") } route1.push([comma_string[i], comma_string[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) { var callee = arguments.callee; return elem instanceof Array ? elem.map(function(elem2) { return callee(elem2); }) @@ -212,7 +181,6 @@ async function getAllRoutes(){ }); }); - //console.log(route) return [route0, route1]; } @@ -250,17 +218,14 @@ async function allRoutes(number_of_ze_route) { let current = await prepare(); const current_route = current[number_of_ze_route]; clearMap() - //var marker = L.marker([49.41607523,8.67220049]).addTo(map); polyline = L.polyline(current_route, {color: color[i]}).addTo(map); var currentime = await getCurrentTime(); - // does stuff ?? var ul = document.getElementById("list"); var li = document.createElement("li"); li.appendChild(document.createTextNode("Route "+ (number_of_ze_route + 1) + " was travelled on: " + currentime + "" )); ul.appendChild(li); //important for maps - map.fitBounds(polyline.getBounds()); map.fitBounds(polyline.getBounds()); @@ -272,27 +237,7 @@ async function showRoutes(){ console.log("Gotten all routes"); console.log(len); 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 len: " + len) @@ -311,6 +256,5 @@ async function showRoutes(){ document.body.appendChild(btn0); document.body.appendChild(document.createElement('br')); document.body.appendChild(btn1); - //*/ } diff --git a/index.html b/index.html index 0ae6ac8..ea4c38b 100644 --- a/index.html +++ b/index.html @@ -24,13 +24,6 @@ @@ -54,9 +47,7 @@ async function prepare_time(){ var currentime = await getCurrentTime(); return currentime - } //document.write(getCurrentTime()) - // var currentime = prepare_time() - //document.getElementById("time").innerHTML = currentime + } @@ -67,84 +58,5 @@ \ No newline at end of file