From 8f6567b960c7a157720a6be9f6e5e3397a6aa19e Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Thu, 25 May 2006 05:18:03 +0000 Subject: [PATCH] 2006-05-24 Alex Roitman * src/plugins/Verify.py: Start major rework, still in progress. svn: r6774 --- gramps2/ChangeLog | 3 + gramps2/src/plugins/Verify.py | 1387 +++++++++++++++++++++++++-------- 2 files changed, 1049 insertions(+), 341 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 9acedadb9..80f2b0d5c 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,6 @@ +2006-05-24 Alex Roitman + * src/plugins/Verify.py: Start major rework, still in progress. + 2006-05-24 Don Allingham * src/DataViews/_PersonView.py: merge functionality * src/ViewManager.py: merge functionality diff --git a/gramps2/src/plugins/Verify.py b/gramps2/src/plugins/Verify.py index aae408a44..a627be5b1 100644 --- a/gramps2/src/plugins/Verify.py +++ b/gramps2/src/plugins/Verify.py @@ -51,6 +51,130 @@ import ManagedWindow from PluginUtils import Tool, register_tool +#------------------------------------------------------------------------- +# +# temp storage and related functions +# +#------------------------------------------------------------------------- +_person_store = {} +_family_store = {} +_event_store = {} + +def find_event(db,handle): + try: + obj = _event_store[handle] + except KeyError: + obj = db.get_event_from_handle(handle) + _event_store[handle] = obj + print "reading event", obj.gramps_id + return obj + +def find_person(db,handle): + try: + obj = _person_store[handle] + except KeyError: + obj = db.get_person_from_handle(handle) + _person_store[handle] = obj + print "reading person", obj.gramps_id + return obj + +def find_family(db,handle): + try: + obj = _family_store[handle] + except KeyError: + obj = db.get_family_from_handle(handle) + _family_store[handle] = obj + print "reading family", obj.gramps_id + return obj + +def clear_storage(): + print "events:", len(_event_store), "families:", len(_family_store), \ + "people:", len(_person_store) + _person_store.clear() + _family_store.clear() + _event_store.clear() +#------------------------------------------------------------------------- +# +# helper functions +# +#------------------------------------------------------------------------- +def get_date_from_event_handle(db,event_handle): + if not event_handle: + return 0 + event = find_event(db,event_handle) + date_obj = event.get_date_object() + return date_obj.get_sort_value() + +def get_date_from_event_type(db,person,event_type): + if not person: + return 0 + for event_ref in person.get_event_ref_list(): + event = find_event(db,event_ref.ref) + if event.get_type() == event_type: + date_obj = event.get_date_object() + return date_obj.get_sort_value() + return 0 + +def get_birth_date(db,person): + if not person: + return 0 + birth_ref = person.get_birth_ref() + if not birth_ref: + return 0 + return get_date_from_event_handle(db,birth_ref.ref) + +def get_death_date(db,person): + if not person: + return 0 + death_ref = person.get_death_ref() + if not death_ref: + return 0 + return get_date_from_event_handle(db,death_ref.ref) + +def get_bapt_date(db,person): + return get_date_from_event_type(db,person,RelLib.EventType.BAPTISM) + +def get_bury_date(db,person): + return get_date_from_event_type(db,person,RelLib.EventType.BURIAL) + +def get_age_at_death(db,person): + birth_date = get_birth_date(db,person) + death_date = get_death_date(db,person) + if (birth_date > 0) and (death_date > 0): + return death_date - birth_date + return 0 + +def get_father(db,family): + if not family: + return None + father_handle = family.get_father_handle() + if father_handle: + return find_person(db,father_handle) + return None + +def get_mother(db,family): + if not family: + return None + mother_handle = family.get_mother_handle() + if mother_handle: + return find_person(db,mother_handle) + return None + +def get_child_birth_dates(db,family): + dates = [] + for child_ref in family.get_child_ref_list(): + child = find_person(db,child_ref.ref) + child_birth_date = get_birth_date(child) + if child_birth_date > 0: + dates.append(child_birth_date) + return dates + +def get_n_children(db,person): + n = 0 + for family_handle in person.get_family_handle_list(): + family = find_family(db,family_handle) + n += len(family.get_child_ref_list()) + #------------------------------------------------------------------------- # # Actual tool @@ -180,7 +304,7 @@ class Verify(Tool.Tool, ManagedWindow.ManagedWindow): def run_tool(self,cli=False): - personList = self.db.get_person_handles(sort_handles=False) + person_handles = self.db.get_person_handles(sort_handles=False) oldage = self.options.handler.options_dict['oldage'] hwdif = self.options.handler.options_dict['hwdif'] cspace = self.options.handler.options_dict['cspace'] @@ -201,384 +325,405 @@ class Verify(Tool.Tool, ManagedWindow.ManagedWindow): # OR should be removed. What's the reason behind it? oldunm = 99 # maximum age at death for unmarried person - error = cStringIO.StringIO() - warn = cStringIO.StringIO() + +# error = cStringIO.StringIO() +# warn = cStringIO.StringIO() if not cli: progress = Utils.ProgressMeter(_('Verify the database'),'') progress.set_pass(_('Checking data'), self.db.get_number_of_people()) - for person_handle in personList: - person = self.db.get_person_from_handle(person_handle) - idstr = "%s (%s)" % (person.get_primary_name().get_name(),person.get_gramps_id()) + for person_handle in person_handles: + person = find_person(self.db,person_handle) - # individual checks - total_children = 0 - ageatdeath = 0 - - birth_ref = person.get_birth_ref() - if birth_ref: - birth_handle = birth_ref.ref - else: - birth_handle = None - - death_ref = person.get_death_ref() - if death_ref: - death_handle = death_ref.ref - else: - death_handle = None + the_rule = BirthAfterBapt(self.db,person) + if the_rule.broken(): + print the_rule.get_message() - byear = self.get_year( birth_handle ) - bapyear = 0 - dyear = self.get_year( death_handle ) - buryear = 0 + the_rule = DeathBeforeBapt(self.db,person) + if the_rule.broken(): + print the_rule.get_message() + + the_rule = BirthAfterBury(self.db,person) + if the_rule.broken(): + print the_rule.get_message() + + the_rule = DeathAfterBury(self.db,person) + if the_rule.broken(): + print the_rule.get_message() + + the_rule = BirthAfterDeath(self.db,person) + if the_rule.broken(): + print the_rule.get_message() + + the_rule = BaptAfterBury(self.db,person) + if the_rule.broken(): + print the_rule.get_message() + + the_rule = OldAge(self.db,person,oldage) + if the_rule.broken(): + print the_rule.get_message() + + the_rule = UnknownGender(self.db,person) + if the_rule.broken(): + print the_rule.get_message() + + the_rule = MultipleParents(self.db,person) + if the_rule.broken(): + print the_rule.get_message() + + the_rule = MarriedOften(self.db,person,wedder) + if the_rule.broken(): + print the_rule.get_message() + + the_rule = OldUnmarried(self.db,person,oldunm) + if the_rule.broken(): + print the_rule.get_message() + + the_rule = TooManyChildren(self.db,person,mxchilddad,mxchildmom) + if the_rule.broken(): + print the_rule.get_message() - for event_ref in person.get_event_ref_list(): - if event_ref: - event_handle = event_ref.ref - event = self.db.get_event_from_handle(event_handle) - if event.get_type() == RelLib.EventType.BURIAL: - buryear = self.get_year( event.get_handle() ) - elif event.get_type() == RelLib.EventType.BAPTISM: - bapyear = self.get_year( event.get_handle() ) - - if byear>0 and bapyear>0: - if byear > bapyear: - if person.get_gender() == RelLib.Person.MALE: - error.write( _("Baptized before birth: %(male_name)s born %(byear)d, baptized %(bapyear)d.\n") % { - 'male_name' : idstr, 'byear' : byear, 'bapyear' : bapyear } ) - if person.get_gender() == RelLib.Person.FEMALE: - error.write( _("Baptized before birth: %(female_name)s born %(byear)d, baptized %(bapyear)d.\n") % { - 'female_name' : idstr, 'byear' : byear, 'bapyear' : bapyear } ) - if byear < bapyear: - if person.get_gender() == RelLib.Person.MALE: - warn.write( _("Baptized late: %(male_name)s born %(byear)d, baptized %(bapyear)d.\n") % { - 'male_name' : idstr, 'byear' : byear, 'bapyear' : bapyear } ) - if person.get_gender() == RelLib.Person.FEMALE: - warn.write( _("Baptized late: %(female_name)s born %(byear)d, baptized %(bapyear)d.\n") % { - 'female_name' : idstr, 'byear' : byear, 'bapyear' : bapyear } ) - if dyear>0 and buryear>0: - if dyear > buryear: - if person.get_gender() == RelLib.Person.MALE: - error.write( _("Buried before death: %(male_name)s died %(dyear)d, buried %(buryear)d.\n") % { - 'male_name' : idstr, 'dyear' : dyear, 'buryear' : buryear } ) - if person.get_gender() == RelLib.Person.FEMALE: - error.write( _("Buried before death: %(female_name)s died %(dyear)d, buried %(buryear)d.\n") % { - 'female_name' : idstr, 'dyear' : dyear, 'buryear' : buryear } ) - if dyear < buryear: - if person.get_gender() == RelLib.Person.MALE: - warn.write( _("Buried late: %(male_name)s died %(dyear)d, buried %(buryear)d.\n") % { - 'male_name' : idstr, 'dyear' : dyear, 'buryear' : buryear } ) - if person.get_gender() == RelLib.Person.FEMALE: - warn.write( _("Buried late: %(female_name)s died %(dyear)d, buried %(buryear)d.\n") % { - 'female_name' : idstr, 'dyear' : dyear, 'buryear' : buryear } ) - if dyear>0 and (byear>dyear): - if person.get_gender() == RelLib.Person.MALE: - error.write( _("Died before birth: %(male_name)s born %(byear)d, died %(dyear)d.\n") % { - 'male_name' : idstr, 'byear' : byear, 'dyear' : dyear } ) - if person.get_gender() == RelLib.Person.FEMALE: - error.write( _("Died before birth: %(female_name)s born %(byear)d, died %(dyear)d.\n") % { - 'female_name' : idstr, 'byear' : byear, 'dyear' : dyear } ) - if dyear>0 and (bapyear>dyear): - if person.get_gender() == RelLib.Person.MALE: - error.write( _("Died before baptism: %(male_name)s baptized %(bapyear)d, died %(dyear)d.\n") % { - 'male_name' : idstr, 'bapyear' : bapyear, 'dyear' : dyear } ) - if person.get_gender() == RelLib.Person.FEMALE: - error.write( _("Died before baptism: %(female_name)s baptized %(bapyear)d, died %(dyear)d.\n") % { - 'female_name' : idstr, 'bapyear' : bapyear, 'dyear' : dyear } ) - if buryear>0 and (byear>buryear): - if person.get_gender() == RelLib.Person.MALE: - error.write( _("Buried before birth: %(male_name)s born %(byear)d, buried %(buryear)d.\n") % { - 'male_name' : idstr, 'byear' : byear, 'buryear' : buryear } ) - if person.get_gender() == RelLib.Person.FEMALE: - error.write( _("Buried before birth: %(female_name)s born %(byear)d, buried %(buryear)d.\n") % { - 'female_name' : idstr, 'byear' : byear, 'buryear' : buryear } ) - if buryear>0 and (bapyear>buryear): - if person.get_gender() == RelLib.Person.MALE: - error.write( _("Buried before baptism: %(male_name)s baptized %(bapyear)d, buried %(buryear)d.\n") % { - 'male_name' : idstr, 'bapyear' : bapyear, 'buryear' : buryear } ) - if person.get_gender() == RelLib.Person.FEMALE: - error.write( _("Buried before baptism: %(female_name)s baptized %(bapyear)d, buried %(buryear)d.\n") % { - 'female_name' : idstr, 'bapyear' : bapyear, 'buryear' : buryear } ) - if byear == 0 and estimate_age: - byear = bapyear # guess baptism = birth - if dyear == 0 and estimate_age: - dyear = buryear # guess burial = death - if byear>0 and dyear>0: - ageatdeath = dyear - byear - else: - ageatdeath = 0 - if ageatdeath > oldage: - if person.get_gender() == RelLib.Person.MALE: - warn.write( _("Old age: %(male_name)s born %(byear)d, died %(dyear)d, at the age of %(ageatdeath)d.\n") % { - 'male_name' : idstr, 'byear' : byear, 'dyear' : dyear, 'ageatdeath' : ageatdeath } ) - if person.get_gender() == RelLib.Person.FEMALE: - warn.write( _("Old age: %(female_name)s born %(byear)d, died %(dyear)d, at the age of %(ageatdeath)d.\n") % { - 'female_name' : idstr, 'byear' : byear, 'dyear' : dyear, 'ageatdeath' : ageatdeath } ) + clear_storage() + + +## if byear>0 and bapyear>0: +## if byear > bapyear: +## if person.get_gender() == RelLib.Person.MALE: +## error.write( _("Baptized before birth: %(male_name)s born %(byear)d, baptized %(bapyear)d.\n") % { +## 'male_name' : idstr, 'byear' : byear, 'bapyear' : bapyear } ) +## if person.get_gender() == RelLib.Person.FEMALE: +## error.write( _("Baptized before birth: %(female_name)s born %(byear)d, baptized %(bapyear)d.\n") % { +## 'female_name' : idstr, 'byear' : byear, 'bapyear' : bapyear } ) +## if byear < bapyear: +## if person.get_gender() == RelLib.Person.MALE: +## warn.write( _("Baptized late: %(male_name)s born %(byear)d, baptized %(bapyear)d.\n") % { +## 'male_name' : idstr, 'byear' : byear, 'bapyear' : bapyear } ) +## if person.get_gender() == RelLib.Person.FEMALE: +## warn.write( _("Baptized late: %(female_name)s born %(byear)d, baptized %(bapyear)d.\n") % { +## 'female_name' : idstr, 'byear' : byear, 'bapyear' : bapyear } ) +## if dyear>0 and buryear>0: +## if dyear > buryear: +## if person.get_gender() == RelLib.Person.MALE: +## error.write( _("Buried before death: %(male_name)s died %(dyear)d, buried %(buryear)d.\n") % { +## 'male_name' : idstr, 'dyear' : dyear, 'buryear' : buryear } ) +## if person.get_gender() == RelLib.Person.FEMALE: +## error.write( _("Buried before death: %(female_name)s died %(dyear)d, buried %(buryear)d.\n") % { +## 'female_name' : idstr, 'dyear' : dyear, 'buryear' : buryear } ) +## if dyear < buryear: +## if person.get_gender() == RelLib.Person.MALE: +## warn.write( _("Buried late: %(male_name)s died %(dyear)d, buried %(buryear)d.\n") % { +## 'male_name' : idstr, 'dyear' : dyear, 'buryear' : buryear } ) +## if person.get_gender() == RelLib.Person.FEMALE: +## warn.write( _("Buried late: %(female_name)s died %(dyear)d, buried %(buryear)d.\n") % { +## 'female_name' : idstr, 'dyear' : dyear, 'buryear' : buryear } ) +## if dyear>0 and (byear>dyear): +## if person.get_gender() == RelLib.Person.MALE: +## error.write( _("Died before birth: %(male_name)s born %(byear)d, died %(dyear)d.\n") % { +## 'male_name' : idstr, 'byear' : byear, 'dyear' : dyear } ) +## if person.get_gender() == RelLib.Person.FEMALE: +## error.write( _("Died before birth: %(female_name)s born %(byear)d, died %(dyear)d.\n") % { +## 'female_name' : idstr, 'byear' : byear, 'dyear' : dyear } ) +## if dyear>0 and (bapyear>dyear): +## if person.get_gender() == RelLib.Person.MALE: +## error.write( _("Died before baptism: %(male_name)s baptized %(bapyear)d, died %(dyear)d.\n") % { +## 'male_name' : idstr, 'bapyear' : bapyear, 'dyear' : dyear } ) +## if person.get_gender() == RelLib.Person.FEMALE: +## error.write( _("Died before baptism: %(female_name)s baptized %(bapyear)d, died %(dyear)d.\n") % { +## 'female_name' : idstr, 'bapyear' : bapyear, 'dyear' : dyear } ) +## if buryear>0 and (byear>buryear): +## if person.get_gender() == RelLib.Person.MALE: +## error.write( _("Buried before birth: %(male_name)s born %(byear)d, buried %(buryear)d.\n") % { +## 'male_name' : idstr, 'byear' : byear, 'buryear' : buryear } ) +## if person.get_gender() == RelLib.Person.FEMALE: +## error.write( _("Buried before birth: %(female_name)s born %(byear)d, buried %(buryear)d.\n") % { +## 'female_name' : idstr, 'byear' : byear, 'buryear' : buryear } ) +## if buryear>0 and (bapyear>buryear): +## if person.get_gender() == RelLib.Person.MALE: +## error.write( _("Buried before baptism: %(male_name)s baptized %(bapyear)d, buried %(buryear)d.\n") % { +## 'male_name' : idstr, 'bapyear' : bapyear, 'buryear' : buryear } ) +## if person.get_gender() == RelLib.Person.FEMALE: +## error.write( _("Buried before baptism: %(female_name)s baptized %(bapyear)d, buried %(buryear)d.\n") % { +## 'female_name' : idstr, 'bapyear' : bapyear, 'buryear' : buryear } ) +## if byear == 0 and estimate_age: +## byear = bapyear # guess baptism = birth +## if dyear == 0 and estimate_age: +## dyear = buryear # guess burial = death +## if byear>0 and dyear>0: +## ageatdeath = dyear - byear +## else: +## ageatdeath = 0 +## if ageatdeath > oldage: +## if person.get_gender() == RelLib.Person.MALE: +## warn.write( _("Old age: %(male_name)s born %(byear)d, died %(dyear)d, at the age of %(ageatdeath)d.\n") % { +## 'male_name' : idstr, 'byear' : byear, 'dyear' : dyear, 'ageatdeath' : ageatdeath } ) +## if person.get_gender() == RelLib.Person.FEMALE: +## warn.write( _("Old age: %(female_name)s born %(byear)d, died %(dyear)d, at the age of %(ageatdeath)d.\n") % { +## 'female_name' : idstr, 'byear' : byear, 'dyear' : dyear, 'ageatdeath' : ageatdeath } ) - # gender checks +## # gender checks - if person.get_gender() == RelLib.Person.FEMALE: - oldpar = oldmom - yngpar = yngmom - if person.get_gender() == RelLib.Person.MALE: - oldpar = olddad - yngpar = yngdad - if (person.get_gender() != RelLib.Person.FEMALE) and (person.get_gender() != RelLib.Person.MALE): - warn.write( _("Unknown gender for %s.\n") % idstr ) - oldpar = olddad - yngpar = yngdad - if (person.get_gender() == RelLib.Person.FEMALE) and (person.get_gender() == RelLib.Person.MALE): - error.write( _("Ambiguous gender for %s.\n") % idstr ) - oldpar = olddad - yngpar = yngdad +## if person.get_gender() == RelLib.Person.FEMALE: +## oldpar = oldmom +## yngpar = yngmom +## if person.get_gender() == RelLib.Person.MALE: +## oldpar = olddad +## yngpar = yngdad +## if (person.get_gender() != RelLib.Person.FEMALE) and (person.get_gender() != RelLib.Person.MALE): +## warn.write( _("Unknown gender for %s.\n") % idstr ) +## oldpar = olddad +## yngpar = yngdad +## if (person.get_gender() == RelLib.Person.FEMALE) and (person.get_gender() == RelLib.Person.MALE): +## error.write( _("Ambiguous gender for %s.\n") % idstr ) +## oldpar = olddad +## yngpar = yngdad - # multiple parentage check - if( len( person.get_parent_family_handle_list() ) > 1 ): - warn.write( _("Multiple parentage for %s.\n") % idstr ) +## # multiple parentage check +## if( len( person.get_parent_family_handle_list() ) > 1 ): +## warn.write( _("Multiple parentage for %s.\n") % idstr ) - # marriage checks - nkids = 0 - nfam = len( person.get_family_handle_list() ) - if nfam > wedder: - if person.get_gender() == RelLib.Person.MALE: - warn.write( _("Married often: %(male_name)s married %(nfam)d times.\n") % { - 'male_name' : idstr, 'nfam' : nfam } ) - if person.get_gender() == RelLib.Person.FEMALE: - warn.write( _("Married often: %(female_name)s married %(nfam)d times.\n") % { - 'female_name' : idstr, 'nfam' : nfam } ) - if ageatdeath>oldunm and nfam == 0: - if person.get_gender() == RelLib.Person.MALE: - warn.write( _("Old and unmarried: %(male_name)s died unmarried, at the age of %(ageatdeath)d years.\n") % { - 'male_name' : idstr, 'ageatdeath' : ageatdeath } ) - if person.get_gender() == RelLib.Person.FEMALE: - warn.write( _("Old and unmarried: %(female_name)s died unmarried, at the age of %(ageatdeath)d years.\n") % { - 'female_name' : idstr, 'ageatdeath' : ageatdeath } ) - prev_cbyear=0 - prev_maryear=0 - prev_sdyear=0 - fnum = 0 +## # marriage checks +## nkids = 0 +## nfam = len( person.get_family_handle_list() ) +## if nfam > wedder: +## if person.get_gender() == RelLib.Person.MALE: +## warn.write( _("Married often: %(male_name)s married %(nfam)d times.\n") % { +## 'male_name' : idstr, 'nfam' : nfam } ) +## if person.get_gender() == RelLib.Person.FEMALE: +## warn.write( _("Married often: %(female_name)s married %(nfam)d times.\n") % { +## 'female_name' : idstr, 'nfam' : nfam } ) +## if ageatdeath>oldunm and nfam == 0: +## if person.get_gender() == RelLib.Person.MALE: +## warn.write( _("Old and unmarried: %(male_name)s died unmarried, at the age of %(ageatdeath)d years.\n") % { +## 'male_name' : idstr, 'ageatdeath' : ageatdeath } ) +## if person.get_gender() == RelLib.Person.FEMALE: +## warn.write( _("Old and unmarried: %(female_name)s died unmarried, at the age of %(ageatdeath)d years.\n") % { +## 'female_name' : idstr, 'ageatdeath' : ageatdeath } ) +## prev_cbyear=0 +## prev_maryear=0 +## prev_sdyear=0 +## fnum = 0 - for family_handle in person.get_family_handle_list(): - family = self.db.get_family_from_handle(family_handle) - fnum = fnum + 1 - mother_handle = family.get_mother_handle() - father_handle = family.get_father_handle() - if mother_handle: - mother = self.db.get_person_from_handle(mother_handle) - if father_handle: - father = self.db.get_person_from_handle(father_handle) - if mother_handle and father_handle: - if ( mother.get_gender() == father.get_gender() ) and mother.get_gender() != RelLib.Person.UNKNOWN: - warn.write( _("Homosexual marriage: %s in family %s.\n") % ( idstr, family.get_gramps_id() ) ) - if father_handle == person.get_handle() and person.get_gender() == RelLib.Person.FEMALE: - error.write( _("Female husband: %s in family %s.\n") % ( idstr, family.get_gramps_id() ) ) - if mother_handle == person.get_handle() and person.get_gender() == RelLib.Person.MALE: - error.write( _("Male wife: %s in family %s.\n") % ( idstr, family.get_gramps_id() ) ) - if father_handle == person.get_handle(): - spouse_id = mother_handle - else: - spouse_id = father_handle - if spouse_id: - spouse = self.db.get_person_from_handle(spouse_id) - if person.get_gender() == RelLib.Person.MALE and \ - person.get_primary_name().get_surname() == spouse.get_primary_name().get_surname(): - warn.write( _("Husband and wife with the same surname: %s in family %s, and %s.\n") % ( - idstr,family.get_gramps_id(), spouse.get_primary_name().get_name() ) ) +## for family_handle in person.get_family_handle_list(): +## family = self.db.get_family_from_handle(family_handle) +## fnum = fnum + 1 +## mother_handle = family.get_mother_handle() +## father_handle = family.get_father_handle() +## if mother_handle: +## mother = self.db.get_person_from_handle(mother_handle) +## if father_handle: +## father = self.db.get_person_from_handle(father_handle) +## if mother_handle and father_handle: +## if ( mother.get_gender() == father.get_gender() ) and mother.get_gender() != RelLib.Person.UNKNOWN: +## warn.write( _("Homosexual marriage: %s in family %s.\n") % ( idstr, family.get_gramps_id() ) ) +## if father_handle == person.get_handle() and person.get_gender() == RelLib.Person.FEMALE: +## error.write( _("Female husband: %s in family %s.\n") % ( idstr, family.get_gramps_id() ) ) +## if mother_handle == person.get_handle() and person.get_gender() == RelLib.Person.MALE: +## error.write( _("Male wife: %s in family %s.\n") % ( idstr, family.get_gramps_id() ) ) +## if father_handle == person.get_handle(): +## spouse_id = mother_handle +## else: +## spouse_id = father_handle +## if spouse_id: +## spouse = self.db.get_person_from_handle(spouse_id) +## if person.get_gender() == RelLib.Person.MALE and \ +## person.get_primary_name().get_surname() == spouse.get_primary_name().get_surname(): +## warn.write( _("Husband and wife with the same surname: %s in family %s, and %s.\n") % ( +## idstr,family.get_gramps_id(), spouse.get_primary_name().get_name() ) ) - death_ref = spouse.get_death_ref() - if death_ref: - death_handle = death_ref.ref - else: - death_handle = None +## death_ref = spouse.get_death_ref() +## if death_ref: +## death_handle = death_ref.ref +## else: +## death_handle = None - birth_ref = spouse.get_birth_ref() - if birth_ref: - birth_handle = birth_ref.ref - else: - birth_handle = None +## birth_ref = spouse.get_birth_ref() +## if birth_ref: +## birth_handle = birth_ref.ref +## else: +## birth_handle = None - sdyear = self.get_year( death_handle ) - sbyear = self.get_year( birth_handle ) - if sbyear != 0 and byear != 0 and abs(sbyear-byear) > hwdif: - warn.write( _("Large age difference between husband and wife: %s in family %s, and %s.\n") % ( - idstr,family.get_gramps_id(), spouse.get_primary_name().get_name() ) ) +## sdyear = self.get_year( death_handle ) +## sbyear = self.get_year( birth_handle ) +## if sbyear != 0 and byear != 0 and abs(sbyear-byear) > hwdif: +## warn.write( _("Large age difference between husband and wife: %s in family %s, and %s.\n") % ( +## idstr,family.get_gramps_id(), spouse.get_primary_name().get_name() ) ) - if sdyear == 0: - sdyear = 0 # burial year +## if sdyear == 0: +## sdyear = 0 # burial year - for event_ref in family.get_event_ref_list(): - if event_ref: - event_handle = event_ref.ref - event = self.db.get_event_from_handle(event_handle) - if event.get_type().xml_str() == "Marriage": - marriage_id = event_handle - break - else: - marriage_id = None +## for event_ref in family.get_event_ref_list(): +## if event_ref: +## event_handle = event_ref.ref +## event = self.db.get_event_from_handle(event_handle) +## if event.get_type().xml_str() == "Marriage": +## marriage_id = event_handle +## break +## else: +## marriage_id = None - maryear = self.get_year( marriage_id ) +## maryear = self.get_year( marriage_id ) - if maryear == 0 and estimate_age: # estimate marriage year - cnum=0 - for child_ref in family.get_child_ref_list(): - cnum = cnum + 1 - if maryear == 0: - child = self.db.get_person_from_handle(child_ref.ref) - birth_ref = child.get_birth_ref() - if birth_ref: - birthyear = self.get_year(birth_ref.ref) - else: - birthyear = 0 - if birthyear > 0: - maryear = birthyear-cnum +## if maryear == 0 and estimate_age: # estimate marriage year +## cnum=0 +## for child_ref in family.get_child_ref_list(): +## cnum = cnum + 1 +## if maryear == 0: +## child = self.db.get_person_from_handle(child_ref.ref) +## birth_ref = child.get_birth_ref() +## if birth_ref: +## birthyear = self.get_year(birth_ref.ref) +## else: +## birthyear = 0 +## if birthyear > 0: +## maryear = birthyear-cnum - if maryear > 0: - if byear > 0: - marage = maryear - byear - if marage < 0: - if person.get_gender() == RelLib.Person.MALE: - error.write( _("Married before birth: %(male_name)s born %(byear)d, married %(maryear)d to %(spouse)s.\n") % { - 'male_name' : idstr, 'byear' : byear, 'maryear' : maryear, 'spouse' : spouse.get_primary_name().get_name() } ) - if person.get_gender() == RelLib.Person.FEMALE: - error.write( _("Married before birth: %(female_name)s born %(byear)d, married %(maryear)d to %(spouse)s.\n") % { - 'female_name' : idstr, 'byear' : byear, 'maryear' : maryear, 'spouse' : spouse.get_primary_name().get_name() } ) - else: - if marage < yngmar: - if person.get_gender() == RelLib.Person.MALE: - warn.write( _("Young marriage: %(male_name)s married at age %(marage)d to %(spouse)s.\n") % { - 'male_name' : idstr, 'marage' : marage, 'spouse' : spouse.get_primary_name().get_name() } ) - if person.get_gender() == RelLib.Person.FEMALE: - warn.write( _("Young marriage: %(female_name)s married at age %(marage)d to %(spouse)s.\n") % { - 'female_name' : idstr, 'marage' : marage, 'spouse' : spouse.get_primary_name().get_name() } ) - if marage > oldmar: - if person.get_gender() == RelLib.Person.MALE: - warn.write( _("Old marriage: %(male_name)s married at age %(marage)d to %(spouse)s.\n") % { - 'male_name' : idstr, 'marage' : marage, 'spouse' : spouse.get_primary_name().get_name() } ) - if person.get_gender() == RelLib.Person.FEMALE: - warn.write( _("Old marriage: %(female_name)s married at age %(marage)d to %(spouse)s.\n") % { - 'female_name' : idstr, 'marage' : marage, 'spouse' : spouse.get_primary_name().get_name() } ) - if dyear>0 and maryear > dyear: - if person.get_gender() == RelLib.Person.MALE: - error.write( _("Married after death: %(male_name)s died %(dyear)d, married %(maryear)d to %(spouse)s.\n") % { - 'male_name' : idstr, 'dyear' : dyear, 'maryear' : maryear, 'spouse' : spouse.get_primary_name().get_name() } ) - if person.get_gender() == RelLib.Person.FEMALE: - error.write( _("Married after death: %(female_name)s died %(dyear)d, married %(maryear)d to %(spouse)s.\n") % { - 'female_name' : idstr, 'dyear' : dyear, 'maryear' : maryear, 'spouse' : spouse.get_primary_name().get_name() } ) - if prev_cbyear > maryear: - if person.get_gender() == RelLib.Person.MALE: - warn.write( _("Marriage before birth from previous family: %(male_name)s married %(maryear)d to %(spouse)s, previous birth %(prev_cbyear)d.\n") % { - 'male_name' : idstr, 'maryear' : maryear, 'spouse' : spouse.get_primary_name().get_name(), 'prev_cbyear' : prev_cbyear } ) - if person.get_gender() == RelLib.Person.FEMALE: - warn.write( _("Marriage before birth from previous family: %(female_name)s married %(maryear)d to %(spouse)s, previous birth %(prev_cbyear)d.\n") % { - 'female_name' : idstr, 'maryear' : maryear, 'spouse' : spouse.get_primary_name().get_name(), 'prev_cbyear' : prev_cbyear } ) - prev_maryear = maryear - else: - maryear = prev_maryear +## if maryear > 0: +## if byear > 0: +## marage = maryear - byear +## if marage < 0: +## if person.get_gender() == RelLib.Person.MALE: +## error.write( _("Married before birth: %(male_name)s born %(byear)d, married %(maryear)d to %(spouse)s.\n") % { +## 'male_name' : idstr, 'byear' : byear, 'maryear' : maryear, 'spouse' : spouse.get_primary_name().get_name() } ) +## if person.get_gender() == RelLib.Person.FEMALE: +## error.write( _("Married before birth: %(female_name)s born %(byear)d, married %(maryear)d to %(spouse)s.\n") % { +## 'female_name' : idstr, 'byear' : byear, 'maryear' : maryear, 'spouse' : spouse.get_primary_name().get_name() } ) +## else: +## if marage < yngmar: +## if person.get_gender() == RelLib.Person.MALE: +## warn.write( _("Young marriage: %(male_name)s married at age %(marage)d to %(spouse)s.\n") % { +## 'male_name' : idstr, 'marage' : marage, 'spouse' : spouse.get_primary_name().get_name() } ) +## if person.get_gender() == RelLib.Person.FEMALE: +## warn.write( _("Young marriage: %(female_name)s married at age %(marage)d to %(spouse)s.\n") % { +## 'female_name' : idstr, 'marage' : marage, 'spouse' : spouse.get_primary_name().get_name() } ) +## if marage > oldmar: +## if person.get_gender() == RelLib.Person.MALE: +## warn.write( _("Old marriage: %(male_name)s married at age %(marage)d to %(spouse)s.\n") % { +## 'male_name' : idstr, 'marage' : marage, 'spouse' : spouse.get_primary_name().get_name() } ) +## if person.get_gender() == RelLib.Person.FEMALE: +## warn.write( _("Old marriage: %(female_name)s married at age %(marage)d to %(spouse)s.\n") % { +## 'female_name' : idstr, 'marage' : marage, 'spouse' : spouse.get_primary_name().get_name() } ) +## if dyear>0 and maryear > dyear: +## if person.get_gender() == RelLib.Person.MALE: +## error.write( _("Married after death: %(male_name)s died %(dyear)d, married %(maryear)d to %(spouse)s.\n") % { +## 'male_name' : idstr, 'dyear' : dyear, 'maryear' : maryear, 'spouse' : spouse.get_primary_name().get_name() } ) +## if person.get_gender() == RelLib.Person.FEMALE: +## error.write( _("Married after death: %(female_name)s died %(dyear)d, married %(maryear)d to %(spouse)s.\n") % { +## 'female_name' : idstr, 'dyear' : dyear, 'maryear' : maryear, 'spouse' : spouse.get_primary_name().get_name() } ) +## if prev_cbyear > maryear: +## if person.get_gender() == RelLib.Person.MALE: +## warn.write( _("Marriage before birth from previous family: %(male_name)s married %(maryear)d to %(spouse)s, previous birth %(prev_cbyear)d.\n") % { +## 'male_name' : idstr, 'maryear' : maryear, 'spouse' : spouse.get_primary_name().get_name(), 'prev_cbyear' : prev_cbyear } ) +## if person.get_gender() == RelLib.Person.FEMALE: +## warn.write( _("Marriage before birth from previous family: %(female_name)s married %(maryear)d to %(spouse)s, previous birth %(prev_cbyear)d.\n") % { +## 'female_name' : idstr, 'maryear' : maryear, 'spouse' : spouse.get_primary_name().get_name(), 'prev_cbyear' : prev_cbyear } ) +## prev_maryear = maryear +## else: +## maryear = prev_maryear - if maryear>0 and prev_sdyear > 0: - wdwyear = maryear-prev_sdyear - if wdwyear > lngwdw: - if person.get_gender() == RelLib.Person.MALE: - warn.write( _("Long widowhood: %s was a widower %d years before, family %s.\n") % (idstr, wdwyear, family.get_gramps_id() ) ) - if person.get_gender() == RelLib.Person.FEMALE: - warn.write( _("Long widowhood: %s was a widow %d years before, family %s.\n") % (idstr, wdwyear, family.get_gramps_id() ) ) +## if maryear>0 and prev_sdyear > 0: +## wdwyear = maryear-prev_sdyear +## if wdwyear > lngwdw: +## if person.get_gender() == RelLib.Person.MALE: +## warn.write( _("Long widowhood: %s was a widower %d years before, family %s.\n") % (idstr, wdwyear, family.get_gramps_id() ) ) +## if person.get_gender() == RelLib.Person.FEMALE: +## warn.write( _("Long widowhood: %s was a widow %d years before, family %s.\n") % (idstr, wdwyear, family.get_gramps_id() ) ) - if fnum==nfam and dyear>0 and sdyear>0: - wdwyear = dyear - sdyear - if wdwyear > lngwdw: - if person.get_gender() == RelLib.Person.MALE: - warn.write( _("Long widowhood: %s was a widower %d years.\n") % (idstr, wdwyear) ) - if person.get_gender() == RelLib.Person.FEMALE: - warn.write( _("Long widowhood: %s was a widow %d years.\n") % (idstr, wdwyear) ) +## if fnum==nfam and dyear>0 and sdyear>0: +## wdwyear = dyear - sdyear +## if wdwyear > lngwdw: +## if person.get_gender() == RelLib.Person.MALE: +## warn.write( _("Long widowhood: %s was a widower %d years.\n") % (idstr, wdwyear) ) +## if person.get_gender() == RelLib.Person.FEMALE: +## warn.write( _("Long widowhood: %s was a widow %d years.\n") % (idstr, wdwyear) ) - nkids = 0 - cbyears = [] +## nkids = 0 +## cbyears = [] - total_children = total_children + len(family.get_child_ref_list()) - for child_ref in family.get_child_ref_list(): - nkids = nkids+1 - child = self.db.get_person_from_handle(child_ref.ref) - birth_ref = child.get_birth_ref() - if birth_ref: - birth_handle = birth_ref.ref - else: - birth_handle = None +## total_children = total_children + len(family.get_child_ref_list()) +## for child_ref in family.get_child_ref_list(): +## nkids = nkids+1 +## child = self.db.get_person_from_handle(child_ref.ref) +## birth_ref = child.get_birth_ref() +## if birth_ref: +## birth_handle = birth_ref.ref +## else: +## birth_handle = None - cbyear = self.get_year( birth_handle ) - if cbyear: - cbyears.append(cbyear) +## cbyear = self.get_year( birth_handle ) +## if cbyear: +## cbyears.append(cbyear) - # parentage checks - if byear>0 and cbyear>0: - bage = cbyear - byear - if bage > oldpar: - if person.get_gender() == RelLib.Person.MALE: - warn.write( _("Old father: %(male_name)s at age of %(bage)d in family %(fam)s had a child %(child)s.\n") % { - 'male_name' : idstr, 'bage' : bage, 'fam' : family.get_handle(), 'child' : child.get_primary_name().get_name() } ) - if person.get_gender() == RelLib.Person.FEMALE: - warn.write( _("Old mother: %(female_name)s at age of %(bage)d in family %(fam)s had a child %(child)s.\n") % { - 'female_name' : idstr, 'bage' : bage, 'fam' : family.get_gramps_id(), 'child' : child.get_primary_name().get_name() } ) - if bage < 0: - if person.get_gender() == RelLib.Person.MALE: - error.write( _("Unborn father: %(male_name)s born %(byear)d, in family %(fam)s had a child %(child)s born %(cbyear)d.\n") % { - 'male_name' : idstr, 'byear' : byear, 'fam' : family.get_gramps_id(), 'child' : child.get_primary_name().get_name(), 'cbyear' : cbyear } ) - if person.get_gender() == RelLib.Person.FEMALE: - error.write( _("Unborn mother: %(female_name)s born %(byear)d, in family %(fam)s had a child %(child)s born %(cbyear)d.\n") % { - 'female_name' : idstr, 'byear' : byear, 'fam' : family.get_gramps_id(), 'child' : child.get_primary_name().get_name(), 'cbyear' : cbyear } ) - else: - if bage < yngpar: - if person.get_gender() == RelLib.Person.MALE: - warn.write( _("Young father: %(male_name)s at the age of %(bage)d in family %(fam)s had a child %(child)s.\n") % { - 'male_name' : idstr, 'bage' : bage, 'fam' : family.get_gramps_id(), 'child' : child.get_primary_name().get_name() } ) - if person.get_gender() == RelLib.Person.FEMALE: - warn.write( _("Young mother: %(female_name)s at the age of %(bage)d in family %(fam)s had a child %(child)s.\n") % { - 'female_name' : idstr, 'bage' : bage, 'fam' : family.get_gramps_id(), 'child' : child.get_primary_name().get_name() } ) - if dyear>0 and cbyear>dyear: - if cbyear-1>dyear: - if person.get_gender() == RelLib.Person.MALE: - error.write( _("Dead father: %(male_name)s died %(dyear)d, but in family %(fam)s had a child %(child)s born %(cbyear)d.\n") % { - 'male_name' : idstr, 'dyear' : dyear, 'fam' : family.get_gramps_id(), 'child' : child.get_primary_name().get_name(), 'cbyear' : cbyear} ) - if person.get_gender() == RelLib.Person.FEMALE: - error.write( _("Dead mother: %(female_name)s died %(dyear)d, but in family %(fam)s had a child %(child)s born %(cbyear)d.\n") % { - 'female_name' : idstr, 'dyear' : dyear, 'fam' : family.get_gramps_id(), 'child' : child.get_primary_name().get_name(), 'cbyear' : cbyear} ) - else: - if person.get_gender() == RelLib.Person.MALE: - warn.write( _("Dead father: %(male_name)s died %(dyear)d, but in family %(fam)s had a child %(child)s born %(cbyear)d.\n") % { - 'male_name' : idstr, 'dyear' : dyear, 'fam' : family.get_gramps_id(), 'child' : child.get_primary_name().get_name(), 'cbyear' : cbyear} ) - if person.get_gender() == RelLib.Person.FEMALE: - warn.write( _("Dead mother: %(female_name)s died %(dyear)d, but in family %(fam)s had a child %(child)s born %(cbyear)d.\n") % { - 'female_name' : idstr, 'dyear' : dyear, 'fam' : family.get_gramps_id(), 'child' : child.get_primary_name().get_name(), 'cbyear' : cbyear} ) +## # parentage checks +## if byear>0 and cbyear>0: +## bage = cbyear - byear +## if bage > oldpar: +## if person.get_gender() == RelLib.Person.MALE: +## warn.write( _("Old father: %(male_name)s at age of %(bage)d in family %(fam)s had a child %(child)s.\n") % { +## 'male_name' : idstr, 'bage' : bage, 'fam' : family.get_handle(), 'child' : child.get_primary_name().get_name() } ) +## if person.get_gender() == RelLib.Person.FEMALE: +## warn.write( _("Old mother: %(female_name)s at age of %(bage)d in family %(fam)s had a child %(child)s.\n") % { +## 'female_name' : idstr, 'bage' : bage, 'fam' : family.get_gramps_id(), 'child' : child.get_primary_name().get_name() } ) +## if bage < 0: +## if person.get_gender() == RelLib.Person.MALE: +## error.write( _("Unborn father: %(male_name)s born %(byear)d, in family %(fam)s had a child %(child)s born %(cbyear)d.\n") % { +## 'male_name' : idstr, 'byear' : byear, 'fam' : family.get_gramps_id(), 'child' : child.get_primary_name().get_name(), 'cbyear' : cbyear } ) +## if person.get_gender() == RelLib.Person.FEMALE: +## error.write( _("Unborn mother: %(female_name)s born %(byear)d, in family %(fam)s had a child %(child)s born %(cbyear)d.\n") % { +## 'female_name' : idstr, 'byear' : byear, 'fam' : family.get_gramps_id(), 'child' : child.get_primary_name().get_name(), 'cbyear' : cbyear } ) +## else: +## if bage < yngpar: +## if person.get_gender() == RelLib.Person.MALE: +## warn.write( _("Young father: %(male_name)s at the age of %(bage)d in family %(fam)s had a child %(child)s.\n") % { +## 'male_name' : idstr, 'bage' : bage, 'fam' : family.get_gramps_id(), 'child' : child.get_primary_name().get_name() } ) +## if person.get_gender() == RelLib.Person.FEMALE: +## warn.write( _("Young mother: %(female_name)s at the age of %(bage)d in family %(fam)s had a child %(child)s.\n") % { +## 'female_name' : idstr, 'bage' : bage, 'fam' : family.get_gramps_id(), 'child' : child.get_primary_name().get_name() } ) +## if dyear>0 and cbyear>dyear: +## if cbyear-1>dyear: +## if person.get_gender() == RelLib.Person.MALE: +## error.write( _("Dead father: %(male_name)s died %(dyear)d, but in family %(fam)s had a child %(child)s born %(cbyear)d.\n") % { +## 'male_name' : idstr, 'dyear' : dyear, 'fam' : family.get_gramps_id(), 'child' : child.get_primary_name().get_name(), 'cbyear' : cbyear} ) +## if person.get_gender() == RelLib.Person.FEMALE: +## error.write( _("Dead mother: %(female_name)s died %(dyear)d, but in family %(fam)s had a child %(child)s born %(cbyear)d.\n") % { +## 'female_name' : idstr, 'dyear' : dyear, 'fam' : family.get_gramps_id(), 'child' : child.get_primary_name().get_name(), 'cbyear' : cbyear} ) +## else: +## if person.get_gender() == RelLib.Person.MALE: +## warn.write( _("Dead father: %(male_name)s died %(dyear)d, but in family %(fam)s had a child %(child)s born %(cbyear)d.\n") % { +## 'male_name' : idstr, 'dyear' : dyear, 'fam' : family.get_gramps_id(), 'child' : child.get_primary_name().get_name(), 'cbyear' : cbyear} ) +## if person.get_gender() == RelLib.Person.FEMALE: +## warn.write( _("Dead mother: %(female_name)s died %(dyear)d, but in family %(fam)s had a child %(child)s born %(cbyear)d.\n") % { +## 'female_name' : idstr, 'dyear' : dyear, 'fam' : family.get_gramps_id(), 'child' : child.get_primary_name().get_name(), 'cbyear' : cbyear} ) - if cbyears: - cbyears.sort() - if (cbyears[-1] - cbyears[0]) > cbspan: - warn.write(_("Large year span for all children: family %s.\n") % family.get_gramps_id() ) - if len(cbyears) > 1: - cby_diff = [ cbyears[i+1]-cbyears[i] for i in range(len(cbyears)-1) ] - if max(cby_diff) > cspace: - warn.write(_("Large age differences between children: family %s.\n") % family.get_gramps_id() ) +## if cbyears: +## cbyears.sort() +## if (cbyears[-1] - cbyears[0]) > cbspan: +## warn.write(_("Large year span for all children: family %s.\n") % family.get_gramps_id() ) +## if len(cbyears) > 1: +## cby_diff = [ cbyears[i+1]-cbyears[i] for i in range(len(cbyears)-1) ] +## if max(cby_diff) > cspace: +## warn.write(_("Large age differences between children: family %s.\n") % family.get_gramps_id() ) - if (person.get_gender() == RelLib.Person.MALE - and total_children > mxchilddad) \ - or (person.get_gender() == RelLib.Person.FEMALE - and total_children > mxchildmom): - warn.write(_("Too many children (%(num_children)d) for %(person_name)s.\n") % { - 'num_children' : total_children, 'person_name' : idstr }) +## if (person.get_gender() == RelLib.Person.MALE +## and total_children > mxchilddad) \ +## or (person.get_gender() == RelLib.Person.FEMALE +## and total_children > mxchildmom): +## warn.write(_("Too many children (%(num_children)d) for %(person_name)s.\n") % { +## 'num_children' : total_children, 'person_name' : idstr }) if not cli: progress.step() if not cli: progress.close() - err_text = error.getvalue() - warn_text = warn.getvalue() - error.close() - warn.close() +## err_text = error.getvalue() +## warn_text = warn.getvalue() +## error.close() +## warn.close() - return err_text.strip(),warn_text.strip() + return ("","") #err_text.strip(),warn_text.strip() def print_results(self,err_text,warn_text): if warn_text: @@ -690,6 +835,566 @@ class VerifyOptions(Tool.ToolOptions): True), } +#------------------------------------------------------------------------- +# +# Base classes for different tests -- the rules +# +#------------------------------------------------------------------------- +class Rule: + """ + Basic class for use in this tool. + + Other rules must inherit from this. + """ + ERROR = 1 + WARNING = 2 + + def __init__(self,db): + self.db = db + self.hidden = False + + def broken(self): + """ + Return boolean indicating whether this rule is violated. + """ + return False + + def hide(self): + self.hidden = True + + def unhide(self): + self.hidden = False + + def get_message(self): + assert False, "Need to be overriden in the derived class" + + def get_id_str(self): + assert False, "Need to be overriden in the derived class" + + def get_level(self): + return Rule.WARNING + +class PersonRule(Rule): + """ + Person-based class. + """ + def __init__(self,db,person): + Rule.__init__(self,db) + self.obj_type = 'Person' + self.obj = person + + def get_id_str(self): + return "%s (%s)" % (self.obj.get_primary_name().get_name(), + self.obj.get_gramps_id()) + +class FamilyRule(Rule): + """ + Family-based class. + """ + def __init__(self,db,family): + Rule.__init__(self,db) + self.obj_type = 'Family' + self.obj = family() + + def get_id_str(self): + return get_family_name(self.db,self.obj) + +#------------------------------------------------------------------------- +# +# Actual rules for testing +# +#------------------------------------------------------------------------- +class BirthAfterBapt(PersonRule): + def broken(self): + birth_date = get_birth_date(self.db,self.obj) + bapt_date = get_bapt_date(self.db,self.obj) + birth_ok = birth_date > 0 + bapt_ok = bapt_date > 0 + birth_after_death = birth_date > bapt_date + return (birth_ok and bapt_ok and birth_after_death) + + def get_message(self): + return _("Baptism before birth") + +class DeathBeforeBapt(PersonRule): + def broken(self): + death_date = get_death_date(self.db,self.obj) + bapt_date = get_bapt_date(self.db,self.obj) + bapt_ok = bapt_date > 0 + death_ok = death_date > 0 + death_before_bapt = bapt_date > death_date + return (death_ok and bapt_ok and death_before_bapt) + + def get_message(self): + return _("Death before baptism") + +class BirthAfterBury(PersonRule): + def broken(self): + birth_date = get_birth_date(self.db,self.obj) + bury_date = get_bury_date(self.db,self.obj) + birth_ok = birth_date > 0 + bury_ok = bury_date > 0 + birth_after_bury = birth_date > bury_date + return (birth_ok and bury_ok and birth_after_bury) + + def get_message(self): + return _("Burial before birth") + +class DeathAfterBury(PersonRule): + def broken(self): + death_date = get_death_date(self.db,self.obj) + bury_date = get_bury_date(self.db,self.obj) + death_ok = death_date > 0 + bury_ok = bury_date > 0 + death_after_bury = death_date > bury_date + return (death_ok and bury_ok and death_after_bury) + + def get_message(self): + return _("Burial before death") + +class BirthAfterDeath(PersonRule): + def broken(self): + birth_date = get_birth_date(self.db,self.obj) + death_date = get_death_date(self.db,self.obj) + birth_ok = birth_date > 0 + death_ok = death_date > 0 + birth_after_death = birth_date > death_date + return (birth_ok and death_ok and birth_after_death) + + def get_message(self): + return _("Death before birth") + +class BaptAfterBury(PersonRule): + def broken(self): + bapt_date = get_bapt_date(self.db,self.obj) + bury_date = get_bury_date(self.db,self.obj) + bapt_ok = bapt_date > 0 + bury_ok = bury_date > 0 + bapt_after_bury = bapt_date > bury_date + return (bapt_ok and bury_ok and bapt_after_bury) + + def get_message(self): + return _("Burial before baptism") + +class OldAge(PersonRule): + def __init__(self,db,person,old_age): + PersonRule.__init__(self,db,person) + self.old_age = old_age + + def broken(self): + age_at_death = get_age_at_death(self.db,self.obj) + return (age_at_death > self.old_age) + + def get_message(self): + return _("Old age at death") + +class UnknownGender(PersonRule): + def broken(self): + female = self.obj.get_gender() == RelLib.Person.FEMALE + male = self.obj.get_gender() == RelLib.Person.MALE + return (male or female) + + def get_message(self): + return _("Unknown gender") + +class MultipleParents(PersonRule): + def broken(self): + n_parent_sets = len(self.obj.get_parent_family_handle_list()) + return (n_parent_sets>1) + + def get_message(self): + return _("Multiple parents") + +class MarriedOften(PersonRule): + def __init__(self,db,person,wedder): + PersonRule.__init__(self,db,person) + self.wedder = wedder + + def broken(self): + n_spouses = len(self.obj.get_family_handle_list()) + return (n_spouses>self.wedder) + + def get_message(self): + return _("Married often") + +class OldUnmarried(PersonRule): + def __init__(self,db,person,old_unm): + PersonRule.__init__(self,db,person) + self.old_unm = old_unm + + def broken(self): + age_at_death = get_age_at_death(self.db,self.obj) + n_spouses = len(self.obj.get_family_handle_list()) + return (age_at_death>self.old_unm and n_spouses==0) + + def get_message(self): + return _("Old and unmarried") + +class SameSexFamily(FamilyRule): + def broken(self): + mother = get_mother(self.db,self.obj) + father = get_father(self.db,self.obj) + same_sex = (mother.get_gender() == father.get_gender()) + unknown_sex = (mother.get_gender() == RelLib.Person.UNKNOWN) + return (same_sex and not unknown_sex) + + def get_message(self): + return _("Same sex marriage") + +class FemaleHusband(FamilyRule): + def broken(self): + father = get_father(self.db,self.obj) + return (father.get_gender() == RelLib.Person.FEMALE) + + def get_message(self): + return _("Female husband") + +class MaleWife(FamilyRule): + def broken(self): + mother = get_mother(self.db,self.obj) + return (mother.get_gender() == RelLib.Person.MALE) + + def get_message(self): + return _("Male wife") + +class SameSurnameFamily(FamilyRule): + def broken(self): + mother = get_mother(self.db,self.obj) + father = get_father(self.db,self.obj) + same_surname = (mother.get_primary_name().get_surname() == + father.get_primary_name().get_surname()) + empty_surname = len(mother.get_primary_name().get_surname())==0 + return (same_surname and not empty_surname) + + def get_message(self): + return _("Husband and wife with the same surname") + +class LargeAgeGapFamily(FamilyRule): + def __init__(self,db,obj,hw_diff): + FamilyRule.__init__(self,db,obj) + self.hw_diff = hw_diff + + def broken(self): + mother = get_mother(self.db,self.obj) + father = get_father(self.db,self.obj) + mother_birth_date = get_birth_date(self.db,mother) + father_birth_date = get_birth_date(self.db,father) + mother_birth_date_ok = mother_birth_date > 0 + father_birth_date_ok = father_birth_date > 0 + large_diff = abs(father_birth_date-mother_birth_date) > self.hw_diff + return (mother_birth_date_ok and father_birth_date_ok and large_diff) + + def get_message(self): + return _("Large age difference between husband and wife") + +class MarriageBeforeBirth(FamilyRule): + def broken(self): + marr_date = get_marriage_date(self.db,self.obj) + marr_date_ok = marr_date > 0 + + mother = get_mother(self.db,self.obj) + father = get_father(self.db,self.obj) + mother_birth_date = get_birth_date(self.db,mother) + father_birth_date = get_birth_date(self.db,father) + mother_birth_date_ok = mother_birth_date > 0 + father_birth_date_ok = father_birth_date > 0 + + father_broken = (father_birth_date_ok and marr_date_ok + and (father_birth_date > marr_date)) + mother_broken = (mother_birth_date_ok and marr_date_ok + and (mother_birth_date > marr_date)) + + return (father_broken or mother_broken) + + def get_message(self): + return _("Marriage before birth") + +class MarriageAfterDeath(FamilyRule): + def broken(self): + marr_date = get_marriage_date(self.db,self.obj) + marr_date_ok = marr_date > 0 + + mother = get_mother(self.db,self.obj) + father = get_father(self.db,self.obj) + mother_death_date = get_death_date(self.db,mother) + father_death_date = get_death_date(self.db,father) + mother_death_date_ok = mother_death_date > 0 + father_death_date_ok = father_death_date > 0 + + father_broken = (father_death_date_ok and marr_date_ok + and (father_death_date > marr_date)) + mother_broken = (mother_death_date_ok and marr_date_ok + and (mother_death_date > marr_date)) + + return (father_broken or mother_broken) + + def get_message(self): + return _("Marriage after death") + +class EarlyMarriage(FamilyRule): + def __init__(self,db,obj,yng_mar): + FamilyRule__init__(self,db,obj) + self.yng_mar = yng_mar + + def broken(self): + marr_date = get_marriage_date(self.db,self.obj) + marr_date_ok = marr_date > 0 + + mother = get_mother(self.db,self.obj) + father = get_father(self.db,self.obj) + mother_birth_date = get_birth_date(self.db,mother) + father_birth_date = get_birth_date(self.db,father) + mother_birth_date_ok = mother_birth_date > 0 + father_birth_date_ok = father_birth_date > 0 + + father_broken = (father_birth_date_ok and marr_date_ok + and (marr_date - father_birth_date < self.yng_mar)) + mother_broken = (mother_birth_date_ok and marr_date_ok + and (marr_date - mother_birth_date < self.yng_mar)) + + return (father_broken or mother_broken) + + def get_message(self): + return _("Early marriage") + +class LateMarriage(FamilyRule): + def __init__(self,db,obj,old_mar): + FamilyRule__init__(self,db,obj) + self.old_mar = old_mar + + def broken(self): + marr_date = get_marriage_date(self.db,self.obj) + marr_date_ok = marr_date > 0 + + mother = get_mother(self.db,self.obj) + father = get_father(self.db,self.obj) + mother_birth_date = get_birth_date(self.db,mother) + father_birth_date = get_birth_date(self.db,father) + mother_birth_date_ok = mother_birth_date > 0 + father_birth_date_ok = father_birth_date > 0 + + father_broken = (father_birth_date_ok and marr_date_ok + and (marr_date - father_birth_date > self.old_mar)) + mother_broken = (mother_birth_date_ok and marr_date_ok + and (marr_date - mother_birth_date > self.old_mar)) + + return (father_broken or mother_broken) + + def get_message(self): + return _("Late marriage") + +## class MarriageBeforePrefiousMarrChild(PersonRule): +## def broken(self): +## marr_date = get_marriage_date(self.obj) +## prev_marr_child_date = get_prev_marr_child_date(self.obj) +## return (prev_marr_child_date>marr_date) + +## def get_message(self): +## return _("Marriage before having a child from previous marriage") + +## class LongWidowhood(FamilyRule): +## def broken(self): +## marr_date = get_marriage_date(self.obj) +## prev_marr_spouse_death_date = get_prev_marr_spouse_death_date(self.obj) +## birth_date = get_birth_date(self.obj) +## return (marr_date-prev_marr_spouse_death_date>lngwdw) + +## def get_message(self): +## return _("Long Windowhood") + +class OldParent(FamilyRule): + def __init__(self,db,obj,old_par): + FamilyRule__init__(self,db,obj) + self.old_par = old_par + + def broken(self): + mother = get_mother(self.db,self.obj) + father = get_father(self.db,self.obj) + mother_birth_date = get_birth_date(self.db,mother) + father_birth_date = get_birth_date(self.db,father) + mother_birth_date_ok = mother_birth_date > 0 + father_birth_date_ok = father_birth_date > 0 + + for child_ref in self.obj.get_child_ref_list(): + child = find_person(self.db,child_ref.ref) + child_birth_date = get_birth_date(self.db,child) + child_birth_date_ok = child_birth_date > 0 + if not child_birth_date_ok: + continue + father_broken = (father_birth_date_ok and ( + father_birth_date - child_birth_date > self.old_par)) + if father_broken: + self.get_message = self.father_message + return True + + mother_broken = (mother_birth_date_ok and ( + mother_birth_date - child_birth_date > self.old_par)) + if mother_broken: + self.get_message = self.mother_message + return True + return False + + def father_message(self): + return _("Old father") + + def mother_message(self): + return _("Old mother") + +class YoungParent(FamilyRule): + def __init__(self,db,obj,yng_par): + FamilyRule__init__(self,db,obj) + self.yng_par = yng_par + + def broken(self): + mother = get_mother(self.db,self.obj) + father = get_father(self.db,self.obj) + mother_birth_date = get_birth_date(self.db,mother) + father_birth_date = get_birth_date(self.db,father) + mother_birth_date_ok = mother_birth_date > 0 + father_birth_date_ok = father_birth_date > 0 + + for child_ref in self.obj.get_child_ref_list(): + child = find_person(self.db,child_ref.ref) + child_birth_date = get_birth_date(self.db,child) + child_birth_date_ok = child_birth_date > 0 + if not child_birth_date_ok: + continue + father_broken = (father_birth_date_ok and ( + father_birth_date - child_birth_date < self.yng_par)) + if father_broken: + self.get_message = self.father_message + return True + + mother_broken = (mother_birth_date_ok and ( + mother_birth_date - child_birth_date < self.yng_par)) + if mother_broken: + self.get_message = self.mother_message + return True + return False + + def father_message(self): + return _("Young father") + + def mother_message(self): + return _("Young mother") + +class UnbornParent(FamilyRule): + def broken(self): + mother = get_mother(self.db,self.obj) + father = get_father(self.db,self.obj) + mother_birth_date = get_birth_date(self.db,mother) + father_birth_date = get_birth_date(self.db,father) + mother_birth_date_ok = mother_birth_date > 0 + father_birth_date_ok = father_birth_date > 0 + + for child_ref in self.obj.get_child_ref_list(): + child = find_person(self.db,child_ref.ref) + child_birth_date = get_birth_date(self.db,child) + child_birth_date_ok = child_birth_date > 0 + if not child_birth_date_ok: + continue + father_broken = (father_birth_date_ok + and (father_birth_date > child_birth_date)) + if father_broken: + self.get_message = self.father_message + return True + + mother_broken = (mother_birth_date_ok + and (mother_birth_date > child_birth_date)) + if mother_broken: + self.get_message = self.mother_message + return True + + def father_message(self): + return _("Unborn father") + + def mother_message(self): + return _("Unborn mother") + +class DeadParent(FamilyRule): + def broken(self): + mother = get_mother(self.db,self.obj) + father = get_father(self.db,self.obj) + mother_death_date = get_death_date(self.db,mother) + father_death_date = get_death_date(self.db,father) + mother_death_date_ok = mother_death_date > 0 + father_death_date_ok = father_death_date > 0 + + for child_ref in self.obj.get_child_ref_list(): + child = find_person(self.db,child_ref.ref) + child_birth_date = get_birth_date(self.db,child) + child_birth_date_ok = child_birth_date > 0 + if not child_birth_date_ok: + continue + father_broken = (father_death_date_ok + and (father_death_date < child_birth_date)) + if father_broken: + self.get_message = self.father_message + return True + + mother_broken = (mother_death_date_ok + and (mother_death_date < child_birth_date)) + if mother_broken: + self.get_message = self.mother_message + return True + + def father_message(self): + return _("Dead father") + + def mother_message(self): + return _("Dead mother") + +class LargeChildrenSpan(FamilyRule): + def __init__(self,db,obj,cb_span): + FamilyRule__init__(self,db,obj) + self.cb_span = cb_span + + def broken(self): + child_birh_dates = get_child_birth_dates(self.db,self.obj) + child_birh_dates.sort() + + return (child_birh_dates[-1] - child_birh_dates[0] > self.cb_span) + + def get_message(self): + return _("Large year span for all children") + +class LargeChildrenAgeDiff(FamilyRule): + def __init__(self,db,obj,c_space): + FamilyRule__init__(self,db,obj) + self.c_space = c_space + + def broken(self): + child_birh_dates = get_child_birth_dates(self.db,self.obj) + child_birh_dates_diff = [child_birh_dates[i+1] - child_birh_dates[i] + for i in range(len(child_birh_dates)-1) ] + + return (max(child_birh_dates_diff) < self.c_space) + + def get_message(self): + return _("Large age differences between children") + +class TooManyChildren(PersonRule): + def __init__(self,db,obj,mx_child_dad,mx_child_mom): + PersonRule.__init__(self,db,obj) + self.mx_child_dad = mx_child_dad + self.mx_child_mom = mx_child_mom + + def broken(self): + n_child = get_n_children(self.db,self.obj) + + if (self.obj.get_gender == RelLib.Person.MALE) \ + and (n_child > self.mx_child_dad): + return True + + if (self.obj.get_gender == RelLib.Person.FEMALE) \ + and (n_child > self.mx_child_mom): + return True + + return False + + def get_message(self): + return _("Too many children") + #------------------------------------------------------------------------- # #