chiark / gitweb /
list age at birth of children
[familyTree.git] / familyTree / askQuestion.py
index df1d95efcf065b6b0a5594ee9df4733d7efcff0c..f5cfa244551164a44f69d6fcb43f45fcb4332fda 100755 (executable)
@@ -150,9 +150,61 @@ def list_people(newLine):
                        century = row[2]/100 + 1
                        out = out +newLine+ 'born in ' 
 
-                       out = out +ordinal_numbers(century) + ' century:' + newLine
+                       out = out +ordinal_numbers(century) \
+                               + ' century:' + newLine
 
                out = out + name_html(row,newLine) +newLine
+
+               if row[2] == 0: #unknown year
+
+                       t = (row[1],) #person ID
+
+
+                       #died
+                       u = "SELECT diedyear FROM people WHERE ID = ?;"
+
+                       bornAfter = 0
+                       for r in run_query(u,t):
+                               if r[0] !=0:
+                                       out = out + "died: "\
+                                        + str(r[0]) + newLine
+                                       bornAfter = r[0] -100
+
+                       #find children
+                       u = "Select people.bornYear from"\
+                               +" people INNER JOIN parents"\
+                               +" ON people.ID = parents.ID"\
+                               +" WHERE parents.parentID = ?"\
+                               + " ORDER BY people.bornYear;"
+                       
+                       hadChild=[]
+                       
+                       for r in run_query(u,t):
+                               if r[0] != 0:
+                                       hadChild.append(r[0])
+                       
+                       bornBefore = 0
+                       if len(hadChild)!=0:
+                               out = out + "had children in: "
+                               for c in hadChild:
+                                       out = out + str(c) + ','
+                               out = out[:-1] + newLine
+
+                               bornBefore = hadChild[0]-12
+                               if bornAfter==0:
+                                       bornAfter = hadChild[0]-100
+                       
+                       if bornAfter!=0:
+                               if bornBefore == 0: 
+                                       out = out + "probably born "\
+                                               +"after " + str(bornAfter)
+                               else:
+                                       out = out + "probably born "\
+                                               +"betwen " + str(bornAfter)\
+                                               +" and " + str(bornBefore)
+                               out = out + newLine
+
+
                year = row[2]
        return out
 
@@ -205,6 +257,19 @@ def count_death_month(newLine):
 
         return out
 
+def count_age_at_child(newLine):
+
+       s = "select p1.bornYear - p2.bornYear as age, count(*)"\
+               +" FROM"\
+               +" parents INNER JOIN people p1"\
+               +" ON parents.ID = p1.ID"\
+               +" INNER JOIN people p2"\
+               +" ON parents.parentID = p2.ID"\
+               +" WHERE p1.bornYear <> 0 and p2.bornYear<>0"\
+               +" GROUP BY age;"
+
+       out = print_query(s,(),newLine)
+       return out
 
 def all_ancestors(personID,newLine):
        #find parents
@@ -451,6 +516,7 @@ def person_info(personID,newLine):
                output = output + 'ID: '+str(row[0]) +newLine
                output = output + print_tagged_name('Name',[row[1], row[0]],newLine) +newLine
                output = output + 'Born: '+row[3] + newLine
+               bornYear = row[4]
                output = output + 'Died: '+row[5] + newLine
 
        s = "SELECT * FROM styles WHERE ID = ?"
@@ -511,10 +577,11 @@ def person_info(personID,newLine):
        output = output + newLine
 
        #find children
-       s = "Select people.NAME, people.ID from"\
-               +" people INNER JOIN parents"\
+       s = "Select people.NAME, people.ID ,people.bornYear"\
+               +" FROM people INNER JOIN parents"\
                +" ON people.ID = parents.ID"\
-               +" WHERE parents.parentID = ?"
+               +" WHERE parents.parentID = ?"\
+               +" ORDER BY people.bornYear;"
 
        for row in run_query(s,t):
                output = output  + print_tagged_name('Child',row,newLine)
@@ -527,8 +594,12 @@ def person_info(personID,newLine):
 
                ids = (row[1],t[0])
 
-               for row in run_query(u,ids):
-                       output = output + print_tagged_name('With',row,newLine)
+               for r in run_query(u,ids):
+                       output = output + print_tagged_name('With',r,newLine)
+
+               #age when child born
+               age = row[2]-bornYear
+               output = output[:-4] + " at the age of "+str(age) + newLine
 
        output = output + newLine