def birth_before_parents_death(individuals_dict, families_dict):
    result_error_messages = list()
    for family_id, family_info in families_dict.items():
        husb_info = individuals_dict[family_info['HUSB']]
        wife_info = individuals_dict[family_info['WIFE']]
        if husb_info.get('DEAT') != None and husb_info.get('DEAT') != 'NA':
            if family_info.get('CHIL') != None and family_info.get('CHIL') != 'NA':
                for child in family_info.get('CHIL'):

                    child_info = individuals_dict[child]
                    if husb_info.get('DEAT') == "NA" or type(husb_info.get('DEAT').date_time_obj) is str or child_info.get('BIRT') == "NA" or type(child_info.get('BIRT')) is str:
                        pass
                    else:
                        try:
                            if Date.get_dates_difference(child_info.get('BIRT').date_time_obj, husb_info.get('DEAT').date_time_obj) < 0:
                                raise ValueError(f"ERROR: US09: {family_id}: Husband died before the birth of his child")
                        except ValueError as e:
                            result_error_messages.append(f"ERROR: US09: {family_id}: Husband died before the birth of his child")
                            print(e)

        if wife_info.get('DEAT') != None and wife_info.get('DEAT') != 'NA':
            if family_info.get('CHIL') != None and family_info.get('CHIL') != 'NA':
                for child in family_info.get('CHIL'):
                    child_info = individuals_dict[child]
                    if wife_info.get('DEAT') == "NA" or type(wife_info.get('DEAT').date_time_obj) is str or child_info.get('BIRT') == "NA" or type(child_info.get('BIRT')) is str:
                        pass
                    else:
                        try:
                            if Date.get_dates_difference(child_info.get('BIRT').date_time_obj, wife_info.get('DEAT').date_time_obj) < 0:
                                raise ValueError(f"ERROR: US09: {family_id} Wife died before the birth of her child")
                        except ValueError as e:
                            result_error_messages.append(f"ERROR: US09: {family_id} Wife died before the birth of her child")
                            print(e)
    return result_error_messages
def check_150_years_age(individual_info_dict):

    age_limit = 150

    # gets dates from individual info
    for individual_id, individual_info in individual_info_dict.items():
        id = individual_id
        birth_date = Date(str(individual_info.get("BIRT")))
        if individual_info.get("DEAT") not in [None, 'NA']:
            death_date = Date(str(individual_info.get("DEAT")))
        else:
            death_date = None

        # calculates age with the dates
        if death_date == None and birth_date != None:
            age = Date.get_dates_difference(birth_date.date_time_obj)
        else:
            if death_date != None and birth_date != None:
                age = Date.get_dates_difference(birth_date.date_time_obj,
                                                death_date.date_time_obj)

        # checks to see if age exceeds age limit and prints error
        if type(age) is not str and age > age_limit and death_date == None:
            print(
                'ERROR: INDIVIDUAL: US07: {}: More than 150 years old - Birth date {}'
                .format(id, birth_date))
        elif type(age) is not str and age > age_limit and death_date != None:
            print(
                'ERROR: INDIVIDUAL: US07: {}: More than 150 years old at death - Birth date {}: Death date {}'
                .format(id, birth_date, death_date))
def print_individuals_pretty_table(individuals_dict, test=False):
    pt = PrettyTable(field_names=[
                     "ID", "Name", "Gender", "Birthday", "Age", "Alive", "Death", "Child", "Spouse"])
    for individual_id, individual_info in individuals_dict.items():
        individual_info["ALIVE"] = individual_info.get("DEAT") == None
        if individual_info.get("BIRT") != None:
            birth_date = individual_info.get("BIRT").date_time_obj
        death_date = None
        if individual_info.get("DEAT") != None:
            death_date = individual_info.get("DEAT").date_time_obj
        individual_info["AGE"] = Date.get_dates_difference(birth_date, death_date)
        individual_info["FAMC"] = individual_info.get(
            "FAMC") if individual_info.get("FAMC") != None else "NA"
        individual_info["FAMS"] = individual_info.get(
            "FAMS") if individual_info.get("FAMS") != None else "NA"
        individual_info["DEAT"] = individual_info.get(
            "DEAT") if individual_info.get("DEAT") != None else "NA"
        individual_info_list = [individual_id]
        for key in get_individual_pretty_Table_order():
            individual_info_list.append(individual_info.get(key))
        pt.add_row(individual_info_list)

    if test:
        return individuals_dict
    else:
        print(pt)
Esempio n. 4
0
def us01(individuals, families):
    """ Check US01 Dates (birth, marriage, divorce, death) should not be after the current date."""

    errors = dict()
    i = 0

    for ind_id, ind in individuals.items(
    ):  # each ind is dict with the attributes of the individual
        error1, error2, error3, error4 = False, False, False, False
        if type(ind['BIRT'].date_time_obj) is not str:
            if ind['BIRT'] != 'NA':
                if Date.get_dates_difference(ind['BIRT'].date_time_obj) < 0:
                    print(
                        f"US01: Error: Individual's '{ind_id}' birthday '{ind['BIRT'].date_time_obj.strftime('%d %b %Y')}' occurs in the future."
                    )
                    error1 = True

        if ind['DEAT'] != 'NA' and type(ind['DEAT'].date_time_obj) is not str:
            if Date.get_dates_difference(ind['DEAT'].date_time_obj) < 0:
                print(
                    f"US01: Error: Individual's '{ind_id}' death date '{ind['DEAT'].date_time_obj.strftime('%d %b %Y')}' occurs in the future."
                )
                error2 = True

        if ind['FAMS'] != 'NA':
            if families[ind['FAMS']]['MARR'] != "NA" and type(
                    families[ind['FAMS']]['MARR'].date_time_obj) is not str:
                if families[ind['FAMS']]['MARR'] != 'NA':
                    if Date.get_dates_difference(
                            families[ind['FAMS']]['MARR'].date_time_obj) < 0:
                        print(
                            f"US01: Error: Individual's '{ind_id}' marriage date '{families[ind['FAMS']]['MARR'].date_time_obj.strftime('%d %b %Y')}' occurs in the future."
                        )
                        error3 = True

            if families[ind['FAMS']]['DIV'] != 'NA' and type(
                    families[ind['FAMS']]['DIV'].date_time_obj) is not str:
                if Date.get_dates_difference(
                        families[ind['FAMS']]['DIV'].date_time_obj) < 0:
                    print(
                        f"US01: Error: Individual's '{ind_id}' divorce date '{families[ind['FAMS']]['DIV'].date_time_obj.strftime('%d %b %Y')}' occurs in the future."
                    )
                    error4 = True

        errors[i] = [error1, error2, error3, error4]
        i += 1
    return errors
Esempio n. 5
0
def us34(individuals, families, fam_id='', test=False):
    """ List all couples who were married when the older spouse was more than twice as old as the younger spouse. """

    if test:
        errors = list()
        error1, error2 = False, False
        if families[fam_id]['HUSB'] != 'NA' and Date.is_valid_date(
                individuals[families[fam_id]['HUSB']]['BIRT'].date_time_obj):
            husb_id = families[fam_id]['HUSB']
            husb_bd = individuals[husb_id]['BIRT'].date_time_obj
        if families[fam_id]['WIFE'] != 'NA' and Date.is_valid_date(
                individuals[families[fam_id]['WIFE']]['BIRT'].date_time_obj):
            wife_id = families[fam_id]['WIFE']
            wife_bd = individuals[wife_id]['BIRT'].date_time_obj
        if families[fam_id]['MARR'] != 'NA' and Date.is_valid_date(
                families[fam_id]['MARR'].date_time_obj):
            marr_dt = families[fam_id]['MARR'].date_time_obj
        check = [husb_bd, wife_bd, marr_dt]
        if None not in check:
            if Date.get_dates_difference(husb_bd, marr_dt) > (
                    2 * Date.get_dates_difference(wife_bd, marr_dt)):
                error1 = True
            elif Date.get_dates_difference(wife_bd, marr_dt) > (
                    2 * Date.get_dates_difference(husb_bd, marr_dt)):
                error2 = True
        errors = [error1, error2]
        return errors
    else:
        husb_bd, wife_bd, marr_dt = None, None, None
        for fam_id, fam in families.items():
            if fam['HUSB'] != 'NA' and Date.is_valid_date(
                    individuals[fam['HUSB']]['BIRT'].date_time_obj):
                husb_id = fam['HUSB']
                husb_bd = individuals[husb_id]['BIRT'].date_time_obj
            if fam['WIFE'] != 'NA' and Date.is_valid_date(
                    individuals[fam['WIFE']]['BIRT'].date_time_obj):
                wife_id = fam['WIFE']
                wife_bd = individuals[wife_id]['BIRT'].date_time_obj
            if fam['MARR'] != 'NA' and Date.is_valid_date(
                    fam['MARR'].date_time_obj):
                marr_dt = fam['MARR'].date_time_obj
            check = [husb_bd, wife_bd, marr_dt]
            if None not in check:
                if Date.get_dates_difference(husb_bd, marr_dt) > (
                        2 * Date.get_dates_difference(wife_bd, marr_dt)):
                    print(
                        f"US34: Husband '{husb_id}' was more than twice as old as wife '{wife_id}' in family '{fam_id}' on marriage date '{marr_dt}'."
                    )
                elif Date.get_dates_difference(wife_bd, marr_dt) > (
                        2 * Date.get_dates_difference(husb_bd, marr_dt)):
                    print(
                        f"US34: Wife '{wife_id}' was more than twice as old as wife '{husb_id}' in family '{fam_id}' on marriage date '{marr_dt}'."
                    )
        return None
Esempio n. 6
0
 def us10(dt1, dt2):
     """ Check US10 Marriage should be at least 14 years after birth of both spouses (parents must be at least 14 years old) """
     try:
         date_diff = Date.get_dates_difference(dt1.date_time_obj,
                                               dt2.date_time_obj)
         if type(date_diff) is str:
             raise ValueError
         if date_diff >= 14:
             return False
         if date_diff < 14:
             return True
     except:
         print("Data Error:", dt1, dt2)
Esempio n. 7
0
def date_before(dt1, dt2):
    """ Send two dates to Date class for comparison """

    try:
        date_diff = Date.get_dates_difference(dt1.date_time_obj,
                                              dt2.date_time_obj)
        if type(date_diff) is str:
            raise ValueError
        if date_diff >= 0:
            return False
        if date_diff <= -1:
            return True
    except:
        print('Data Error', dt1, dt2)
def us10(dt1, dt2, spouse, fam_id):
    """ Check US10 Marriage should be at least 14 years after birth of both spouses (parents must be at least 14 years old) """

    try:
        date_diff = Date.get_dates_difference(dt1.date_time_obj,
                                              dt2.date_time_obj)
        if type(date_diff) is str:
            raise ValueError
        if date_diff >= 14:
            return False
        if date_diff < 14:
            return True
    except:
        print(
            f"Data Error: Birth date '{dt1}' and marriage date '{dt2}' for '{spouse}' in family '{fam_id}' are not in a compatible format."
        )
def us03(individuals, test=False):
    """ Check US03 Birth should occur before death of an individual."""

    for ind_id, ind in individuals.items(
    ):  # each ind is dict with the attributes of the individual
        if ind['BIRT'] != 'NA':
            birth_dt = ind['BIRT'].date_time_obj
        if ind['DEAT'] != 'NA':
            death_dt = ind['DEAT'].date_time_obj
            if Date.get_dates_difference(birth_dt, death_dt) < 0:
                print(
                    f"US03: Error: Individual's '{ind_id}' birthday '{ind['BIRT'].date_time_obj.strftime('%d %b %Y')}' occurs after the death date '{ind['DEAT'].date_time_obj.strftime('%d %b %Y')}'."
                )
                if test:
                    return ind_id
                else:
                    return None
Esempio n. 10
0
def us03(individuals):
    """ Check US03 Birth should occur before death of an individual."""

    i = 0
    errors = dict()
    for ind_id, ind in individuals.items(
    ):  # each ind is dict with the attributes of the individual
        errors[i] = False
        if type(ind['BIRT'].date_time_obj) is not str and type(
                ind['DEAT']) is not str and type(
                    ind['DEAT'].date_time_obj) is not str:
            if ind['BIRT'] != 'NA':
                birth_dt = ind['BIRT'].date_time_obj
            if ind['DEAT'] != 'NA':
                death_dt = ind['DEAT'].date_time_obj
                if Date.get_dates_difference(birth_dt, death_dt) < 0:
                    print(
                        f"US03: Error: Individual's '{ind_id}' birthday '{ind['BIRT'].date_time_obj.strftime('%d %b %Y')}' occurs after the death date '{ind['DEAT'].date_time_obj.strftime('%d %b %Y')}'."
                    )
                    errors[i] = True
        i += 1

    return errors
Esempio n. 11
0
def check_parents_not_too_old(individual_info_dict, family_info_dict):
    for family_id, family_info in family_info_dict.items():
        wife_id = family_info.get('WIFE')
        husband_id = family_info.get('HUSB')
        children = family_info.get('CHIL')
        husb_dict = individual_info_dict.get(husband_id)
        wife_dict = individual_info_dict.get(wife_id)
        husb_birth_date = Date(str(husb_dict.get('BIRT')))
        wife_birth_date = Date(str(wife_dict.get('BIRT')))
        parents_too_old = False
        if children not in [None, 'NA']:
            for child in children:
                child_dict = individual_info_dict.get(child)
                birth_date = Date(str(child_dict.get('BIRT')))
                
                too_old_age_difference = 65
                if type(husb_birth_date) is not str and husb_birth_date != None and type(husb_birth_date.date_time_obj) is not str and type(husb_birth_date.date_time_obj) is not str:
                    if type(wife_birth_date) is not str and wife_birth_date != None and type(wife_birth_date.date_time_obj) is not str and type(wife_birth_date.date_time_obj) is not str:
                        if type(birth_date) is not str and birth_date != None and type(birth_date.date_time_obj) is not str and type(birth_date.date_time_obj) is not str:
                            if Date.get_dates_difference(husb_birth_date.date_time_obj, birth_date.date_time_obj) > too_old_age_difference or Date.get_dates_difference(wife_birth_date.date_time_obj, birth_date.date_time_obj) > too_old_age_difference:
                                parents_too_old = True
                    
        if parents_too_old == True:
            print('ANOMOLY: FAMILY: US12: {}: Parents are too old: Parent(s) were greater than 65 years old when child was born'.format(family_id))