Some fixes for Age on Date

svn: r14149
This commit is contained in:
Doug Blank 2010-01-27 13:32:53 +00:00
parent 1bc7a15a27
commit d63804d6b6

View File

@ -474,6 +474,11 @@ class ProbablyAlive(object):
self.AVG_GENERATION_GAP = avg_generation_gap self.AVG_GENERATION_GAP = avg_generation_gap
def probably_alive_range(self, person, is_spouse=False): def probably_alive_range(self, person, is_spouse=False):
# FIXME: some of these computed dates need to be a span. For
# example, if a person could be born +/- 20 yrs around
# a date then it should be a span, and yr_offset should
# deal with it as well ("between 1920 and 1930" + 10 =
# "between 1930 and 1940")
if person is None: if person is None:
return (None, None, "", None) return (None, None, "", None)
birth_ref = person.get_birth_ref() birth_ref = person.get_birth_ref()
@ -550,7 +555,7 @@ class ProbablyAlive(object):
if year != 0: if year != 0:
# sibling birth date # sibling birth date
return (gen.lib.Date().copy_ymd(year - self.MAX_SIB_AGE_DIFF), return (gen.lib.Date().copy_ymd(year - self.MAX_SIB_AGE_DIFF),
gen.lib.Date().copy_ymd(year + self.MAX_SIB_AGE_DIFF + self.MAX_AGE_PROB_ALIVE), gen.lib.Date().copy_ymd(year - self.MAX_SIB_AGE_DIFF + self.MAX_AGE_PROB_ALIVE),
_("sibling birth date"), _("sibling birth date"),
child) child)
elif ev and ev.type.is_death(): elif ev and ev.type.is_death():
@ -561,7 +566,8 @@ class ProbablyAlive(object):
if year != 0: if year != 0:
# sibling death date # sibling death date
return (gen.lib.Date().copy_ymd(year - self.MAX_SIB_AGE_DIFF - self.MAX_AGE_PROB_ALIVE), return (gen.lib.Date().copy_ymd(year - self.MAX_SIB_AGE_DIFF - self.MAX_AGE_PROB_ALIVE),
gen.lib.Date().copy_ymd(year + self.MAX_SIB_AGE_DIFF), gen.lib.Date().copy_ymd(year - self.MAX_SIB_AGE_DIFF - self.MAX_AGE_PROB_ALIVE
+ self.MAX_AGE_PROB_ALIVE),
_("sibling death date"), _("sibling death date"),
child) child)
# Go through again looking for fallback: # Go through again looking for fallback:
@ -575,7 +581,7 @@ class ProbablyAlive(object):
if year != 0: if year != 0:
# sibling birth date # sibling birth date
return (gen.lib.Date().copy_ymd(year - self.MAX_SIB_AGE_DIFF), return (gen.lib.Date().copy_ymd(year - self.MAX_SIB_AGE_DIFF),
gen.lib.Date().copy_ymd(year + self.MAX_SIB_AGE_DIFF + self.MAX_AGE_PROB_ALIVE), gen.lib.Date().copy_ymd(year - self.MAX_SIB_AGE_DIFF + self.MAX_AGE_PROB_ALIVE),
_("sibling birth-related date"), _("sibling birth-related date"),
child) child)
elif ev and ev.type.is_death_fallback(): elif ev and ev.type.is_death_fallback():
@ -586,7 +592,7 @@ class ProbablyAlive(object):
if year != 0: if year != 0:
# sibling death date # sibling death date
return (gen.lib.Date().copy_ymd(year - self.MAX_SIB_AGE_DIFF - self.MAX_AGE_PROB_ALIVE), return (gen.lib.Date().copy_ymd(year - self.MAX_SIB_AGE_DIFF - self.MAX_AGE_PROB_ALIVE),
gen.lib.Date().copy_ymd(year + self.MAX_SIB_AGE_DIFF), gen.lib.Date().copy_ymd(year - self.MAX_SIB_AGE_DIFF - self.MAX_AGE_PROB_ALIVE + self.MAX_AGE_PROB_ALIVE),
_("sibling death-related date"), _("sibling death-related date"),
child) child)
@ -620,8 +626,9 @@ class ProbablyAlive(object):
elif person.handle == father_handle and mother_handle: elif person.handle == father_handle and mother_handle:
other = self.db.get_person_from_handle(mother_handle) other = self.db.get_person_from_handle(mother_handle)
return (gen.lib.Date().copy_ymd(year - self.AVG_GENERATION_GAP), return (gen.lib.Date().copy_ymd(year - self.AVG_GENERATION_GAP),
gen.lib.Date().copy_ymd(year + (self.MAX_AGE_PROB_ALIVE - gen.lib.Date().copy_ymd(year - self.AVG_GENERATION_GAP +
self.AVG_GENERATION_GAP)), self.MAX_AGE_PROB_ALIVE),
_("event with spouse"), other) _("event with spouse"), other)
# Try looking for descendants that were born more than a lifespan # Try looking for descendants that were born more than a lifespan
@ -834,13 +841,12 @@ def probably_alive(person, db,
pb = ProbablyAlive(db, max_sib_age_diff, pb = ProbablyAlive(db, max_sib_age_diff,
max_age_prob_alive, avg_generation_gap) max_age_prob_alive, avg_generation_gap)
birth, death, explain, relative = pb.probably_alive_range(person) birth, death, explain, relative = pb.probably_alive_range(person)
if death is None: # no evidence... can't say if alive/dead if current_date is None:
if return_range: current_date = gen.lib.date.Today()
return (True, birth, death, explain, relative) if not birth or not death:
else: # no evidence, must consider alive
return True return (True, None, None, _("no evidence"), None)
# must have est dates # must have est dates from here:
if current_date: # date in which to consider alive
# SPECIAL CASE: Today: # SPECIAL CASE: Today:
if current_date.match(gen.lib.date.Today(), "=="): if current_date.match(gen.lib.date.Today(), "=="):
if person.get_death_ref(): if person.get_death_ref():
@ -848,21 +854,28 @@ def probably_alive(person, db,
return (False, birth, death, explain, relative) return (False, birth, death, explain, relative)
else: else:
return False return False
if limit:
death += limit # add these years to death
# if death in the future: # if death in the future:
if (gen.lib.date.Today() - death)[0] < 0: if (gen.lib.date.Today() - death)[0] < 0:
if return_range: if return_range:
return (True, birth, death, explain, relative) return (True, birth, death, ("future death, ") + explain, relative)
else: else:
return True return True
########### Not today, or today and no death ref:
if limit:
death += limit # add these years to death
# if the current - birth is too big, not alive: # if the current - birth is too big, not alive:
# FIXME: use match here:
if (current_date - birth)[0] > max_age_prob_alive: if (current_date - birth)[0] > max_age_prob_alive:
if return_range: if return_range:
return (False, birth, death, explain, relative) return (False, birth, death, explain, relative)
else: else:
return False return False
# FIXME: use match here:
# if the current_date is before birth, not alive:
if (birth - current_date)[0] >= 0:
if return_range:
return (False, birth, death, explain, relative)
else:
return False
# Finally, check to see if current_date is between dates # Finally, check to see if current_date is between dates
result = (current_date.match(birth, ">=") and result = (current_date.match(birth, ">=") and
current_date.match(death, "<=")) current_date.match(death, "<="))
@ -870,19 +883,6 @@ def probably_alive(person, db,
return (result, birth, death, explain, relative) return (result, birth, death, explain, relative)
else: else:
return result return result
# Future death:
if (gen.lib.date.Today() - death)[0] < 0:
if return_range:
return (True, birth, death, explain, relative)
else:
return True
# else, they have a est death date, and Today, thus dead
else:
if return_range:
return (False, birth, death, explain, relative)
else:
return False
def probably_alive_range(person, db, def probably_alive_range(person, db,
max_sib_age_diff=None, max_sib_age_diff=None,