-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.py
213 lines (186 loc) · 9.67 KB
/
manage.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
import os, json
from flask import Flask, request, render_template, jsonify
from lib.GraphManageEngine import GraphManage
GM_DIR = r"./static/database/graphDB"
if (not GM_DIR is None) and not os.path.exists(GM_DIR):
os.mkdir(GM_DIR)
GM = GraphManage(dir_path=GM_DIR)
app = Flask(__name__, template_folder="./templates", static_folder="./static", static_url_path='/static')
app.jinja_env.auto_reload = True
app.config['TEMPLATES_AUTO_RELOAD'] = True
app.jinja_env.variable_start_string = '||<-EL PSY CONGROO->||'
app.jinja_env.variable_end_string = '||<-EL PSY CONGROO->||'
@ app.route('/graph-interface/', methods=['GET','POST'])
def graph_interface_init():
return render_template("graph-interface.html")
@ app.route('/graph-interface/save-graph', methods=['GET','POST'])
def graph_interface_graph_save():
GM.save()
return ""
@ app.route('/graph-interface/flush-graph', methods=['GET','POST'])
def graph_interface_graph_flush():
GM.flushdb()
return jsonify({"nodes": [], "edges": []})
@ app.route('/graph-interface/load-graph', methods=['GET','POST'])
def graph_interface_graph_init():
## TODO - reload step
# struct = {}
# GraphManage.restart(nodes=struct.get("nodes", []), edges=struct.get("edges", []))
GM.load()
names = json.loads(request.form.get("names") or "[]")
node_types = json.loads(request.form.get("nodeTypes") or "[]")
conn_types = json.loads(request.form.get("connTypes") or "[]")
mode = str(request.form.get("mode") or "bi")
n = int(request.form.get("n") or 5)
nodes, edges = GM.get_n_connect_map(names=names,
conn_types=conn_types,
node_types=node_types,
name_typ="uuid",
mode=mode, n=n)
return jsonify({"nodes": nodes, "edges": edges})
@ app.route('/graph-interface/change-query', methods=['GET','POST'])
def graph_interface_change_query():
names = json.loads(request.form.get("names") or "[]")
conn_types = json.loads(request.form.get("connTypes") or "[]")
node_types = json.loads(request.form.get("nodeTypes") or "[]")
mode = str(request.form.get("mode") or "bi")
n = int(request.form.get("n") or 5)
nodes, edges = GM.get_n_connect_map(names=names,
conn_types=conn_types,
node_types=node_types,
name_typ="uuid",
mode=mode, n=n)
return jsonify({"nodes": nodes, "edges": edges})
@ app.route('/graph-interface/add-edge', methods=['GET','POST'])
def graph_interface_add_edge():
edge = json.loads(request.form.get("edge") or "{}")
old_type = request.form.get("oldType")
if old_type:
GM.edit_edge(edge, old_type=old_type)
else:
GM.add_edge(edge)
names = json.loads(request.form.get("names") or "[]")
conn_types = json.loads(request.form.get("connTypes") or "[]")
node_types = json.loads(request.form.get("nodeTypes") or "[]")
mode = str(request.form.get("mode") or "bi")
n = int(request.form.get("n") or 5)
nodes, edges = GM.get_n_connect_map(names=names,
conn_types=conn_types,
node_types=node_types,
name_typ="uuid",
mode=mode, n=n)
return jsonify({"nodes": nodes, "edges": edges})
@ app.route('/graph-interface/del-edge', methods=['GET','POST'])
def graph_interface_del_edge():
edge = json.loads(request.form.get("edge") or "{}")
GM.del_edge(edge)
names = json.loads(request.form.get("names") or "[]")
conn_types = json.loads(request.form.get("connTypes") or "[]")
node_types = json.loads(request.form.get("nodeTypes") or "[]")
mode = str(request.form.get("mode") or "bi")
n = int(request.form.get("n") or 5)
nodes, edges = GM.get_n_connect_map(names=names,
conn_types=conn_types,
node_types=node_types,
name_typ="uuid",
mode=mode, n=n)
return jsonify({"nodes": nodes, "edges": edges})
@ app.route('/graph-interface/edit-edge', methods=['GET','POST'])
def graph_interface_edit_edge():
edge = json.loads(request.form.get("edge") or "{}")
old_type = request.form.get("oldType")
GM.edit_edge(edge, old_type)
old_type = json.loads(request.form.get("oldType") or "{}")
names = json.loads(request.form.get("names") or "[]")
conn_types = json.loads(request.form.get("connTypes") or "[]")
node_types = json.loads(request.form.get("nodeTypes") or "[]")
mode = str(request.form.get("mode") or "bi")
n = int(request.form.get("n") or 5)
nodes, edges = GM.get_n_connect_map(names=names,
conn_types=conn_types,
node_types=node_types,
name_typ="uuid",
mode=mode, n=n)
return jsonify({"nodes": nodes, "edges": edges})
@ app.route('/graph-interface/add-node', methods=['GET','POST'])
def graph_interface_add_node():
node = json.loads(request.form.get("node") or "{}")
GM.add_node(node)
names = json.loads(request.form.get("names") or "[]")
conn_types = json.loads(request.form.get("connTypes") or "[]")
node_types = json.loads(request.form.get("nodeTypes") or "[]")
mode = str(request.form.get("mode") or "bi")
n = int(request.form.get("n") or 5)
nodes, edges = GM.get_n_connect_map(names=names,
conn_types=conn_types,
node_types=node_types,
name_typ="uuid",
mode=mode, n=n)
return jsonify({"nodes": nodes, "edges": edges})
@ app.route('/graph-interface/fuse-node', methods=['GET','POST'])
def graph_interface_fuse_node():
node = json.loads(request.form.get("node") or "{}")
targ_uid = request.form.get("targ_uid") or ""
GM.fuse_node(node, targ_uid)
names = json.loads(request.form.get("names") or "[]")
conn_types = json.loads(request.form.get("connTypes") or "[]")
node_types = json.loads(request.form.get("nodeTypes") or "[]")
mode = str(request.form.get("mode") or "bi")
n = int(request.form.get("n") or 5)
nodes, edges = GM.get_n_connect_map(names=names,
conn_types=conn_types,
node_types=node_types,
name_typ="uuid",
mode=mode, n=n)
return jsonify({"nodes": nodes, "edges": edges})
@ app.route('/graph-interface/del-node', methods=['GET','POST'])
def graph_interface_del_node():
node = json.loads(request.form.get("node") or "{}")
GM.del_node(node)
names = json.loads(request.form.get("names") or "[]")
conn_types = json.loads(request.form.get("connTypes") or "[]")
node_types = json.loads(request.form.get("nodeTypes") or "[]")
mode = str(request.form.get("mode") or "bi")
n = int(request.form.get("n") or 5)
nodes, edges = GM.get_n_connect_map(names=names,
conn_types=conn_types,
node_types=node_types,
name_typ="uuid",
mode=mode, n=n)
return jsonify({"nodes": nodes, "edges": edges})
@ app.route('/graph-interface/edit-node', methods=['GET','POST'])
def graph_interface_edit_node():
node = json.loads(request.form.get("node") or "{}")
GM.edit_node(node)
old_type = json.loads(request.form.get("oldType") or "{}")
names = json.loads(request.form.get("names") or "[]")
conn_types = json.loads(request.form.get("connTypes") or "[]")
node_types = json.loads(request.form.get("nodeTypes") or "[]")
mode = str(request.form.get("mode") or "bi")
n = int(request.form.get("n") or 5)
nodes, edges = GM.get_n_connect_map(names=names,
conn_types=conn_types,
node_types=node_types,
name_typ="uuid",
mode=mode, n=n)
return jsonify({"nodes": nodes, "edges": edges})
@ app.route('/graph-interface/get-node-info', methods=['GET','POST'])
def graph_interface_get_node_info():
node_uid = request.form.get("nodeUid") or ""
res = GM.get_node_info(node_uid)
return jsonify(res)
@ app.route('/graph-interface/get-edge-info', methods=['GET','POST'])
def graph_interface_get_edge_info():
srcUid = request.form.get("srcUid") or ""
trgUid = request.form.get("trgUid") or ""
conn_type = request.form.get("connType") or ""
res = GM.get_edge_info(srcUid, trgUid, conn_type)
return jsonify(res)
@ app.route("/graph-interface/re-match-name", methods=['GET','POST'])
def graph_interface_get_match_name():
query = request.form.get("query") or ""
nlimit = int(request.form.get("nlimit") or 20)
res = GM.get_match_name(query, nlimit)
return jsonify(res)
if __name__ == "__main__":
app.run(host="127.0.0.1", port=8090)