Fix for #2303: plugins/Det*Report.py use an outdated method of computing ages. This fix brings it up to date, but needs some additional work once date spans can fully repr themselves.

svn: r11549
This commit is contained in:
Doug Blank 2008-12-31 14:49:24 +00:00
parent 7d1f63341a
commit 6d2cc418e4
4 changed files with 44 additions and 77 deletions

View File

@ -2351,7 +2351,7 @@ def born_str(database, person, person_name=None, verbose=True,
#
#-------------------------------------------------------------------------
def died_str(database, person, person_name=None, verbose=True,
empty_date="", empty_place="", age=None, age_units=0):
empty_date="", empty_place="", span=None):
"""
Write obit sentence.
FIRSTNAME died on Date
@ -2391,6 +2391,28 @@ def died_str(database, person, person_name=None, verbose=True,
bdate, bplace, bdate_full, bdate_mod, ddate, dplace, ddate_full, ddate_mod = \
get_birth_death_strings(database, person, empty_date, empty_place)
# TODO: fixme to let date format itself
if span and span.is_valid():
YEARS = 1
MONTHS = 2
DAYS = 3
if span[0] != 0:
age = span[0]
age_units = YEARS
elif span[1] != 0:
age = span[1]
age_units = MONTHS
elif span[2] != 0:
age = span[2]
age_units = DAYS
else:
age = 0
age_units = 0
else:
age = 0
age_units = 0
# end of todo ----------------------------
value_map = {
'name' : person_name,
'unknown_gender_name' : person_name,
@ -2399,7 +2421,7 @@ def died_str(database, person, person_name=None, verbose=True,
'death_date' : ddate,
'modified_date' : ddate,
'death_place' : dplace,
'age' : age ,
'age' : age,
'month_year' : ddate,
}
@ -2772,22 +2794,8 @@ def old_calc_age(database, person):
"""
Calculate age.
Returns a tuple (age, units) where units is an integer representing
time units:
no age info: 0
years: 1
months: 2
days: 3
Returns a date difference span.
"""
YEARS = 1
MONTHS = 2
DAYS = 3
# FIXME: This is an old and ugly implementation.
# It must be changed to use the new age calculator.
age = 0
units = 0
birth_ref = person.get_birth_ref()
if birth_ref:
birth = database.get_event_from_handle(birth_ref.ref).get_date_object()
@ -2803,50 +2811,9 @@ def old_calc_age(database, person):
# wihtout at least a year for each event we're clueless
if not (birth_year_valid and death_year_valid):
return (age, units)
return None
# FIXME: The code below uses hard-coded 31 days in a month
# and 12 month in a year. This is incorrect for half the Gregorian
# months and for other calendars.
# FIXME: We need to move to estimate_age !!!
# If born and died in the same year, go to the months
if death.get_year() == birth.get_year():
if birth.get_month_valid() and death.get_month_valid():
# if born and died in the same month, do the days
if birth.get_month() == death.get_month() \
and birth.get_day_valid() and death.get_day_valid():
age = death.get_day() - birth.get_day()
units = DAYS
# if not the same month, just diff the months
else:
age = death.get_month() - birth.get_month()
units = MONTHS
# Born and died in different years
else:
age = death.get_year() - birth.get_year()
units = YEARS
if birth.get_month_valid() and death.get_month_valid():
# Subtract one year if less than a last full year
if birth.get_month() > death.get_month():
age = age - 1
# If less than a year (but still in different years)
# then calculate month diff modulo 12
if age == 0:
age = 12 + death.get_month() - birth.get_month()
units = MONTHS
# This is the case of birth on Dec 30 and death on Jan 2
# or birth on May 30 and death on June 2
if age == 1 and units == MONTHS \
and birth.get_day_valid() and death.get_day_valid() \
and birth.get_day() > death.get_day():
age = death.get_day() + 31 - birth.get_day()
units = DAYS
return (age, units)
return death - birth
def common_name(person, use_call=False):
if use_call and person.get_primary_name().get_call_name():

View File

@ -77,6 +77,9 @@ class Span:
def __getitem__(self, pos):
return self.diff_tuple[pos]
def is_valid(self):
return True
def __repr__(self):
retval = ""
if self.diff_tuple[0] != 0:
@ -348,23 +351,20 @@ class Date:
elif isinstance(other, type(self)): # Date1 - Date2 -> tuple
# We should make sure that Date2 + tuple -> Date1 and
# Date1 - tuple -> Date2
d1 = [i or 1 for i in self.get_ymd()]
d2 = [i or 1 for i in other.get_ymd()]
date1 = self
date2 = other
negative = False
if date1.calendar != Date.CAL_GREGORIAN:
date1 = date1.to_calendar("gregorian")
if date2.calendar != Date.CAL_GREGORIAN:
date2 = date2.to_calendar("gregorian")
d1 = [i or 1 for i in date1.get_ymd()]
d2 = [i or 1 for i in date2.get_ymd()]
if d1 < d2:
d1, d2 = d2, d1
date1, date2 = date2, date1
negative = True
# d1 - d2 (1998, 12, 32) - (1982, 12, 15)
if date1.calendar != date2.calendar:
diff = date1.sortval - date2.sortval
if negative:
return Span(-diff/365, -((diff % 365)/30), -((diff % 365) % 30))
else:
return Span(diff/365, (diff % 365)/30, (diff % 365) % 30)
# days:
if d2[2] > d1[2]:
# months:

View File

@ -250,9 +250,9 @@ class DetAncestorReport(Report):
if text:
self.doc.write_text(text)
age,units = self.calc_age(person)
span = self.calc_age(person)
text = ReportUtils.died_str(self.database, person, first, self.verbose,
self.EMPTY_DATE, self.EMPTY_PLACE, age, units)
self.EMPTY_DATE, self.EMPTY_PLACE, span)
if text:
death_ref = person.get_death_ref()
if death_ref:
@ -629,10 +629,10 @@ class DetAncestorReport(Report):
self.doc.write_text(text)
print_name = 0
age, units = self.calc_age(ind)
span = self.calc_age(ind)
text = ReportUtils.died_str(self.database, ind, print_name,
self.verbose, self.EMPTY_DATE, self.EMPTY_PLACE,
age, units)
span)
if text:
self.doc.write_text(text)
print_name = 0
@ -671,7 +671,7 @@ class DetAncestorReport(Report):
if self.calcageflag:
return ReportUtils.old_calc_age(self.database,ind)
else:
return (0,0)
return None
def endnotes(self, obj):
if not obj or not self.inc_sources:

View File

@ -532,9 +532,9 @@ class DetDescendantReport(Report):
if text:
self.doc.write_text(text)
age,units = self.calc_age(person)
span = self.calc_age(person)
text = ReportUtils.died_str(self.database, person, first, self.verbose,
self.EMPTY_DATE, self.EMPTY_PLACE, age, units)
self.EMPTY_DATE, self.EMPTY_PLACE, span)
if text:
death_ref = person.get_death_ref()
if death_ref:
@ -646,7 +646,7 @@ class DetDescendantReport(Report):
if self.calcageflag:
return ReportUtils.old_calc_age(self.database, ind)
else:
return (0, 0)
return None
def endnotes(self, obj):
if not obj or not self.inc_sources: