-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdb_graph.py
executable file
·78 lines (54 loc) · 1.9 KB
/
db_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
77
78
#!/usr/bin/env python
from gh.connect import Connect
import gh
from GephiStreamer import Node, Edge, GephiStreamerManager
from random import choice
def display_graph(t, nodes, edges):
if nodes != None:
print "*** Graphing Nodes"
for n in nodes:
node_temp = Node(n._id)
properties = n.map()
for key in properties:
node_temp.property[key] = properties[key]
node_temp.property["colour"] = node_temp.property["color"]
node_temp.property["label"] = node_temp.property["name"]
t.add_node(node_temp)
if edges != None:
print "*** Graphing Edges"
for e in edges:
src = e._outV
dst = e._inV
edge_temp = Edge(src, dst, directed=True)
properties = e.map()
for key in properties:
edge_temp.property[key] = properties[key]
t.add_edge(edge_temp)
t.commit()
def display_graph_from_list(t, l=None):
if l == None:
return
for element in l:
if element["_type"] == "vertex":
node_temp = Node(element["_id"])
for key in element:
node_temp.property[key] = element[key]
node_temp.property["label"] = node_temp.property["name"]
node_temp.property["colour"] = node_temp.property["color"]
t.add_node(node_temp)
elif element["_type"] == "edge":
src = element["_outV"]
dst = element["_inV"]
edge_temp = Edge(src, dst, directed=True)
for key in element:
edge_temp.property[key] = element[key]
t.add_edge(edge_temp)
t.commit()
if __name__ == "__main__":
g = Connect()
t = GephiStreamerManager()
print "Getting nodes..."
nodes = g.V
print "Getting edges..."
edges = g.E
display_graph(t, g.V, g.E)