-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.py
More file actions
62 lines (50 loc) · 1.78 KB
/
Copy pathapp.py
File metadata and controls
62 lines (50 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from flask import Flask, request, jsonify, render_template, send_from_directory
from backend.warehouse_layout import get_simple_warehouse_layout, get_large_warehouse_layout
import json
from backend.models import WarehouseCell
import networkx as nx
import os
from flask_cors import CORS
app = Flask(__name__, static_url_path='')
CORS(app)
WAREHOUSE = {
'simple-warehouse': get_simple_warehouse_layout(),
'large-warehouse': get_large_warehouse_layout()
}
@app.route('/favicon.ico')
def favicon():
return send_from_directory(os.path.join(app.root_path, 'static'), 'favicon.ico', mimetype='image/vnd.microsoft.icon')
@app.route('/')
def homepage():
return app.send_static_file('index.html')
# @app.route('/')
# def homepage():
# return "<h1>Hello world</h1>"
@app.route('/warehouse/<warehouse_id>')
def get_warehouse(warehouse_id):
warehouse = WAREHOUSE[warehouse_id]
# blocked_nodes = warehouse
return json.dumps({
'dimensions': warehouse.dimensions,
'valid_nodes': get_all_valid_nodes(warehouse)
})
# find pick path from respective warehouse
@app.route('/<warehouse_id>/find-pick-path', methods = ['POST'])
def find_pick_path(warehouse_id):
data = request.get_json()
source = (data['source']['x'], data['source']['y'])
items = [(item['x'], item['y']) for item in data['items']]
warehouse = WAREHOUSE[warehouse_id]
path = warehouse.find_optimal_path(pick_points = items, source = source)
return json.dumps({
'path': path
})
def get_all_valid_nodes(G):
valid_nodes = []
for i in range(G.dimensions[0]):
for j in range(G.dimensions[1]):
if G.grid[i][j] == WarehouseCell.Navigable:
valid_nodes.append((i,j))
return valid_nodes
if __name__ == "__main__":
app.run(debug = True)