def getLibSNA(self, session):
     network = libsna.getusernetwork(self.request.get('id', None))
     libSNA = libsna.SocialNetwork()
     
     if network.getnodes() == None or network.getedges() == None: return None
     else: libSNA.loadGraph(nodes=network.getnodes(), edges=network.getedges())
     
     return libSNA
Esempio n. 2
0
    def getLibSNA(self, session):
        network = libsna.getusernetwork(self.request.get('id', None))
        libSNA = libsna.SocialNetwork()

        if network.getnodes() == None or network.getedges() == None:
            return None
        else:
            libSNA.loadGraph(nodes=network.getnodes(),
                             edges=network.getedges())

        return libSNA
def getLibSNA(self, session):
    uid = self.request.get('id', None)
    if uid == None: uid = self.request.get('uid', None)
    
    if uid: network = libsna.getusernetwork(uid)
    else: network = libsna.getusernetwork(uid)
    libSNA = libsna.SocialNetwork()
    
    lastMonth = datetime.datetime.today() - datetime.timedelta(30)
    if network.updated_time <  lastMonth or network.getnodes() == None or network.getedges() == None:
        logging.info("Reading network from Facebook.")
        nodes, edges = getNodesEdges(self, session)
        libSNA.loadGraph(nodes=nodes, edges=edges)

        h = hashlib.sha1()
        h.update("%s - %s" % (libSNA.graph.nodes(), libSNA.graph.edges()))
        
        network.networkhash = h.hexdigest()
        network.setnodes(str(nodes))
        network.setedges(str(edges))
        network.setleague(None)
        network.put()
    else:
        libSNA.loadGraph(nodes=network.getnodes(), edges=network.getedges())
    
    logging.info("nodes:%s" %libSNA.graph.number_of_nodes())
    
    cache = {}
    cache['networkhash'] = network.networkhash
    cache['uid'] = uid
    libSNA.cache = cache
        
    if network.getleague() == None:
        logging.info('Computation of network league sent to backend backend-indexes.')
        taskqueue.add(url='/networkleague', params={'id': uid,
                                                    'backend': True,
                                                    'code': self.request.get('code', None),
                                                    'access_token': session['access_token']},
                      queue_name='indexes-queue', method='POST', target='backend-indexes')
    
    return libSNA