diff --git a/magazine/__pycache__/views.cpython-37.pyc b/magazine/__pycache__/views.cpython-37.pyc index 0013882..71fc264 100644 Binary files a/magazine/__pycache__/views.cpython-37.pyc and b/magazine/__pycache__/views.cpython-37.pyc differ diff --git a/magazine/static/magazine/forklift.js b/magazine/static/magazine/forklift.js index fe59d78..78d71ce 100644 --- a/magazine/static/magazine/forklift.js +++ b/magazine/static/magazine/forklift.js @@ -35,16 +35,16 @@ class Forklift { } setVelocity() { - this.direction = p5.Vector.sub( + p5.Vector.sub( sections[this.currentTarget], - this.positoin + this.positoin, + this.direction ); this.velocity = this.direction.setMag(this.speed); } move() { this.positoin = p5.Vector.add(this.positoin, this.velocity); - debugger; if ( Math.abs(this.positoin.x - sections[this.currentTarget].x) <= this.speed && diff --git a/magazine/static/magazine/sketch.js b/magazine/static/magazine/sketch.js index 7df03fd..d2c8a9d 100644 --- a/magazine/static/magazine/sketch.js +++ b/magazine/static/magazine/sketch.js @@ -4,6 +4,8 @@ let packageClaim; let going = false; let forklift; +let target; + // This runs once at start function setup() { createCanvas(500, 500).parent('canvas'); @@ -13,9 +15,9 @@ function setup() { createMagazineLayout(); select('#button').mousePressed(deliver); + target = select('#target'); // Create a forklift instance forklift = new Forklift(sections[0].x, sections[0].y); - console.log(magazineToGraph()); } // This runs every frame @@ -62,9 +64,25 @@ function drawMagazine() { } function deliver() { - path = [2, 1, 5, 4]; - forklift.setPath(path); - going = true; + let data = { + graph: magazineToGraph(), + start_node: 0, + dest_node: int(target.value()) + }; + console.log(data); + httpPost( + 'http://localhost:8000/shortestPath', + data, + response => { + path = response.split('').map(Number); + forklift.currentTarget = path[0]; + forklift.setPath(path); + going = true; + }, + error => { + console.log(error); + } + ); } function createMagazineLayout() { diff --git a/magazine/templates/magazine/index.html b/magazine/templates/magazine/index.html index 6136c2a..edd6aab 100644 --- a/magazine/templates/magazine/index.html +++ b/magazine/templates/magazine/index.html @@ -1,7 +1,7 @@ {% load static %} - + @@ -59,6 +59,8 @@ Hard Soft + +
diff --git a/magazine/views.py b/magazine/views.py index 73d1cb9..30bba36 100644 --- a/magazine/views.py +++ b/magazine/views.py @@ -20,6 +20,7 @@ def classify(request): @csrf_exempt def shortestPath(request): loaded_request = json.load(request) + print(loaded_request) graph = loaded_request["graph"] graph = {int(k): v for k, v in graph.items()} @@ -55,7 +56,7 @@ def shortestPath(request): for node in graph: current = node - p = [current + 1] + p = [current] while current != start_node: p.append(predecessor[current]) current = predecessor[current]