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:
parent
d09bfef267
commit
7977800875
@ -1328,6 +1328,36 @@ class Date(object):
|
|||||||
if day != 0 or dv[Date._POS_DAY] > 28:
|
if day != 0 or dv[Date._POS_DAY] > 28:
|
||||||
self.set_yr_mon_day(*self.offset(day))
|
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):
|
def copy_offset_ymd(self, year=0, month=0, day=0):
|
||||||
"""
|
"""
|
||||||
Return a Date copy based on year, month, and day offset.
|
Return a Date copy based on year, month, and day offset.
|
||||||
@ -1339,6 +1369,9 @@ class Date(object):
|
|||||||
new_date = self
|
new_date = self
|
||||||
retval = Date(new_date)
|
retval = Date(new_date)
|
||||||
retval.set_yr_mon_day_offset(year, month, day)
|
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:
|
if orig_cal == 0:
|
||||||
return retval
|
return retval
|
||||||
else:
|
else:
|
||||||
@ -1351,6 +1384,9 @@ class Date(object):
|
|||||||
"""
|
"""
|
||||||
retval = Date(self)
|
retval = Date(self)
|
||||||
retval.set_yr_mon_day(year, month, day)
|
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
|
return retval
|
||||||
|
|
||||||
def set_year(self, year):
|
def set_year(self, year):
|
||||||
|
@ -102,16 +102,17 @@ class ProbablyAlive(object):
|
|||||||
death_date = None
|
death_date = None
|
||||||
birth_date = None
|
birth_date = None
|
||||||
explain = ""
|
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 and death_ref.get_role().is_primary():
|
||||||
if death_ref:
|
if death_ref:
|
||||||
death = self.db.get_event_from_handle(death_ref.ref)
|
death = self.db.get_event_from_handle(death_ref.ref)
|
||||||
if death and death.get_date_object().is_valid():
|
if death:
|
||||||
death_date = death.get_date_object()
|
if death.get_date_object().is_valid():
|
||||||
elif death: # has a death event, but it is no valid:
|
death_date = death.get_date_object()
|
||||||
death_date = Today() # before today
|
else: # has a death event, but it is not valid:
|
||||||
death_date.set_modifier(Date.MOD_BEFORE)
|
death_date = Today() # before today
|
||||||
explain = _("death event without date")
|
death_date.set_modifier(Date.MOD_BEFORE)
|
||||||
|
|
||||||
# Look for Cause Of Death, Burial or Cremation events.
|
# Look for Cause Of Death, Burial or Cremation events.
|
||||||
# These are fairly good indications that someone's not alive.
|
# 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)
|
ev = self.db.get_event_from_handle(ev_ref.ref)
|
||||||
if ev and ev.type.is_death_fallback():
|
if ev and ev.type.is_death_fallback():
|
||||||
death_date = ev.get_date_object()
|
death_date = ev.get_date_object()
|
||||||
if death_date.is_valid():
|
if not death_date.is_valid():
|
||||||
explain = _("death-related evidence")
|
|
||||||
else:
|
|
||||||
death_date = Today() # before today
|
death_date = Today() # before today
|
||||||
death_date.set_modifier(Date.MOD_BEFORE)
|
death_date.set_modifier(Date.MOD_BEFORE)
|
||||||
explain = _("death-related evidence without date")
|
|
||||||
|
|
||||||
# If they were born within X years before current year then
|
# If they were born within X years before current year then
|
||||||
# assume they are alive (we already know they are not dead).
|
# 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)
|
ev = self.db.get_event_from_handle(ev_ref.ref)
|
||||||
if ev and ev.type.is_birth_fallback():
|
if ev and ev.type.is_birth_fallback():
|
||||||
birth_date = ev.get_date_object()
|
birth_date = ev.get_date_object()
|
||||||
explain = _("birth-related evidence")
|
|
||||||
|
|
||||||
if not birth_date and death_date:
|
if not birth_date and death_date:
|
||||||
# person died more than MAX after current year
|
# 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
|
# First, get the real database to use all people
|
||||||
# for determining alive status:
|
# for determining alive status:
|
||||||
basedb = db.basedb
|
birth, death, explain, relative = probably_alive_range(person, db,
|
||||||
# Now, we create a wrapper for doing work:
|
max_sib_age_diff, max_age_prob_alive, avg_generation_gap)
|
||||||
pb = ProbablyAlive(basedb, max_sib_age_diff,
|
|
||||||
max_age_prob_alive,
|
|
||||||
avg_generation_gap)
|
|
||||||
birth, death, explain, relative = pb.probably_alive_range(person)
|
|
||||||
if current_date is None:
|
if current_date is None:
|
||||||
current_date = Today()
|
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:
|
if not birth or not death:
|
||||||
# no evidence, must consider alive
|
# 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:
|
# must have dates from here:
|
||||||
if limit:
|
if limit:
|
||||||
death += limit # add these years to death
|
death += limit # add these years to death
|
||||||
# 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, "<="))
|
||||||
if return_range:
|
if return_range:
|
||||||
return (result, birth, death, explain, relative)
|
return (result, birth, death, explain, relative)
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user