#!/usr/bin/python
import cgi
-import cgitb
-cgitb.enable()
+#import cgitb
+#cgitb.enable()
import sys
sys.path.append('/home/naath/familyTreeProject/familyTree')
import make_dot as d
import askQuestion as aQ
+import graphQuestions as gQ
-def find_oneside_path(ID,start,stop):
- global myP
- global myC
- start = start + 1
- if start == stop+1:
- return
- [parents, parentIDs,parentNames] = aQ.find_parents(ID)
-
- for i in parentIDs:
- myP.append(i)
- myC.append(ID)
-
- for i in range(len(parents)):
- if parentIDs[i]!=0:
- newID = parentIDs[i]
- find_oneside_path(newID,start,stop)
-
-def find_path(ID,ID2,LA,LB):
- global myP
- global myC
-
- myP = []
- myC = []
- find_oneside_path(ID,0,int(LA))
- aP = myP + [ID]
- aC = myC + [ID]
- myP = []
- myC = []
- find_oneside_path(ID2,0,int(LB))
- bP = myP + [ID2]
- bC = myC +[ID2]
-
- z = set([0])
- cA = set(aP).intersection(set(bP))
- cA = cA.difference(z)
-
- for a in cA:
- i = aP.index(a)
- c = aC[i]
-
- while c!=ID:
-
- [parents, parentIDs,parentNames] = aQ.find_parents(c)
- s = aQ.find_person(c)[0]
-
- d.add_marriage(parents[0],parents[1],[s],1)
-
-
- i = aP.index(c)
- c = aC[i]
+def make_graph(ID,ID2):
+ d.start_dot(8)
- [parents, parentIDs,parentNames] = aQ.find_parents(c)
- s = aQ.find_person(c)[0]
- d.add_marriage(parents[0],parents[1],[s],1)
+ mrca,otherRCA,lA,lB = gQ.relationship(ID,ID2)
- for a in cA:
- i = bP.index(a)
- c = bC[i]
+ nodes = gQ.join_up([ID,ID2],mrca+otherRCA)
+
- while c!=ID2:
- [parents, parentIDs,parentNames] = aQ.find_parents(c)
- s = aQ.find_person(c)[0]
+ for node in nodes:
+ [Self, selfID, selfName] = aQ.find_person(node)
- d.add_marriage(parents[0],parents[1],[s],1)
- i = bP.index(c)
- c = bC[i]
- [parents, parentIDs,parentNames] = aQ.find_parents(c)
- s = aQ.find_person(c)[0]
+ if node==ID or node==ID2 or node in mrca or node in otherRCA:
+ d.add_highlight(Self)
- d.add_marriage(parents[0],parents[1],[s],1)
+ [ps,pIDs,pNames] = aQ.find_parents(node)
+ if node not in mrca+otherRCA:
+ d.add_marriage(ps[0],ps[1],[Self],1)
+ elif (pIDs[0] in mrca+otherRCA) or (pIDs[1] in mrca+otherRCA):
+ d.add_marriage(ps[0],ps[1],[Self],1)
-def make_graph(ID,ID2,LA,LB):
- d.start_dot(8)
- done = 0
- for tID in [ID, ID2]:
- [Self, selfID, selfName] = aQ.find_person(tID)
- d.add_highlight(Self)
- find_path(ID,ID2,LA,LB)
+ if web==0:
+ return
+ d.create_dot()
d.add_subgraphs()
d.end_dot()
d.render_dot()
aQ.close(conn)
-form = cgi.FieldStorage()
+global web
+global maxLevel
+web = 1
+if web == 1:
+ form = cgi.FieldStorage()
-ID = form.getvalue('id')
-ID2 = form.getvalue('id2')
-LA = form.getvalue('LA')
-LB = form.getvalue('LB')
+ ID = int(form.getvalue('id'))
+ ID2 = int(form.getvalue('id2'))
+ maxLevel = int(int(form.getvalue('mL')))
+else:
+ ID = 60
+ ID2 = 226
+ maxLevel = 3
conn = aQ.connect()
-make_graph(ID,ID2,LA,LB)
-aQ.close(conn)
+make_graph(ID,ID2)
+aQ.close()