コード例 #1
0
def us28(children, num_chil, fam_id, individuals, test=False):
    """ List siblings in families by decreasing age, i.e. oldest siblings first. """
    # Needs Revision: import from gedcom_file_parser and use print_individuals_pretty_table function?

    birth_order = defaultdict(list)
    for i in range(num_chil):
        bd_key = individuals[children[i]]['BIRT'].date_time_obj
        if Date.is_valid_date(bd_key):
            if bd_key not in birth_order:
                birth_order[bd_key] = [children[i]]
            else:
                birth_order[bd_key].append(children[i])

    print(f"US28: List: Eldest to youngest children in family '{fam_id}'.")
    pt = PrettyTable(field_names=["ID", "Name", "Date of Birth"])
    for birthdate, child_list in sorted(birth_order.items(), reverse=False):
        child_list_len = len(child_list)
        if child_list_len == 1:
            child_info = [
                child_list[0], individuals[child_list[0]]['NAME'],
                birthdate.strftime('%d %b %Y')
            ]
            pt.add_row(child_info)
        elif child_list_len > 1:
            for i in range(child_list_len):
                child_info = [
                    child_list[i], individuals[child_list[i]]['NAME'],
                    birthdate.strftime('%d %b %Y')
                ]
                pt.add_row(child_info)

    if test:
        return str(pt)
    else:
        print(pt)
コード例 #2
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
コード例 #3
0
def us35(individuals, test=False):
    """ List all people in a GEDCOM file who were born in the last 30 days. """

    print(
        'US35: List:  The following people were born within the last 30 days')
    pt = PrettyTable(field_names=["ID", "Name", "Date of Birth"])
    for ind_id, ind in individuals.items():
        if Date.is_valid_date(ind['BIRT'].date_time_obj):
            diff, time_typ = get_dates_diff(ind['BIRT'].date_time_obj)
            if time_typ == 'days' and diff <= 30:
                recent_births = [
                    ind_id, ind['NAME'],
                    (ind['BIRT'].date_time_obj).strftime('%d %b %Y')
                ]
                pt.add_row(recent_births)

    if test:
        return (str(pt))
    else:
        print(pt)
        return None
コード例 #4
0
def us36(individuals, families, test=False):
    """ List all people in a GEDCOM file who died in the last 30 days. """
    def us37(ind_id, individuals, families, test=False):
        """ List all living spouses and descendants of people in a GEDCOM file who died in the last 30 days. """
        def get_descendants(ind_id, individuals, families, so_far=None):
            """ return a set of individual ids of all descendants of ind_id """
            if so_far is None:
                descendants = set()
            else:
                descendants = so_far  # the descendants we've already checked

            if individuals[ind_id]['FAMS'] != 'NA':
                # get the descendants for all of ind_id's children
                fam_id = individuals[ind_id]['FAMS']
                if families[fam_id]['CHIL'] != 'NA':
                    child_in_desc = False
                    for child in families[fam_id]['CHIL']:
                        if child not in descendants:
                            descendants.add(
                                child)  # this child is a descendant
                            descendants.update(
                                get_descendants(child, individuals, families,
                                                descendants)
                            )  # add all of the children of child to the set as well
                        else:
                            child_in_desc = True
                    if child_in_desc == True:
                        print(
                            f"US37: WARNING: {ind_id} is a descendant of him/her self in {fam_id}"
                        )
            return descendants

        if individuals[ind_id]['FAMS'] != 'NA':
            pt = PrettyTable(field_names=["ID", "Name", "Relation"])
            fam_id = individuals[ind_id]['FAMS']
            if families[fam_id]['WIFE'] == ind_id:
                if families[fam_id]['HUSB'] != 'NA':
                    relation = 'Husband'
                    recent_survivor = [
                        families[fam_id]['HUSB'], families[fam_id]['HNAME'],
                        relation
                    ]
                    pt.add_row(recent_survivor)
            elif families[fam_id]['HUSB'] == ind_id:
                if families[fam_id]['WIFE'] != 'NA':
                    relation = 'Wife'
                    recent_survivor = [
                        families[fam_id]['WIFE'], families[fam_id]['WNAME'],
                        relation
                    ]
                    pt.add_row(recent_survivor)

            descendants = get_descendants(ind_id, individuals, families)
            if len(descendants) > 0:
                for child in descendants:
                    recent_survivor = [
                        child, individuals[child]['NAME'], 'Descendant'
                    ]
                    pt.add_row(recent_survivor)

            if test:
                return str(pt)
            else:
                print(
                    f"US37: List:  The following people are living spouses and descendents of '{individuals[ind_id]['NAME']}' who died within the last 30 days"
                )
                print(pt)
                return None
        # End US37

    pt = PrettyTable(field_names=["ID", "Name", "Date of Death"])
    for ind_id, ind in individuals.items():
        if ind['DEAT'] != 'NA' and Date.is_valid_date(
                ind['DEAT'].date_time_obj):
            diff, time_typ = get_dates_diff(ind['DEAT'].date_time_obj)
            if time_typ == 'days' and diff <= 30:
                us37_test = us37(ind_id, individuals, families, test)
                recent_deaths = [
                    ind_id, ind['NAME'],
                    (ind['DEAT'].date_time_obj).strftime('%d %b %Y')
                ]
                pt.add_row(recent_deaths)

    if test:
        return str(pt), us37_test
    else:
        print('US36: List:  The following people died within the last 30 days')
        print(pt)
        return None
コード例 #5
0
def us13(children, num_chil, fam_id, individuals, test=False):
    """ Birth dates of siblings should be more than 8 months apart or less than 2 days apart. """

    if test:
        error1, error2 = False, False
        error3 = ''
        errors = list()
        bd_dict = defaultdict(list)
        for i in range(num_chil):
            bd_key = individuals[children[i]]['BIRT'].date_time_obj
            if Date.is_valid_date(bd_key):
                if bd_key not in bd_dict:
                    bd_dict[bd_key] = [children[i]]
                else:
                    bd_dict[bd_key].append(children[i])

        test_next = True

        for bd_child, child in sorted(bd_dict.items(), reverse=True):
            error = False
            if len(bd_dict[bd_child]) == 1:
                if test_next:
                    bd_sib1 = bd_child
                    child1 = child
                    test_next = False
                else:
                    bd_sib2 = bd_child
                    child2 = child
                    diff, time_typ = get_dates_diff(bd_sib1, bd_sib2)
                    if time_typ == 'years':
                        continue
                    elif time_typ == 'months' and diff < 8:
                        print(
                            f"US13: Error: Child '{child1}' and Child '{child2}' in family '{fam_id}' are born more than 2 days and less than 8 months apart."
                        )
                        error1 = True
                    elif time_typ == 'days' and diff > 2:
                        print(
                            f"US13: Error: Child '{child1}' and Child '{child2}' in family '{fam_id}' are born more than 2 days and less than 8 months apart."
                        )
                        error1 = True
                    test_next = True

            elif len(bd_dict[bd_child]) > 1:
                error2, error3 = us14(len(bd_dict[bd_child]), bd_child,
                                      bd_dict[bd_child], fam_id, individuals,
                                      test)
                test_next = True

        errors = [error1, error2, error3]
        return errors
    else:
        bd_dict = defaultdict(list)
        for i in range(num_chil):
            bd_key = individuals[children[i]]['BIRT'].date_time_obj
            if Date.is_valid_date(bd_key):
                if bd_key not in bd_dict:
                    bd_dict[bd_key] = [children[i]]
                else:
                    bd_dict[bd_key].append(children[i])

        test_next = True

        for bd_child, child in sorted(bd_dict.items(), reverse=True):
            if len(bd_dict[bd_child]) == 1:
                if test_next:
                    bd_sib1 = bd_child
                    child1 = child
                    test_next = False
                else:
                    bd_sib2 = bd_child
                    child2 = child
                    diff, time_typ = get_dates_diff(bd_sib1, bd_sib2)
                    if time_typ == 'years':
                        continue
                    elif time_typ == 'months' and diff < 8:
                        print(
                            f"US13: Error: Child '{child1}' and Child '{child2}' in family '{fam_id}' are born more than 2 days and less than 8 months apart."
                        )
                    elif time_typ == 'days' and diff > 2:
                        print(
                            f"US13: Error: Child '{child1}' and Child '{child2}' in family '{fam_id}' are born more than 2 days and less than 8 months apart."
                        )
                    test_next = True

            elif len(bd_dict[bd_child]) > 1:
                test_next = True