* src/Utils.py: uses MAX_AGE_PROB_ALIVE, MAX_SIB_AGE_DIFF, MIN_GENERATION_YEARS, AVG_GENERATION_GAP from Config (Bug #1217)
* src/Config/_GrampsConfigKeys.py: added MAX_AGE_PROB_ALIVE, MAX_SIB_AGE_DIFF, MIN_GENERATION_YEARS, AVG_GENERATION_GAP 2007-10-13 Douglas S. Blank <dblank@cs.brynmawr.edu> svn: r9177
This commit is contained in:
parent
4ae9327dd8
commit
b444a96dbe
@ -1,3 +1,7 @@
|
|||||||
|
2007-10-13 Douglas S. Blank <dblank@cs.brynmawr.edu>
|
||||||
|
* src/Utils.py: uses MAX_AGE_PROB_ALIVE, MAX_SIB_AGE_DIFF, MIN_GENERATION_YEARS, AVG_GENERATION_GAP from Config (Bug #1217)
|
||||||
|
* src/Config/_GrampsConfigKeys.py: added MAX_AGE_PROB_ALIVE, MAX_SIB_AGE_DIFF, MIN_GENERATION_YEARS, AVG_GENERATION_GAP
|
||||||
|
|
||||||
2007-10-13 Douglas S. Blank <dblank@cs.brynmawr.edu>
|
2007-10-13 Douglas S. Blank <dblank@cs.brynmawr.edu>
|
||||||
* src/plugins/Calendar.py: no negative years on calendar (no events show before they occur)
|
* src/plugins/Calendar.py: no negative years on calendar (no events show before they occur)
|
||||||
* src/plugins/Calendar.py: uses StringOption in MenuOption
|
* src/plugins/Calendar.py: uses StringOption in MenuOption
|
||||||
|
@ -151,7 +151,10 @@ OWNER_WARN = ('behavior', 'owner-warn', 0)
|
|||||||
DATE_BEFORE_RANGE = ('behavior', 'date-before-range', 1)
|
DATE_BEFORE_RANGE = ('behavior', 'date-before-range', 1)
|
||||||
DATE_AFTER_RANGE = ('behavior', 'date-after-range', 1)
|
DATE_AFTER_RANGE = ('behavior', 'date-after-range', 1)
|
||||||
DATE_ABOUT_RANGE = ('behavior', 'date-about-range', 1)
|
DATE_ABOUT_RANGE = ('behavior', 'date-about-range', 1)
|
||||||
|
MAX_AGE_PROB_ALIVE = ('behavior', 'max-age-prob-alive', 1)
|
||||||
|
MAX_SIB_AGE_DIFF = ('behavior', 'max-sib-age-diff', 1)
|
||||||
|
MIN_GENERATION_YEARS = ('behavior', 'min-generation-years', 1)
|
||||||
|
AVG_GENERATION_GAP = ('behavior', 'avg-generation-gap', 1)
|
||||||
|
|
||||||
default_value = {
|
default_value = {
|
||||||
DEFAULT_SOURCE : False,
|
DEFAULT_SOURCE : False,
|
||||||
@ -259,4 +262,8 @@ default_value = {
|
|||||||
DATE_BEFORE_RANGE : 9999,
|
DATE_BEFORE_RANGE : 9999,
|
||||||
DATE_AFTER_RANGE : 9999,
|
DATE_AFTER_RANGE : 9999,
|
||||||
DATE_ABOUT_RANGE : 10,
|
DATE_ABOUT_RANGE : 10,
|
||||||
|
MAX_AGE_PROB_ALIVE : 110,
|
||||||
|
MAX_SIB_AGE_DIFF : 20,
|
||||||
|
MIN_GENERATION_YEARS : 13,
|
||||||
|
AVG_GENERATION_GAP : 20,
|
||||||
}
|
}
|
||||||
|
63
src/Utils.py
63
src/Utils.py
@ -51,6 +51,26 @@ import gen.lib
|
|||||||
import Errors
|
import Errors
|
||||||
from QuestionDialog import WarningDialog
|
from QuestionDialog import WarningDialog
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Constants from config .ini keys
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#obtain the values once, they do not change!
|
||||||
|
try:
|
||||||
|
import Config
|
||||||
|
_MAX_AGE_PROB_ALIVE = Config.get(Config.MAX_AGE_PROB_ALIVE)
|
||||||
|
_MAX_SIB_AGE_DIFF = Config.get(Config.MAX_SIB_AGE_DIFF)
|
||||||
|
_MIN_GENERATION_YEARS = Config.get(Config.MIN_GENERATION_YEARS)
|
||||||
|
_AVG_GENERATION_GAP = Config.get(Config.AVG_GENERATION_GAP)
|
||||||
|
except ImportError:
|
||||||
|
# Utils used as module not part of GRAMPS
|
||||||
|
_MAX_AGE_PROB_ALIVE = 110
|
||||||
|
_MAX_SIB_AGE_DIFF = 20
|
||||||
|
_MIN_GENERATION_YEARS = 13
|
||||||
|
_AVG_GENERATION_GAP = 20
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# Integer to String mappings for constants
|
# Integer to String mappings for constants
|
||||||
@ -580,14 +600,14 @@ def probably_alive(person, db, current_year=None, limit=0):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
if not birth_year and death_year:
|
if not birth_year and death_year:
|
||||||
if death_year > current_year + 110:
|
if death_year > current_year + _MAX_AGE_PROB_ALIVE:
|
||||||
# person died more tha 110 after current year
|
# person died more than MAX after current year
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Neither birth nor death events are available. Try looking
|
# Neither birth nor death events are available. Try looking
|
||||||
# at siblings. If a sibling was born more than 120 years past,
|
# at siblings. If a sibling was born more than 120 years past,
|
||||||
# or more than 20 future, then problem then this person is
|
# or more than 20 future, then probably this person is
|
||||||
# probably not alive. If the sibling died more than 120 years
|
# not alive. If the sibling died more than 120 years
|
||||||
# past, or more than 120 years future, then probably not alive.
|
# past, or more than 120 years future, then probably not alive.
|
||||||
|
|
||||||
family_list = person.get_parent_family_handle_list()
|
family_list = person.get_parent_family_handle_list()
|
||||||
@ -604,7 +624,10 @@ def probably_alive(person, db, current_year=None, limit=0):
|
|||||||
# if sibling birth date too far away, then not alive:
|
# if sibling birth date too far away, then not alive:
|
||||||
year = dobj.get_year()
|
year = dobj.get_year()
|
||||||
if year != 0:
|
if year != 0:
|
||||||
if not (current_year - 120 < year < current_year + 20):
|
if not (current_year -
|
||||||
|
(_MAX_AGE_PROB_ALIVE + _MAX_SIB_AGE_DIFF) <
|
||||||
|
year <
|
||||||
|
current_year + _MAX_SIB_AGE_DIFF):
|
||||||
return False
|
return False
|
||||||
child_death_ref = child.get_death_ref()
|
child_death_ref = child.get_death_ref()
|
||||||
if child_death_ref:
|
if child_death_ref:
|
||||||
@ -614,14 +637,14 @@ def probably_alive(person, db, current_year=None, limit=0):
|
|||||||
# if sibling death date too far away, then not alive:
|
# if sibling death date too far away, then not alive:
|
||||||
year = dobj.get_year()
|
year = dobj.get_year()
|
||||||
if year != 0:
|
if year != 0:
|
||||||
if not (current_year - 120 < year < current_year + 120):
|
if not (current_year -
|
||||||
|
(_MAX_AGE_PROB_ALIVE + _MAX_SIB_AGE_DIFF) <
|
||||||
|
year < current_year + _MAX_AGE_PROB_ALIVE):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Try looking for descendants that were born more than a lifespan
|
# Try looking for descendants that were born more than a lifespan
|
||||||
# ago.
|
# ago.
|
||||||
|
|
||||||
min_generation = 13
|
|
||||||
|
|
||||||
def descendants_too_old (person, years):
|
def descendants_too_old (person, years):
|
||||||
for family_handle in person.get_family_handle_list():
|
for family_handle in person.get_family_handle_list():
|
||||||
family = db.get_family_from_handle(family_handle)
|
family = db.get_family_from_handle(family_handle)
|
||||||
@ -649,7 +672,7 @@ def probably_alive(person, db, current_year=None, limit=0):
|
|||||||
if not not_too_old (dobj, current_year):
|
if not not_too_old (dobj, current_year):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if descendants_too_old (child, years + min_generation):
|
if descendants_too_old (child, years + _MIN_GENERATION_YEARS):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
@ -658,16 +681,14 @@ def probably_alive(person, db, current_year=None, limit=0):
|
|||||||
# been alive in the current year then they must be dead.
|
# been alive in the current year then they must be dead.
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if descendants_too_old (person, min_generation):
|
if descendants_too_old(person, _MIN_GENERATION_YEARS):
|
||||||
return False
|
return False
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
raise Errors.DatabaseError(
|
raise Errors.DatabaseError(
|
||||||
_("Database error: %s is defined as his or her own ancestor") %
|
_("Database error: %s is defined as his or her own ancestor") %
|
||||||
name_displayer.display(person))
|
name_displayer.display(person))
|
||||||
|
|
||||||
average_generation_gap = 20
|
def ancestors_too_old(person, year):
|
||||||
|
|
||||||
def ancestors_too_old (person, year):
|
|
||||||
family_handle = person.get_main_parents_family_handle()
|
family_handle = person.get_main_parents_family_handle()
|
||||||
|
|
||||||
if family_handle:
|
if family_handle:
|
||||||
@ -681,7 +702,7 @@ def probably_alive(person, db, current_year=None, limit=0):
|
|||||||
father_birth_ref.ref)
|
father_birth_ref.ref)
|
||||||
dobj = father_birth.get_date_object()
|
dobj = father_birth.get_date_object()
|
||||||
if dobj.get_start_date() != gen.lib.Date.EMPTY:
|
if dobj.get_start_date() != gen.lib.Date.EMPTY:
|
||||||
if not not_too_old (dobj, year - average_generation_gap):
|
if not not_too_old (dobj, year - _AVG_GENERATION_GAP):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
father_death_ref = father.get_death_ref()
|
father_death_ref = father.get_death_ref()
|
||||||
@ -690,10 +711,10 @@ def probably_alive(person, db, current_year=None, limit=0):
|
|||||||
father_death_ref.ref)
|
father_death_ref.ref)
|
||||||
dobj = father_death.get_date_object()
|
dobj = father_death.get_date_object()
|
||||||
if dobj.get_start_date() != gen.lib.Date.EMPTY:
|
if dobj.get_start_date() != gen.lib.Date.EMPTY:
|
||||||
if dobj.get_year() < year - average_generation_gap:
|
if dobj.get_year() < year - _AVG_GENERATION_GAP:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if ancestors_too_old (father, year - average_generation_gap):
|
if ancestors_too_old (father, year - _AVG_GENERATION_GAP):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
mother_handle = family.get_mother_handle()
|
mother_handle = family.get_mother_handle()
|
||||||
@ -704,7 +725,7 @@ def probably_alive(person, db, current_year=None, limit=0):
|
|||||||
mother_birth = db.get_event_from_handle(mother_birth_ref.ref)
|
mother_birth = db.get_event_from_handle(mother_birth_ref.ref)
|
||||||
dobj = mother_birth.get_date_object()
|
dobj = mother_birth.get_date_object()
|
||||||
if dobj.get_start_date() != gen.lib.Date.EMPTY:
|
if dobj.get_start_date() != gen.lib.Date.EMPTY:
|
||||||
if not not_too_old (dobj, year - average_generation_gap):
|
if not not_too_old (dobj, year - _AVG_GENERATION_GAP):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
mother_death_ref = mother.get_death_ref()
|
mother_death_ref = mother.get_death_ref()
|
||||||
@ -713,10 +734,10 @@ def probably_alive(person, db, current_year=None, limit=0):
|
|||||||
mother_death_ref.ref)
|
mother_death_ref.ref)
|
||||||
dobj = mother_death.get_date_object()
|
dobj = mother_death.get_date_object()
|
||||||
if dobj.get_start_date() != gen.lib.Date.EMPTY:
|
if dobj.get_start_date() != gen.lib.Date.EMPTY:
|
||||||
if dobj.get_year() < year - average_generation_gap:
|
if dobj.get_year() < year - _AVG_GENERATION_GAP:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if ancestors_too_old (mother, year - average_generation_gap):
|
if ancestors_too_old (mother, year - _AVG_GENERATION_GAP):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
@ -739,7 +760,7 @@ def not_too_old(date, current_year=None):
|
|||||||
year = date.get_year()
|
year = date.get_year()
|
||||||
if year > current_year:
|
if year > current_year:
|
||||||
return False
|
return False
|
||||||
return (year != 0 and current_year - year < 110)
|
return (year != 0 and current_year - year < _MAX_AGE_PROB_ALIVE)
|
||||||
|
|
||||||
def too_old(date, current_year=None):
|
def too_old(date, current_year=None):
|
||||||
if current_year:
|
if current_year:
|
||||||
@ -750,7 +771,7 @@ def too_old(date, current_year=None):
|
|||||||
year = date.get_year()
|
year = date.get_year()
|
||||||
if year > the_current_year:
|
if year > the_current_year:
|
||||||
return True
|
return True
|
||||||
return (year != 0 and the_current_year - year > 150)
|
return (year != 0 and the_current_year - year > _MAX_AGE_PROB_ALIVE)
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
|
Loading…
x
Reference in New Issue
Block a user