From 4c75409729f3012351315941c7d641025c927f3e Mon Sep 17 00:00:00 2001 From: Paul Mueller Date: Tue, 2 Aug 2022 15:58:18 +0200 Subject: [PATCH] Minor changes --- browser.html~ | 77 -------------- functions.js | 86 ++++++++++----- functions.js~ | 31 ------ index.html~ | 281 -------------------------------------------------- map.js | 47 ++++++--- new.csv~ | 87 ---------------- 6 files changed, 91 insertions(+), 518 deletions(-) delete mode 100644 browser.html~ delete mode 100644 functions.js~ delete mode 100644 index.html~ delete mode 100644 new.csv~ diff --git a/browser.html~ b/browser.html~ deleted file mode 100644 index 992dccc..0000000 --- a/browser.html~ +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - Track your bike - - - - - - - - - - - - - - - - - - - - - - - diff --git a/functions.js b/functions.js index 2112470..2471d16 100644 --- a/functions.js +++ b/functions.js @@ -19,13 +19,12 @@ async function createDb(){ const db = await orbitdb.keyvalue('routes') const address = db.address - console.log(address) - console.log(db.address.toString()) + //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') - await db.put(' 2022-07-01T10:49:25','49.41084041/8.67651128') - await db.put('2022-07-01T10:49:31','49.41049801/8.67656948') + await db.put('2022-07-01T10:49:25','49.41084041/8.67651128') await db.put('2022-07-01T10:49:31','49.41049801/8.67656948') await db.put('2022-07-01T10:49:38','49.4102198/8.67658131') await db.put('2022-07-01T10:49:44','49.40982577/8.67668618') @@ -62,16 +61,12 @@ async function createDb(){ return db } - - - - async function loadRoute(){ const db = await createDb() await db.load() console.log("loadroute ausgeführt") const value = db.all - console.log(value) + //console.log(value) return value; } async function connectDB(){ @@ -82,19 +77,19 @@ async function createDb(){ 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()) + //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) + //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) + //console.log(latest_coordinate_str) return latest_coordinate_str; } @@ -106,48 +101,83 @@ async function createDb(){ //console.log(currentCoordinate) var all_times = (Object.keys(currentCoordinate)) var lasttime = all_times[(all_times.length-1)] - console.log(lasttime) + //console.log(lasttime) return lasttime; } - + var buffer_for_i = 0; async function getAllCoordinates(){ var db2 = await createDb() - const all_coordinates = db2.all + const current_route = db2.all // coordinates in this schema 49.123/8.2311 - var coordinates = Object.values(all_coordinates) + var coordinates = Object.values(current_route) // 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(',') + const comma_string = final_string.split(',') // create new Array and put string back in to array for using paths/polylines with leafleat - var newArray =[]; + var route0 =[]; + var route1 = [] // use for loop for iterating over string and put it in the right order + //route 0 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(comma_string[i]) + if (comma_string[i] == "00"){ + console.log("00 gefunden") + buffer_for_i = i +2; + //console.log(buffer_for_i) + break; + } + route0.push([comma_string[i], comma_string[i+1]]) + i = i+1 + } + // 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); }) + : parseFloat(elem); + }) + route0 = route0.map(function(elem) { + return elem.map(function(elem2) { + 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); }) : parseFloat(elem); }) - newArray = newArray.map(function(elem) { + route1 = route1.map(function(elem) { return elem.map(function(elem2) { return parseFloat(elem2); }); }); - console.log(newArray) - //console.log(newArray) - return newArray; + //console.log(route) + return [route0, route1]; } + async function createRouteObject(){ var currentime = await getCurrentTime() var myBtn = document.createElement("p"); diff --git a/functions.js~ b/functions.js~ deleted file mode 100644 index b14936d..0000000 --- a/functions.js~ +++ /dev/null @@ -1,31 +0,0 @@ -// 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() - - async function createDb(){ - // Create database instance - - // Create IPFS instance - const ipfsOptions = { repo: '/orbitdb/examples/browser/new/ipfs/0.33.1', } - const ipfs = await Ipfs.create(ipfsOptions) - const orbitdb = await OrbitDB.createInstance(ipfs) - const db = await orbitdb.keyvalue('route1') - const address = db.address - console.log(address) - console.log(db.address.toString()) - await db.put('2022-07-01T10:49:07', '49.41185089/8.67646861') - await db.put('2022-07-01T10:49:12', '49.41166303/8.67652893') - const value = db.all - console.log(value) - } -createDb() - diff --git a/index.html~ b/index.html~ deleted file mode 100644 index 805c4e3..0000000 --- a/index.html~ +++ /dev/null @@ -1,281 +0,0 @@ - - - - - - - - Track your bike - - -
- - - -
- -
-
-
-
-

Statistics

- -
- Route X -
-
- -
-
-
- kilometers traveled - 2 Km -
-
- traveled time - 2 min -
- -
- -
-
- -
-
-
-
-
- - - - - - - - - - - - - - - - diff --git a/map.js b/map.js index bee8ebb..9994b23 100644 --- a/map.js +++ b/map.js @@ -7,24 +7,43 @@ L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { // helper function for displayRoute() async function prepare(){ - var allcoordinates = getAllCoordinates('coordinates'); - return allcoordinates; + console.log("prepare") + var route = getAllCoordinates('coordinates'); + console.log(route); + return route; } async function displayRoute() { -var allcoordinates = await prepare(); -console.log(allcoordinates); -//var marker = L.marker([49.41607523,8.67220049]).addTo(map); -var polyline = L.polyline(allcoordinates, {color: 'red'}).addTo(map); - -var currentime = await getCurrentTime() -var ul = document.getElementById("list"); -var li = document.createElement("li"); -li.appendChild(document.createTextNode("Last travelled route on: " +currentime+"")); +//color array + let color = ["blue","red","green","purple","gray","yellow"]; + var i = 0; + let current_route = await prepare(); + console.log("after prepare"); + console.log(current_route); + console.log("Current_route"); + console.log(current_route); + const current_route0 = current_route[0]; + const current_route1 = current_route[1]; + console.log("Route 0"); + console.log(current_route0); + console.log("Route 1"); + console.log(current_route1); + //var marker = L.marker([49.41607523,8.67220049]).addTo(map); + polyline0 = L.polyline(current_route0, {color: color[i]}).addTo(map); + polyline1 = L.polyline(current_route1, {color: color[i+1]}).addTo(map); + var currentime = await getCurrentTime(); + // does stuff ?? + var ul = document.getElementById("list"); + var li = document.createElement("li"); + li.appendChild(document.createTextNode("Last travelled route on: " +currentime+"")); ul.appendChild(li); - map.fitBounds(polyline.getBounds()); -map.fitBounds(polyline.getBounds()) -return currentime + //important for maps + map.fitBounds(polyline0.getBounds()); + map.fitBounds(polyline0.getBounds()); + map.fitBounds(polyline1.getBounds()); + map.fitBounds(polyline1.getBounds()); + + return currentime; } async function showBike(){ diff --git a/new.csv~ b/new.csv~ deleted file mode 100644 index 9d4ed72..0000000 --- a/new.csv~ +++ /dev/null @@ -1,87 +0,0 @@ -time,lat,lon -2022-07-01T10:49:07.000Z,49.41185089,8.67646861 -2022-07-01T10:49:12.660Z,49.41166303,8.67652893 -2022-07-01T10:49:20.000Z,49.41123636,8.67652849 -2022-07-01T10:49:25.693Z,49.41084041,8.67651128 -2022-07-01T10:49:31.870Z,49.41049801,8.67656948 -2022-07-01T10:49:38.053Z,49.4102198,8.67658131 -2022-07-01T10:49:44.222Z,49.40982577,8.67668618 -2022-07-01T10:49:50.379Z,49.4095211,8.6767495 -2022-07-01T10:49:59.000Z,49.40881224,8.67658343 -2022-07-01T10:50:06.000Z,49.4083738,8.67664092 -2022-07-01T10:50:13.000Z,49.4080936,8.676667 -2022-07-01T10:50:20.000Z,49.40797358,8.67662421 -2022-07-01T10:50:27.000Z,49.40791573,8.67663151 -2022-07-01T10:50:32.673Z,49.40795257,8.6766228 -2022-07-01T10:50:41.000Z,49.40798433,8.67665855 -2022-07-01T10:50:46.645Z,49.4079701,8.67669428 -2022-07-01T10:50:52.804Z,49.40799444,8.67669857 -2022-07-01T10:51:01.000Z,49.40789121,8.6766631 -2022-07-01T10:51:08.000Z,49.40755973,8.67658864 -2022-07-01T10:51:17.000Z,49.40689473,8.67677555 -2022-07-01T10:51:25.000Z,49.40620921,8.67697955 -2022-07-01T10:51:33.000Z,49.40555543,8.67708163 -2022-07-01T10:51:42.000Z,49.40499466,8.67692979 -2022-07-01T10:51:47.669Z,49.40458895,8.67694948 -2022-07-01T10:51:53.840Z,49.40416906,8.67702318 -2022-07-01T10:52:00.005Z,49.40382355,8.67724113 -2022-07-01T10:52:06.176Z,49.40350553,8.67751751 -2022-07-01T10:52:12.341Z,49.40314888,8.67785638 -2022-07-01T10:52:18.508Z,49.40273859,8.67812989 -2022-07-01T10:52:24.674Z,49.40232416,8.67848992 -2022-07-01T10:52:30.833Z,49.40220921,8.67911913 -2022-07-01T10:52:36.988Z,49.40197856,8.67962545 -2022-07-01T10:52:45.000Z,49.40163851,8.68023891 -2022-07-01T10:52:50.662Z,49.40129879,8.68054592 -2022-07-01T10:53:07.000Z,49.40050412,8.68132096 -2022-07-01T10:53:12.700Z,49.40034406,8.68167395 -2022-07-01T10:53:20.000Z,49.40029889,8.68197948 -2022-07-01T10:53:27.000Z,49.4000934,8.68233753 -2022-07-01T10:53:34.000Z,49.39977873,8.68282787 -2022-07-01T10:53:39.676Z,49.39954051,8.68310713 -2022-07-01T10:53:45.836Z,49.39926802,8.68338566 -2022-07-01T10:53:52.006Z,49.39909119,8.68379701 -2022-07-01T10:54:00.000Z,49.39877088,8.68459149 -2022-07-01T10:54:05.692Z,49.39865451,8.68498273 -2022-07-01T10:54:13.000Z,49.39838235,8.68510378 -2022-07-01T10:54:20.000Z,49.39808397,8.6851097 -2022-07-01T10:54:25.684Z,49.39778037,8.68529797 -2022-07-01T10:54:33.000Z,49.39735536,8.6855275 -2022-07-01T10:54:40.000Z,49.39701056,8.68558536 -2022-07-01T10:54:49.000Z,49.39683103,8.6859003 -2022-07-01T10:54:56.000Z,49.39672644,8.68651683 -2022-07-01T10:55:03.000Z,49.3964463,8.68696265 -2022-07-01T10:55:12.000Z,49.39620133,8.68741868 -2022-07-01T10:55:19.000Z,49.39597341,8.6874125 -2022-07-01T10:55:29.000Z,49.39537879,8.68760769 -2022-07-01T10:55:37.000Z,49.3949609,8.68750202 -2022-07-01T10:55:48.000Z,49.39423945,8.6877149 -2022-07-01T10:55:55.000Z,49.39378364,8.68773376 -2022-07-01T10:56:03.000Z,49.39340213,8.68778782 -2022-07-01T10:56:10.000Z,49.39303098,8.68791288 -2022-07-01T10:56:15.653Z,49.39268479,8.68795369 -2022-07-01T10:56:21.852Z,49.39248838,8.68813889 -2022-07-01T10:56:28.021Z,49.3921367,8.68808023 -2022-07-01T10:56:34.192Z,49.39168962,8.68813309 -2022-07-01T10:56:43.000Z,49.39117231,8.68814905 -2022-07-01T10:56:50.000Z,49.39076199,8.68818273 -2022-07-01T10:56:59.000Z,49.39058452,8.68776805 -2022-07-01T10:57:04.656Z,49.39048152,8.68746322 -2022-07-01T10:57:10.827Z,49.39009475,8.68742468 -2022-07-01T10:57:18.000Z,49.38966856,8.68741891 -2022-07-01T10:57:26.000Z,49.3896966,8.68683682 -2022-07-01T10:57:34.000Z,49.38985798,8.68647962 -2022-07-01T11:00:12.000Z,49.38983544,8.68654936 -2022-07-01T11:00:19.000Z,49.38982943,8.68686349 -2022-07-01T11:00:24.649Z,49.38988557,8.68711804 -2022-07-01T11:00:32.000Z,49.38975355,8.68742027 -2022-07-01T11:00:39.000Z,49.38968475,8.68789061 -2022-07-01T11:00:47.000Z,49.38968741,8.68864464 -2022-07-01T11:00:56.000Z,49.38981096,8.68935897 -2022-07-01T11:01:03.000Z,49.38991498,8.6898232 -2022-07-01T11:01:13.000Z,49.39008687,8.69005123 -2022-07-01T11:01:20.000Z,49.39012705,8.69004198 -2022-07-01T11:01:42.000Z,49.39012273,8.69044973 -2022-07-01T11:03:13.000Z,49.39020013,8.69013153 -2022-07-01T11:03:37.000Z,49.3902416,8.69011779 -2022-07-01T11:06:03.000Z,49.39010871,8.68987621