def computeLeague(libSNA, session): d = nx.degree(libSNA.graph) c = nx.closeness_centrality(libSNA.graph) b = nx.betweenness_centrality(libSNA.graph) ds = sorted_map(d) cs = sorted_map(c) bs = sorted_map(b) weights = [.50, .30, .20] names1 = [x[0] for x in ds[:10]] names2 = [x[0] for x in cs[:10]] names3 = [x[0] for x in bs[:10]] names = list(set(names1) | set(names2) | set(names3)) names = sorted(names, key = lambda name: (float(d[name])/ds[0][1])*weights[0] + (float(c[name])/cs[0][1])*weights[1] + (float(b[name])/bs[0][1])*weights[2], reverse = True) result = fbutils.fql( "SELECT uid, name FROM user WHERE uid IN ( " \ "SELECT uid2 FROM friend WHERE uid1 = me() )", session['access_token']) nodes = {} for node in result: nodes[str(node['uid'])] = node['name'] return [[name, nodes[name], str(d[name]), str(c[name]), str(b[name])] for name in names]
def computeLeague(libSNA, session): d = nx.degree(libSNA.graph) c = nx.closeness_centrality(libSNA.graph) b = nx.betweenness_centrality(libSNA.graph) ds = sorted_map(d) cs = sorted_map(c) bs = sorted_map(b) weights = [.50, .30, .20] names1 = [x[0] for x in ds[:10]] names2 = [x[0] for x in cs[:10]] names3 = [x[0] for x in bs[:10]] names = list(set(names1) | set(names2) | set(names3)) names = sorted(names, key=lambda name: (float(d[name]) / ds[0][1]) * weights[0] + (float(c[name]) / cs[0][1]) * weights[1] + (float(b[name]) / bs[0][1]) * weights[2], reverse=True) result = fbutils.fql( "SELECT uid, name FROM user WHERE uid IN ( " \ "SELECT uid2 FROM friend WHERE uid1 = me() )", session['access_token']) nodes = {} for node in result: nodes[str(node['uid'])] = node['name'] return [[name, nodes[name], str(d[name]), str(c[name]), str(b[name])] for name in names]
def getNodesEdges(self, session): result = fbutils.fql( "SELECT uid2 FROM friend WHERE uid1 = me()", session['access_token']) nodes = [] for node in result: nodes.append(node['uid2']) result = fbutils.fql( "SELECT uid1, uid2 FROM friend WHERE " + "uid1 IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND " + "uid2 IN (SELECT uid1 FROM friend WHERE uid2 = me())", session['access_token']); edges = [] for edge in result: edges.append([edge['uid1'], edge['uid2']]) return nodes, edges