From 3140002f94384cd188d559d38160643127f426bf Mon Sep 17 00:00:00 2001 From: naath Date: Wed, 9 Apr 2014 09:41:56 +0100 Subject: [PATCH] Oops, forgot to commit. Lots of faffing arround with graphs, graphs will be added serperately --- cgiFiles/everyPage.py | 14 ++- cgiFiles/listPeople.py | 3 +- cgiFiles/person.py | 4 +- familyTree/askQuestion.py | 171 ++++++++++++++++++++++++++++++++---- familyTree/findYear.py | 28 +++--- familyTree/notes | 9 +- familyTree/printLists.py | 8 +- familyTree/printYearBorn.py | 9 +- familyTree/tree | 108 +++++++++++------------ familyTree/tree.db | Bin 71680 -> 71680 bytes 10 files changed, 253 insertions(+), 101 deletions(-) diff --git a/cgiFiles/everyPage.py b/cgiFiles/everyPage.py index d202b61..9f2d622 100755 --- a/cgiFiles/everyPage.py +++ b/cgiFiles/everyPage.py @@ -7,6 +7,7 @@ sys.path.append('/home/naath/familyTreeProject/familyTree') import askQuestion import everyPage +cgitb.enable() def base_url(): return 'http://www.chiark.greenend.org.uk/ucgi/~naath/' @@ -19,7 +20,10 @@ def links(): print ' count how many times first names are use' print '
' print ' At what age did people have children' - + print '
' + print ' At what age did people die' + print '
' + print ' big graph' print '
' def footer(): @@ -28,6 +32,14 @@ def footer(): print 'naath' print '
' print 'Thanks to chiark for hosting this' + print '
' + print 'Information sourced from wikipedia' + print 'All errors in transcription are mine.' + print 'Reports of errors, or ideas of interesting questions to ask' + print 'my database by email to naath@chiark.greenend.org.uk' + print "(omissions of people are largely because I haven't got to them yet)." + + def title(titleNum): return 'Silly toy' diff --git a/cgiFiles/listPeople.py b/cgiFiles/listPeople.py index d0e6897..d6deedc 100755 --- a/cgiFiles/listPeople.py +++ b/cgiFiles/listPeople.py @@ -9,12 +9,13 @@ import askQuestion import everyPage [conn,form]=everyPage.top() +cgitb.enable() result = 1 if result == None: everyPage.bad() else: - printMe = askQuestion.list_people('
') + printMe = askQuestion.list_people('
') if len(printMe)<10: printMe = 'sorry, no data
' diff --git a/cgiFiles/person.py b/cgiFiles/person.py index 32d3807..fb0a08c 100755 --- a/cgiFiles/person.py +++ b/cgiFiles/person.py @@ -23,6 +23,7 @@ result = re.match('^[0-9]{1,3}$', str(ID)) if result == None: everyPage.bad() else: + printMe = askQuestion.person_info(ID,'
') if len(printMe)<10: printMe = 'sorry, no data
' @@ -31,6 +32,5 @@ else: printMe = printMe + '
' + url everyPage.good(printMe) - - + everyPage.bottom(conn) diff --git a/familyTree/askQuestion.py b/familyTree/askQuestion.py index 3c1b999..d841441 100755 --- a/familyTree/askQuestion.py +++ b/familyTree/askQuestion.py @@ -6,7 +6,6 @@ from string import Template global link_Template link_Template= Template("$text") - def run_query(s,t): c = make_cursor() return c.execute(s,t) @@ -68,22 +67,33 @@ def name_html(row,html): else: return row[0] + "," +str(row[1]) -def print_age_count(row,newLine): +def print_people(n): + if n>1: + return ' people ' + else: + return ' person ' + +def print_age_child_count(row,newLine): if newLine == '
': script = "age.py?age="+str(row[0]) link = link_Template.substitute(script = \ script, text = row[0]) - out = str(row[1]) - if row[1]>1: - out = out + ' people ' - else: - out = out + ' person ' + out = str(row[1])+print_people(row[1]) out = out + 'had children at age '+ link + newLine return out else: return print_row(row,newLine) +def print_age_death_count(row,newLine): + if newLine =='
': + script = "ageDeath.py?age="+str(row[0]) + link = link_Template.substitute(script = script,text = row[0]) + out = str(row[1])+print_people(row[1]) + out = out + "died at age " + link + newLine + return out + else: + return print_row(row,newLine) def print_name_count(row,newLine): if newLine=='
': @@ -161,6 +171,50 @@ def list_territories(newLine): out =out + terr_html(row[0],newLine) +newLine return out +def list_people_parents(): + s = "SELECT name,id"\ + +" FROM people"\ + +" ORDER BY id;" + + output = [] + for row in run_query(s,()): + t = "SELECT parentid"\ + +" FROM parents"\ + +" WHERE id = ?;" + + u = "SELECT name,id"\ + +" FROM people"\ + +" WHERE id = ?"; + + parents =[] + for r in run_query(t,(row[1],)): + parentID = r[0] + hasParent = 0 + for q in run_query(u,(r[0],)): + parents.append(q[0] + ' ' + str(q[1])) + hasParent=1 + if hasParent==0: + parents.append(r[0] + ' p' +\ + str(row[1])) + + spouses=[] + v = "SELECT name,idb"\ + +" FROM marriages LEFT JOIN people"\ + +" ON idb = id"\ + +" WHERE ida = ?" + for r in run_query(v,(row[1],)): + if r[0]!=None: + spouses.append(r[0]+ ' '+str(r[1])) + else: + spouses.append(r[1] + ' s' +\ + str(row[1])) + + + myName = row[0] + myID = str(row[1]) + output.append([myName+ ' '+ myID,parents,spouses]) + return output + def list_people(newLine): s = "SELECT name,id,bornyear"\ @@ -326,7 +380,7 @@ def count_age_at_child(newLine): out = '' for row in run_query(s,()): - out = out + print_age_count(row,newLine) + out = out + print_age_child_count(row,newLine) return out @@ -351,6 +405,27 @@ def people_had_child_at_age(age,newLine): return out +def count_age_at_death(newLine): + s = "select diedYear-bornYear as age,count(*)"\ + +" FROM people"\ + +" WHERE diedYear<>0 AND bornYear<>0"\ + +" GROUP BY age;" + out='' + for row in run_query(s,()): + out = out + print_age_death_count(row,newLine) + + return out +def people_died_at_age(age,newLine): + s = "SELECT diedYear-bornYear as age, name,ID"\ + +" FROM people"\ + +" WHERE age = ? AND bornYear<>0 AND diedYear<>0;" + t = (int(age),) + out ='' + out = 'These people died at age ' +str(age) + ' :' + for row in run_query(s,t): + out = out +newLine + out = out + name_html([row[1],row[2]],newLine) + return out def all_ancestors(personID,newLine): #find parents @@ -388,10 +463,11 @@ def all_ancestors(personID,newLine): allAncestors.append(row[1]) trackLevel.append(level) ancestors = newA - if len(ancestors)>0: - out = out+thisout - + out = out+thisout + + image = "" + out = out+newLine + image+newLine return [out, allAncestors,trackLevel] @@ -471,8 +547,10 @@ def common_ancestors(IDA, IDB,newLine): +" WHERE id=?" out = out + newLine + 'Most Recent Common Ancestors:' + newLine + mrca = [] for a in indexA: t = (common[a],) + mrca.append(common[a]) out = out + print_tagged_query('',s,t,newLine) if a!=indexA[-1]: out = out + 'and' + newLine @@ -502,6 +580,15 @@ def common_ancestors(IDA, IDB,newLine): related = relationship(al,bl,names) out = out+newLine + related + + image = "" + + + + out = out+newLine + image+newLine + return [out,common,related] def relationship(level1, level2,names): @@ -598,9 +685,11 @@ def person_info(personID,newLine): for row in run_query(s,t): output = output + 'ID: '+str(row[0]) +newLine output = output + print_tagged_name('Name',[row[1], row[0]],newLine) +newLine + name = row[1] output = output + 'Born: '+row[3] + newLine bornYear = row[4] - output = output + 'Died: '+row[5] + newLine + output = output + 'Died: '+row[5] + ", aged " \ + +str(row[6]-row[4]) +newLine s = "SELECT * FROM styles WHERE ID = ?" for row in run_query(s,t): @@ -635,15 +724,27 @@ def person_info(personID,newLine): +" parents LEFT JOIN people"\ +" ON parents.parentID = people.ID"\ +" WHERE parents.ID = ?" + + parents =[] for row in run_query(s,t): output = output + print_tagged_name('Parent',row,newLine) + if row[0]!=None: + parents.append(row[0] + ' ' + row[1]) + else: + parents.append(row[1] + ' p' + personID) #find spouses s = "SELECT people.NAME, marriages.IDb from"\ +" marriages LEFT JOIN people"\ +" ON people.ID = marriages.IDb"\ - +" WHERE marriages.IDa = ?" + +" WHERE marriages.IDa = ?"\ + +" ORDER BY IDb;" + spouses = [] for row in run_query(s,t): + if row[0]!=None: + spouses.append(row[0] + ' '+str(row[1])) + else: + spouses.append(row[1] + ' s' + personID) output = output + newLine output = output + print_tagged_name('Spouse',row,newLine) output = output + relationship_html(personID,row[1],newLine) @@ -651,8 +752,13 @@ def person_info(personID,newLine): s = "SELECT people.NAME, marriages.IDa from"\ +" marriages LEFT JOIN people"\ +" ON people.ID = marriages.IDa"\ - +" WHERE marriages.IDb = ?" + +" WHERE marriages.IDb = ?"\ + +" ORDER BY IDa;" for row in run_query(s,t): + if row[0]!=None: + spouses.append(row[0] + ' '+str(row[1])) + else: + spouses.append(row[1] + ' s' + personID) output = output + newLine output = output + print_tagged_name('Spouse',row,newLine) output = output + relationship_html(personID,row[1],newLine) @@ -666,26 +772,55 @@ def person_info(personID,newLine): +" WHERE parents.parentID = ?"\ +" ORDER BY people.bornYear;" + children = [] + ops =[] for row in run_query(s,t): output = output + print_tagged_name('Child',row,newLine) - + children.append(row[0] + ' ' + str(row[1])) + #find children's other parent u = "Select people.NAME, parents.parentID FROM"\ - +" parents LEFT JOIN people"\ + +" parents INNER JOIN people"\ +" ON people.ID = parents.parentID"\ - +" WHERE parents.ID = ? AND parents.parentID <> ?" + +" WHERE parents.ID = ? AND parents.parentID <>?;" ids = (row[1],t[0]) + op = 0 for r in run_query(u,ids): output = output + print_tagged_name('With',r,newLine) + op = 1 + ops.append(r[0] + ' ' + str(r[1])) + if op==0: + ops.append('?' + ' s' + personID) #age when child born if row[2] !=0 and bornYear != 0: age = row[2]-bornYear output = output[:-4] + " at the age of "+str(age) + newLine - output = output + newLine + + Self = name +' ' + str(personID) + + image = "smallGraph.py?Self="+Self + for p in parents: + image = image + '&p='+p + for c in children: + image = image + '&c='+c + for op in ops: + if op !=None: + image = image + '&op='+op + for s in spouses: + if s !=None: + image = image + '&s='+str(s) + + image = image.replace(' ','%20') + image ="uB?DKRjYU* zF&&ecy16at#CEJ>nzNNZk&nuy4K(-fwNh}@R15Jgy?F;yabF2d4Up2E*WSc>H;yeC3ZEJxv85t3q4 z6n-jtLsHG7_>KrkwQPmAL`a&?QaCPxa`9w^*F{iXG*jVK5tJ95r0~x|NQDfA9|$3j zo2c-D(50UV3jZK<=_g&`c@dPlX$r@L9-LshxtF|f?xF6srS0)}n`Wk}Z|8(AmuU)r zCv++4QuvMtNGB-@Pm6$b;#7D-1ms$W!sEIj&t!$ibQNb(cvLs!wNT;fx*^3t;cL1P z&{XW3VMLc%-K1U)>#?x5QPGed3u@n2bV!fs+6F~~Ld3N7iVo`0X!<&)d^qrMPkeb- zPlxtB^?sio4O-*=7z+`#ON+LrWd~waMkvS!9f4KL$vT!MbM2`|G6h+1Vkew!Lz?#2>NAr)GG-%*lUrH5i+=b03? z{X4Iu_$z_m;UDv3?5At=5+x{rH}NoT!di5|G3bO!yKJ{fsk0Mq)bo^xy{A0ADqvLU zVI!7O?M$_=?U{}b%m;pz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