-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
46 lines (40 loc) · 1.35 KB
/
app.py
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
from flask import Flask, render_template, request, send_file
from buscas import Buscas
from Node import nodes, edges_labels
from flask_socketio import SocketIO
import random
app = Flask(__name__)
socketio = SocketIO(cors_allowed_origins="*")
socketio.init_app(app)
busca = Buscas()
@app.route("/")
def home():
return render_template("home.html", nos=list(nodes.keys()))
@app.route("/imagem")
def imagem():
return send_file("static/files/graph.jpg", mimetype='image/gif')
@socketio.on("gerarGrafo")
def gerarGrafo(input):
configure_busca()
tipo_busca = input["busca"]
busca.initial_node = input["init_node"]
busca.finish_node = input["finish_node"]
resultado = busca[tipo_busca]
name = generate_random_names()
busca.gerar_grafico(resultado[0], name, input['use_digraph'])
socketio.emit("dado_gerado", {"nome": name, "custo": resultado[1]})
def configure_busca():
busca.nodes = nodes
busca.edges_cost = edges_labels
def generate_random_names():
name = ""
letras = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'm', 'n', 'o', 'p']
numeros = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
for x in range(10):
n = random.randint(0, 1)
if n == 0:
name += random.choice(letras)
else:
name += random.choice(numeros)
return name+".jpg"
socketio.run(app, debug=True)