def get_path(): start = time.time() src = flask.request.args['source'] tgt = flask.request.args['target'] s = get_matching_node(src,key_id,data_dict) t = get_matching_node(tgt,key_id,data_dict) path = nx.shortest_path(G1,int(s),int(t)) g = nx.Graph() g.add_path(path) links = get_links(g,'path') r = {'data':links} return json.dumps(r)
def get_neighbors(): start = time.time() node = flask.request.args['node'] node = get_matching_node(node,key_id,data_dict) NodeVec = snap.TIntV() n_nodes = snap.GetNodesAtHop(G,int(node),1,NodeVec,False) nodes = [item for item in NodeVec] l = [] for n in nodes: x1 = data_dict[str(id_key[str(node)])] x2 = data_dict[str(id_key[str(n)])] l.append({'source': x1[1]+'('+str(x1[0])+')', 'target':x2[1]+'('+str(x2[0])+')'}) r = {'data':l} return json.dumps(r)