Connect website to shortestPath endpoint
This commit is contained in:
parent
0521035af3
commit
e5e8669663
Binary file not shown.
@ -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 &&
|
||||
|
@ -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];
|
||||
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() {
|
||||
|
@ -1,7 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
<head>
|
||||
{% load static %}
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.3/p5.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.3/p5.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.3/addons/p5.dom.min.js"></script>
|
||||
<script src="{% static 'magazine/forklift.js' %}"></script>
|
||||
<script src="{% static 'magazine/sketch.js' %}"></script>
|
||||
@ -59,6 +59,8 @@
|
||||
<input type="radio" name="material"> Hard
|
||||
<input type="radio" name="material"> Soft
|
||||
</div>
|
||||
<label for="target">Target</label>
|
||||
<input type="number" id="target" name="target">
|
||||
<button id="button">Send Package</button>
|
||||
</div>
|
||||
<div id="canvas" style="margin: 10px;"></div>
|
||||
|
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user