Пример #1
0
def createResults(field, args_array):

    ## is text search 
    if not field.lower() in ["email", "entity"]:
        text = head(args_array)    
        if text:
            tangelo.log("text search : %s" % text)        
            es = Elasticsearch()
            res = es.search(index="newman", doc_type="emails", size=1000, q=text, body= {"fields": ["_id"], "query": {"match_all": {}}})
            
            ingestESTextResults(jsonGet(['hits','hits'], res, []))
    
    node_vals = getNodeVals(field, args_array)
    colors = {k:v.get("group_id") for k,v in node_vals.iteritems()}

    for k,v in node_vals.iteritems():
        node_vals[k]["color"] = colors.get(k)
    emails = sorted(getEmails(colors, field, args_array), key=lambda x: str(x.get('datetime')))
    idx_lookup = {}
    nodes = []

    for i, o in enumerate(node_vals.iteritems()):
        k,v = o
        idx_lookup[k]=i
        #nodes.append({"name": k, "num": v.get("num"), "rank": v.get("rank"), "group": v.get("color"), "community": colors.get(v.get("comm"))})
        nodes.append({"name": k, "num": v.get("num"), "rank": v.get("rank"), "group": v.get("color"), "community": v.get("comm_id")})
    edges = getEdges(idx_lookup, field, args_array)    

    results = { 'rows': emails, 'graph': { 'nodes': nodes, 'links': edges }}

    return results
Пример #2
0
                        'name': target,
                        'community': 'n/a',
                        'idx': node_map[target]
                    })

                edges.append((node_map[src], node_map[target]))

    g = igraph.Graph(len(nodes) + 1)
    g.add_edges(edges)
    g.vs['node'] = nodes

    g = g.as_undirected(mode='collapse')
    clustering = g.community_multilevel()

    for subgraph in clustering.subgraphs():
        community_name = jsonGet(['name'], head(subgraph.vs['node']), 'n/a')
        for node in subgraph.vs['node']:
            node['community'] = community_name

    #output format
    #NODE\tCOMMUNITY
    # for node in nodes:
    #     print "{}\t{}".format(node['name'], node['community'])

    count = counter(1)
    with newman_connector() as read_cnx, newman_connector() as write_cnx:
        txid = Tx(read_cnx.conn()).next()
        print "tx: %s" % txid
        facts = Fact(write_cnx.conn(), autocommit=False)
        print "assigning communities"
        for node in nodes:
Пример #3
0
                    node_map[target] = c.next()
                    nodes.append({'name': target, 
                                  'community': 'n/a', 
                                  'idx': node_map[target] })

                edges.append((node_map[src], node_map[target]))

    g = igraph.Graph(len(nodes)+1)
    g.add_edges(edges)
    g.vs['node'] = nodes

    g = g.as_undirected(mode='collapse')
    clustering = g.community_multilevel()

    for subgraph in clustering.subgraphs():
        community_name = jsonGet(['name'], head(subgraph.vs['node']), 'n/a')
        for node in subgraph.vs['node']:
            node['community'] = community_name

    #output format 
    #NODE\tCOMMUNITY
    # for node in nodes:
    #     print "{}\t{}".format(node['name'], node['community'])

    count = counter(1)
    with newman_connector() as read_cnx, newman_connector() as write_cnx:
        txid = Tx(read_cnx.conn()).next()
        print "tx: %s" % txid
        facts = Fact(write_cnx.conn(), autocommit=False)
        print "assigning communities"
        for node in nodes: