diff --git a/iris_model.h5 b/iris_model.h5 new file mode 100644 index 0000000..386edca Binary files /dev/null and b/iris_model.h5 differ diff --git a/magazine/__pycache__/views.cpython-37.pyc b/magazine/__pycache__/views.cpython-37.pyc index 57eb524..faa5968 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 dfe9c57..9c714a8 100644 --- a/magazine/static/magazine/forklift.js +++ b/magazine/static/magazine/forklift.js @@ -1,68 +1,66 @@ class Forklift { - constructor(x, y) { - this.positoin = createVector(x, y); - this.speed = 5; - this.path = []; - this.currentTarget = ''; - this.targetId = 0; - this.velocity = createVector(0, 0); - this.direction = createVector(0, 0); - this.end = false; - this.currentSection = 0; - } + constructor(x, y) { + this.positoin = createVector(x, y); + this.speed = 5; + this.path = []; + this.currentTarget = ''; + this.targetId = 0; + this.velocity = createVector(0, 0); + this.direction = createVector(0, 0); + this.end = false; + this.currentSection = 0; + } - draw() { - fill(225, 255, 0); - ellipse(this.positoin.x, this.positoin.y, 20); - } + draw() { + fill(225, 255, 0); + ellipse(this.positoin.x, this.positoin.y, 20); + } - setPath(path) { - this.end = false; - this.path = path; - this.currentTarget = this.path[this.targetId]; - this.setVelocity(); - } + setPath(path) { + this.end = false; + this.path = path; + this.currentTarget = this.path[this.targetId]; + this.setVelocity(); + } - nextTarget() { - this.targetId += 1; - if (this.targetId < this.path.length) { - this.currentTarget = this.path[this.targetId]; - } else { - this.end = true; - this.targetId = 0; - } + nextTarget() { + this.targetId += 1; + if (this.targetId < this.path.length) { + this.currentTarget = this.path[this.targetId]; + } else { + this.end = true; + this.targetId = 0; } + } - targetReached() { - this.currentSection = this.currentTarget; - return this.end; - } + targetReached() { + this.currentSection = this.currentTarget; + return this.end; + } - setVelocity() { - debugger; - this.direction = this.sub(sections[this.currentTarget], this.positoin); - this.velocity = this.direction.setMag(this.speed); - } + setVelocity() { + this.direction = this.sub(sections[this.currentTarget], this.positoin); + this.velocity = this.direction.setMag(this.speed); + } - move() { - this.positoin = this.add(this.positoin, this.velocity); - if ( - Math.abs(this.positoin.x - sections[this.currentTarget].x) <= - this.speed && - Math.abs(this.positoin.y - sections[this.currentTarget].y) <= - this.speed - ) { - this.positoin = sections[this.currentTarget]; - this.nextTarget(); - this.setVelocity(); - } + move() { + this.positoin = this.add(this.positoin, this.velocity); + if ( + Math.abs(this.positoin.x - sections[this.currentTarget].x) <= + this.speed && + Math.abs(this.positoin.y - sections[this.currentTarget].y) <= this.speed + ) { + this.positoin = sections[this.currentTarget]; + this.nextTarget(); + this.setVelocity(); } + } - sub(target, pos) { - return createVector(target.x - pos.x, target.y - pos.y); - } + sub(target, pos) { + return createVector(target.x - pos.x, target.y - pos.y); + } - add(target, pos) { - return createVector(target.x + pos.x, target.y + pos.y); - } + add(target, pos) { + return createVector(target.x + pos.x, target.y + pos.y); + } } diff --git a/magazine/static/magazine/sketch.js b/magazine/static/magazine/sketch.js index 45ab43c..6ffe613 100644 --- a/magazine/static/magazine/sketch.js +++ b/magazine/static/magazine/sketch.js @@ -1,130 +1,149 @@ +const serverUrl = 'http://localhost:8000'; let sections; let roads; let packageClaim; let going = false; let forklift; -let target; - // This runs once at start function setup() { - createCanvas(600, 600).parent('canvas'); + createCanvas(600, 600).parent('canvas'); - frameRate(30); + frameRate(30); - createMagazineLayout(); + createMagazineLayout(); - select('#button').mousePressed(deliver); - target = select('#target'); - // Create a forklift instance - forklift = new Forklift(sections[0].x, sections[0].y); + select('#button').mousePressed(getIrisType); + sepalWidth = select('#sepalWidth'); + sepalLength = select('#sepalLength'); + petalWidth = select('#petalWidth'); + petalLength = select('#petalLength'); + // Create a forklift instance + forklift = new Forklift(sections[0].x, sections[0].y); } // This runs every frame function draw() { - background(64); - drawMagazine(); - forklift.draw(); - if (going) { - if (forklift.targetReached()) { - going = false; - } else { - forklift.move(); - } + background(64); + drawMagazine(); + forklift.draw(); + if (going) { + if (forklift.targetReached()) { + going = false; + } else { + forklift.move(); } + } } function drawMagazine() { - noFill(); - stroke(220); - strokeWeight(10); - // Draw all the roads in the magazine - for (let road of roads) { - line( - sections[road[0]].x, - sections[road[0]].y, - sections[road[1]].x, - sections[road[1]].y, - ); - } - noStroke(); - textAlign(CENTER, CENTER); - // Draw all sections in the magazine - for (let section of Object.keys(sections)) { - if (section === 0) { - fill(80); - rect(sections[section].x - 15, sections[section].y, 30, 30); - } else { - fill(30); - ellipse(sections[section].x, sections[section].y, 30); - fill(255); - text(section, sections[section].x, sections[section].y); - } + noFill(); + stroke(220); + strokeWeight(10); + // Draw all the roads in the magazine + for (let road of roads) { + line( + sections[road[0]].x, + sections[road[0]].y, + sections[road[1]].x, + sections[road[1]].y, + ); + } + noStroke(); + textAlign(CENTER, CENTER); + // Draw all sections in the magazine + for (let section of Object.keys(sections)) { + if (section === 0) { + fill(80); + rect(sections[section].x - 15, sections[section].y, 30, 30); + } else { + fill(30); + ellipse(sections[section].x, sections[section].y, 30); + fill(255); + text(section, sections[section].x, sections[section].y); } + } } -function deliver() { - let data = { - graph: magazineToGraph(), - start_node: forklift.currentSection, - dest_node: int(target.value()), - }; - 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 getIrisType() { + let sw = select('#sepalWidth').value(); + let sl = select('#sepalLength').value(); + let pw = select('#petalWidth').value(); + let pl = select('#petalLength').value(); + let data = { + sepalWidth: sw, + sepalLength: sl, + petalWidth: pw, + petalLength: pl, + }; + httpPost(serverUrl + '/classify', data, response => { + deliver(response); + }); +} + +function deliver(targetSection) { + let data = { + graph: magazineToGraph(), + start_node: forklift.currentSection, + dest_node: int(targetSection), + }; + console.log(data); + httpPost( + serverUrl + '/shortestPath', + data, + response => { + path = response.split('').map(Number); + forklift.currentTarget = path[0]; + forklift.setPath(path); + going = true; + }, + error => { + console.log(error); + }, + ); } function createMagazineLayout() { - unit = width / 6; + unit = width / 6; - sections = { - 0: { x: 2 * unit, y: unit }, - 1: createVector(unit, 2 * unit), - 2: createVector(unit, 3 * unit), - 3: createVector(unit, 4 * unit), - 4: createVector(3 * unit, 2 * unit), - 5: createVector(3 * unit, 3 * unit), - 6: createVector(3 * unit, 4 * unit), - }; - roads = [ - [1, 5], - [2, 3], - [0, 1], - [0, 4], - [4, 5], - [5, 6], - [3, 6], - [4, 2], - [5, 3], - ]; + sections = { + 0: { x: 2 * unit, y: unit }, + 1: createVector(unit, 2 * unit), + 2: createVector(unit, 3 * unit), + 3: createVector(unit, 4 * unit), + 4: createVector(3 * unit, 2 * unit), + 5: createVector(3 * unit, 3 * unit), + 6: createVector(3 * unit, 4 * unit), + }; + roads = [ + [1, 5], + [2, 3], + [0, 1], + [0, 4], + [4, 5], + [5, 6], + [3, 6], + [4, 2], + [5, 3], + ]; } function magazineToGraph() { - graph = {}; - for (let key of Object.keys(sections)) { - graph[key] = {}; - } - for (let road of roads) { - start = road[0]; - end = road[1]; - graph[start][end] = Math.sqrt( - Math.pow(sections[start].x - sections[end].x, 2) + - Math.pow(sections[start].y - sections[end].y, 2), - ); - graph[end][start] = Math.sqrt( - Math.pow(sections[start].x - sections[end].x, 2) + - Math.pow(sections[start].y - sections[end].y, 2), - ); - } - return graph; + graph = {}; + for (let key of Object.keys(sections)) { + graph[key] = {}; + } + for (let road of roads) { + start = road[0]; + end = road[1]; + graph[start][end] = Math.sqrt( + Math.pow(sections[start].x - sections[end].x, 2) + + Math.pow(sections[start].y - sections[end].y, 2), + ); + graph[end][start] = Math.sqrt( + Math.pow(sections[start].x - sections[end].x, 2) + + Math.pow(sections[start].y - sections[end].y, 2), + ); + } + return graph; } diff --git a/magazine/templates/magazine/index.html b/magazine/templates/magazine/index.html index dc60ca3..a1941a2 100644 --- a/magazine/templates/magazine/index.html +++ b/magazine/templates/magazine/index.html @@ -42,27 +42,21 @@
A - Cartons
-B - Barrels
-C - Plastic boxes
-D - ______
-E - ______
-F - ______
-G - ______
+1 - Setosa
+2 - Versicolor
+3 - Viginica