-
Notifications
You must be signed in to change notification settings - Fork 0
/
display.py
executable file
·41 lines (34 loc) · 988 Bytes
/
display.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
#!/usr/bin/env python
from db import dbase
import sys
visitedPhDs = set([])
def formatNode(idx, name):
thesis = dbase.readFirstPhDThesis(idx)
if thesis is None:
return '[label = "%s" shape="box"]' % name
else:
return '[label = "%s\\n%s" shape="box"]' % (name, thesis[2])
def visPhD(idx, depth=1000):
if idx in visitedPhDs:
return ""
phd = dbase.readPhD(idx)
if phd is None:
print >> sys.stderr, "[Display] Failed reading", idx
return ""
advisors = dbase.getAdvisors(idx)
res = ""
visitedPhDs.add(idx)
if depth > 0:
for aID in advisors:
try:
res += "%s\n" % visPhD(aID, depth - 1)
except Exception, e:
print >> sys.stderr, "[Display] Exception occured processing %d:" % aID, e
res += "\n".join([" %d -> %d" % (idx, aID) for aID in advisors])
return res+"\n %d %s" % (idx, formatNode(idx, phd[1]))
def graphVIZ(idx):
visitedPhDs = set([])
return ("digraph Genealogy {\n"
" rankdir = BT\n"
" %s\n"
"}" % visPhD(idx)).encode("utf-8")