From: naath Date: Wed, 9 Apr 2014 08:41:56 +0000 (+0100) Subject: Oops, forgot to commit. Lots of faffing arround with graphs, graphs will be added... X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~naath/git?a=commitdiff_plain;h=3140002f94384cd188d559d38160643127f426bf;p=familyTree.git Oops, forgot to commit. Lots of faffing arround with graphs, graphs will be added serperately --- 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 ="