Skip to content

Commit cb3fb28

Browse files
committed
Finished v1. Code cleanup (PEP8 compliance).
1 parent 8ad8545 commit cb3fb28

File tree

7 files changed

+399
-350
lines changed

7 files changed

+399
-350
lines changed

app.py

Lines changed: 66 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -9,101 +9,113 @@
99
USER_NAME = 'syngnz'
1010
PASSWORD = 'inform'
1111

12-
app = Flask(__name__)
13-
app.config.from_object(__name__)
12+
APP = Flask(__name__)
13+
APP.config.from_object(__name__)
1414

1515
# Cache the results on server
16-
n_cache = []
17-
s_cache = []
16+
NODE_CACHE = []
17+
REL_CACHE = []
1818

1919

20-
@app.route('/about')
20+
@APP.route('/about')
2121
def about():
2222
return render_template('about.html')
2323

2424

25-
@app.route('/discuss')
25+
@APP.route('/discuss')
2626
def discuss():
2727
return render_template('discuss.html')
2828

2929

30-
@app.route('/build')
30+
@APP.route('/build')
3131
def build():
32-
neo.dbAddNeurons(True)
33-
neo.dbAddSynapses(False)
32+
neo.db_add_neurons(clear=True)
33+
neo.db_add_synapses(clear=False)
3434
return redirect(url_for('index'))
3535

3636

37-
@app.route('/')
37+
@APP.route('/')
3838
def index():
39-
global n_cache, s_cache
40-
n_cache = neo.neurons()
41-
s_cache = neo.synapsesD3(n_cache, 0)
42-
d = {'neurons':n_cache, 'synapses':s_cache}
43-
j = json.dumps(d)
44-
return render_template('graph.html', data=j)
39+
global NODE_CACHE, REL_CACHE
40+
NODE_CACHE = neo.neurons()
41+
REL_CACHE = neo.synapses_d3(NODE_CACHE, min_weight=0)
42+
jsn = json.dumps({'neurons':NODE_CACHE, 'synapses':REL_CACHE})
43+
return render_template('graph.html', data=jsn)
4544

4645

47-
@app.route('/_subgraph')
46+
@APP.route('/_subgraph')
4847
def subgraph():
49-
global n_cache, s_cache
50-
g1 = request.args.get('group1', "no group1", type=str)
51-
g1 = [s.strip() for s in g1.split(",")]
52-
g2 = request.args.get('group2', "no group2", type=str)
53-
g2 = [s.strip() for s in g2.split(",")]
54-
ws = request.args.get('minWeightS', 1, type=int)
55-
wj = request.args.get('minWeightJ', 1, type=int)
56-
l = request.args.get('maxLength', 2, type=int)
57-
dir = request.args.get('dir', '->', type=str)
58-
res = neo.subgraph(g1, g2, l, ws, wj, dir)
59-
n_cache = res['neurons']
60-
s_cache = res['synapses']
48+
global NODE_CACHE, REL_CACHE
49+
gr1 = request.args.get('group1', "no group1", type=str)
50+
gr1 = [s.strip() for s in gr1.split(",")]
51+
gr2 = request.args.get('group2', "no group2", type=str)
52+
gr2 = [s.strip() for s in gr2.split(",")]
53+
min_ws = request.args.get('minWeightS', 1, type=int)
54+
min_wj = request.args.get('minWeightJ', 1, type=int)
55+
max_l = request.args.get('maxLength', 2, type=int)
56+
path_dir = request.args.get('dir', '->', type=str)
57+
res = neo.subgraph(gr1, gr2, max_l, min_ws, min_wj, path_dir)
58+
NODE_CACHE = res['neurons']
59+
REL_CACHE = res['synapses']
6160
return jsonify(result=res)
6261

6362

64-
@app.route('/_expand')
63+
@APP.route('/_expand')
6564
def expand():
66-
global n_cache, s_cache
65+
global NODE_CACHE, REL_CACHE
6766
names = request.args.getlist('names[]')
68-
res = neo.allConsForSet(names)
69-
n_cache = res['neurons']
70-
s_cache = res['synapses']
67+
res = neo.all_cons_for_set(names)
68+
NODE_CACHE = res['neurons']
69+
REL_CACHE = res['synapses']
7170
return jsonify(result=res)
7271

7372

74-
@app.route('/_reset')
73+
@APP.route('/_reset')
7574
def reset():
76-
global n_cache, s_cache
77-
n_cache = neo.neurons()
78-
s_cache = neo.synapsesD3(n_cache, 0)
79-
res = {'neurons':n_cache, 'synapses':s_cache}
75+
global NODE_CACHE, REL_CACHE
76+
NODE_CACHE = neo.neurons()
77+
REL_CACHE = neo.synapses_d3(NODE_CACHE, min_weight=0)
78+
res = {'neurons':NODE_CACHE, 'synapses':REL_CACHE}
8079
return jsonify(result=res)
8180

8281

83-
@app.route('/export')
82+
@APP.route('/export', methods=["GET"])
8483
def export():
85-
nxg = netx.toNx(n_cache, s_cache)
86-
jsg = netx.toJson(nxg)
87-
resp = Response(jsg, mimetype="application/json")
84+
print request.args
85+
exp_format = request.args.get('format', "json", type=str)
86+
nxg = netx.to_netx(NODE_CACHE, REL_CACHE)
87+
88+
if "json" in exp_format:
89+
jsg = netx.to_json(nxg, exp_format)
90+
resp = Response(jsg, mimetype="application/json")
91+
elif "graphml" in exp_format:
92+
text = netx.to_graphml(nxg)
93+
resp = Response(text, mimetype="text/plain")
94+
elif "gml" in exp_format:
95+
text = netx.to_gml(nxg)
96+
resp = Response(text, mimetype="text/plain")
97+
elif "adj" in exp_format:
98+
text = netx.to_adj(nxg)
99+
resp = Response(text, mimetype="text/plain")
100+
88101
return resp
89102

90103

91-
@app.route('/sigma')
104+
@APP.route('/sigma')
92105
def sigma():
93-
ns = neo.neuronsSigma()
94-
ss = neo.synapsesSigma(ns, 2)
95-
d = {'nodes':ns, 'edges':ss}
96-
j = json.dumps(d)
97-
return render_template('sigma.html', data=j)
106+
n_sig = neo.neurons_sigma()
107+
s_sig = neo.synapses_sigma(n_sig, 2)
108+
jsn = json.dumps({'nodes':n_sig, 'edges':s_sig})
109+
return render_template('sigma.html', data=jsn)
98110

99111

100-
@app.route('/login', methods=['GET', 'POST'])
112+
@APP.route('/login', methods=['GET', 'POST'])
101113
def login():
102114
error = None
103115
if request.method == 'POST':
104-
if request.form['username'] != app.config['USER_NAME']:
116+
if request.form['username'] != APP.config['USER_NAME']:
105117
error = 'Invalid username'
106-
elif request.form['password'] != app.config['PASSWORD']:
118+
elif request.form['password'] != APP.config['PASSWORD']:
107119
error = 'Invalid password'
108120
else:
109121
session['logged_in'] = True
@@ -114,7 +126,7 @@ def login():
114126
return redirect(url_for('show_runs'))
115127

116128

117-
@app.route('/logout')
129+
@APP.route('/logout')
118130
def logout():
119131
session.pop('logged_in', None)
120132
flash('You were logged out')
@@ -124,4 +136,4 @@ def logout():
124136
# Autostart
125137
# ------------------------------------------------------------------------------
126138
if __name__ == '__main__':
127-
app.run(debug=True)
139+
APP.run(debug=True)

0 commit comments

Comments
 (0)