7034: probably_alive() failing when no birth-death dates specified; 6965: Probably Alive fails when birth date is a range

svn: r23023
This commit is contained in:
Doug Blank 2013-09-04 02:54:32 +00:00
parent d09bfef267
commit 7977800875
2 changed files with 53 additions and 20 deletions

View File

@ -1328,6 +1328,36 @@ class Date(object):
if day != 0 or dv[Date._POS_DAY] > 28:
self.set_yr_mon_day(*self.offset(day))
def set2_yr_mon_day_offset(self, year=0, month=0, day=0):
"""
Set the year, month, and day values by offset.
"""
dv = list(self.dateval)
if dv[Date._POS_RYR]:
dv[Date._POS_RYR] += year
elif year:
dv[Date._POS_RYR] = year
if dv[Date._POS_RMON]:
dv[Date._POS_RMON] += month
elif month:
if month < 0:
dv[Date._POS_RMON] = 1 + month
else:
dv[Date._POS_RMON] = month
# Fix if month out of bounds:
if month != 0: # only check if changed
if dv[Date._POS_RMON] == 0: # subtraction
dv[Date._POS_RMON] = 12
dv[Date._POS_RYR] -= 1
elif dv[Date._POS_RMON] < 0: # subtraction
dv[Date._POS_RYR] -= int((-dv[Date._POS_RMON]) / 12) + 1
dv[Date._POS_RMON] = (dv[Date._POS_RMON] % 12)
elif dv[Date._POS_RMON] > 12 or dv[Date._POS_RMON] < 1:
dv[Date._POS_RYR] += int(dv[Date._POS_RMON] / 12)
dv[Date._POS_RMON] = dv[Date._POS_RMON] % 12
if day != 0 or dv[Date._POS_RDAY] > 28:
self.set2_yr_mon_day(*self.offset(day))
def copy_offset_ymd(self, year=0, month=0, day=0):
"""
Return a Date copy based on year, month, and day offset.
@ -1339,6 +1369,9 @@ class Date(object):
new_date = self
retval = Date(new_date)
retval.set_yr_mon_day_offset(year, month, day)
if (self.get_modifier() == Date.MOD_RANGE or
self.get_modifier() == Date.MOD_SPAN):
retval.set2_yr_mon_day_offset(year, month, day)
if orig_cal == 0:
return retval
else:
@ -1351,6 +1384,9 @@ class Date(object):
"""
retval = Date(self)
retval.set_yr_mon_day(year, month, day)
if (self.get_modifier() == Date.MOD_RANGE or
self.get_modifier() == Date.MOD_SPAN):
retval.set2_yr_mon_day_offset(year, month, day)
return retval
def set_year(self, year):

View File

@ -102,16 +102,17 @@ class ProbablyAlive(object):
death_date = None
birth_date = None
explain = ""
# If the recorded death year is before current year then
# things are simple.
if death_ref and death_ref.get_role().is_primary():
if death_ref:
death = self.db.get_event_from_handle(death_ref.ref)
if death and death.get_date_object().is_valid():
death_date = death.get_date_object()
elif death: # has a death event, but it is no valid:
death_date = Today() # before today
death_date.set_modifier(Date.MOD_BEFORE)
explain = _("death event without date")
if death:
if death.get_date_object().is_valid():
death_date = death.get_date_object()
else: # has a death event, but it is not valid:
death_date = Today() # before today
death_date.set_modifier(Date.MOD_BEFORE)
# Look for Cause Of Death, Burial or Cremation events.
# These are fairly good indications that someone's not alive.
@ -121,12 +122,9 @@ class ProbablyAlive(object):
ev = self.db.get_event_from_handle(ev_ref.ref)
if ev and ev.type.is_death_fallback():
death_date = ev.get_date_object()
if death_date.is_valid():
explain = _("death-related evidence")
else:
if not death_date.is_valid():
death_date = Today() # before today
death_date.set_modifier(Date.MOD_BEFORE)
explain = _("death-related evidence without date")
# If they were born within X years before current year then
# assume they are alive (we already know they are not dead).
@ -143,7 +141,6 @@ class ProbablyAlive(object):
ev = self.db.get_event_from_handle(ev_ref.ref)
if ev and ev.type.is_birth_fallback():
birth_date = ev.get_date_object()
explain = _("birth-related evidence")
if not birth_date and death_date:
# person died more than MAX after current year
@ -488,23 +485,23 @@ def probably_alive(person, db,
"""
# First, get the real database to use all people
# for determining alive status:
basedb = db.basedb
# Now, we create a wrapper for doing work:
pb = ProbablyAlive(basedb, max_sib_age_diff,
max_age_prob_alive,
avg_generation_gap)
birth, death, explain, relative = pb.probably_alive_range(person)
birth, death, explain, relative = probably_alive_range(person, db,
max_sib_age_diff, max_age_prob_alive, avg_generation_gap)
if current_date is None:
current_date = Today()
LOG.debug("{}: b.{}, d.{} - {}".format(
" ".join(person.get_primary_name().get_text_data_list()),
birth, death, explain))
if not birth or not death:
# no evidence, must consider alive
return (True, None, None, _("no evidence"), None)
return ((True, None, None, _("no evidence"), None) if return_range
else True)
# must have dates from here:
if limit:
death += limit # add these years to death
# Finally, check to see if current_date is between dates
result = (current_date.match(birth, ">=") and
current_date.match(death, "<<"))
current_date.match(death, "<="))
if return_range:
return (result, birth, death, explain, relative)
else: