forked from woj-ciech/Danger-zone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.py
76 lines (55 loc) · 1.75 KB
/
graph.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import matplotlib.pyplot as plt
import networkx as nx
from elasticsearch import Elasticsearch
# test = collections.defaultdict(dict)
# test['000.000.000.000'] = {'ip' : ['[email protected]', '[email protected]']}
# test['000.000.000.000'] = {'email': ['xx@x', 'zz@z']}
# test = {'000.000.000.000': {'ip' : ['[email protected]', '[email protected]']}, {'email': ['xx@x', 'zz@z']}}
test = {'000.000.000.000': {'ip': ['[email protected]', '[email protected]']}}
test['000.000.000.000'].update({'email': {'xx@x': 'test', 'zzz@z': 'kupa3'}})
# graph = defaultdict(list)
# def addEdge(graph,u,v):
# graph[u].append(v)
#
# def generate_edges(graph):
# edges = []
#
# # for each node in graph
# for node in graph:
#
# # for each neighbour node of a single node
# for neighbour in graph[node]:
# # if edge exists then append
# edges.append((node, neighbour))
# return edges
def graf():
g = nx.Graph()
g.add_nodes_from(test.keys())
for k, v in test.items():
for i, j in v.items():
g.add_edges_from([(k, t) for t in j], color='skyblue')
if isinstance(j, dict):
for q, w in j.items():
g.add_edge(q, w, color='orange')
#edge_colors = [e[2]['color'] for e in g.edges(data=True)]
print g.edges
nx.draw(g, with_labels=True)
plt.show()
def elast():
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
res = es.index(index='b', doc_type='a', id=2, body=test)
print res
a = ["1"]
b = ['4', '5', '6']
c = ['7', '8', '9']
G = nx.Graph()
for i in a:
G.add_node(i)
for j in b:
G.add_edge(i, j)
for k in c:
G.add_edge(j, k)
G.add_edge(i, "kupa")
# G.add_nodes_from(b)
nx.draw(G, with_labels=True)
plt.show()