Browse Source

refurbished code

improvements
jeanz6 2 years ago
parent
commit
bad67e5fc8
  1. 6
      execution.js
  2. 58
      functions.js
  3. 90
      index.html

6
execution.js

@ -1,6 +0,0 @@
(async () =>{
//displayRoute();
//showBike()
//createDb()
//getCurrentTime()
})();

58
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);
//*/
}

90
index.html

@ -24,13 +24,6 @@
<!-- <button onclick="createlistitem()"> create route</button> -->
<ul id="list">
</ul>
</div>
@ -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
}
</script>
@ -67,84 +58,5 @@
<button onclick="showRoutes()"> Show Routes </button>
</div>
<style>
/*
*{
box-sizing: border-box;
}
body {
height: 100%;
width: 100%;
display: flex;
justify-content: center;
align-items:flex-start;
font-family: 'Roboto', sans-serif;
background: #bb753b;
overflow: hidden;
}
.panel {
width: 300px;
height: 400px;
background: #e68a43;
box-shadow: 1px 2px 3px 0px rgba(0,0,0,0.10);
border-radius: 6px;
overflow: hidden;
}
.panel-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 30px;
height: 60px;
background: rgb(241, 239, 239);
}
.title {
color: #5E6977;
font-weight: 500;
}
.panel-body {
display: flex;
height: 340px;
}
.categories {
display: flex;
flex-direction: column;
justify-content: space-between;
flex-basis: 25%;
padding: 39px 0px 41px 26px;
}
.category {
display: flex;
flex-direction: column;
}
.category span:first-child {
font-weight: 300;
font-size: 14px;
opacity: 0.6;
color: #fff;
margin-bottom: 6px;
}
.category span:last-child {
font-size: 32px;
font-weight: 300;
color: #fff;
}
.chart {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
flex-grow: 2;
position: relative;
}
.routes {
float:right ;
position: bottom;
margin-right: 20%;
}
*/
</style>
Loading…
Cancel
Save