def us34(indi, fam, f):
    print("Userstory 34 Running")
    flag = True
    for family in fam:
        # getting birthdates of both spouses
        husb_bdate = getIndiByID(indi, family['HUSB'])['BIRT']
        wife_bdate = getIndiByID(indi, family['WIFE'])['BIRT']

        days_in_year = 365.2425
        husb_age_at_marr = abs(int((family['MARR'] - husb_bdate).days / days_in_year))
        wife_age_at_marr = abs(int((family['MARR'] - wife_bdate).days / days_in_year))

        if husb_age_at_marr > wife_age_at_marr * 2:
            flag = False
            print(
                f"ERROR: FAMILY: US34: family with id {family['FAM']} had husband {family['HUSB']} of age {husb_age_at_marr} twice the age of his wife {family['WIFE']} of age {wife_age_at_marr} during their marriage {family['MARR']}")
            f.write(f"ERROR: FAMILY: US34: family with id {family['FAM']} had husband {family['HUSB']} of age {husb_age_at_marr} twice the age of his wife {family['WIFE']} of age {wife_age_at_marr} during their marriage {family['MARR']}\n")
        elif wife_age_at_marr > husb_age_at_marr * 2:
            flag = False
            print(
                f"ERROR: FAMILY: US34: family with id {family['FAM']} had wife {family['WIFE']} of age {wife_age_at_marr} twice the age of her husband {family['HUSB']} of age {husb_age_at_marr} during their marriage {family['MARR']}")
            f.write(f"ERROR: FAMILY: US34: family with id {family['FAM']} had wife {family['WIFE']} of age {wife_age_at_marr} twice the age of her husband {family['HUSB']} of age {husb_age_at_marr} during their marriage {family['MARR']}\n")
    print("Userstory 34 Completed")
    if flag:
        return True
    else:
        return False
def us25(indi, fam, f):
    flag = True
    print("User Story 25 - unique name and birthdate, running")
    for family in fam:
        if family['CHIL'] != "NA":
            if len(family['CHIL']) > 1:
                check_child = list()
                for child in family['CHIL']:
                    check = getIndiByID(indi, child)['NAME']
                    for child1 in family['CHIL']:
                        if child != child1:
                            check2 = getIndiByID(indi, child1)['NAME']
                            if check == check2:
                                if getIndiByID(indi,
                                               child)['BIRT'] == getIndiByID(
                                                   indi, child1)['BIRT']:
                                    check_child.append(check)
                                    print(
                                        f"Error: INDIVIDUAL: US25: multiple children with the name {child} and "
                                        f"birthdate {getIndiByID(indi, child)['BIRT']} exist in a family"
                                    )
                                    f.write(
                                        f"Error: INDIVIDUAL: US25: multiple children with the name {child} and "
                                        f"birthdate {getIndiByID(indi, child)['BIRT']} exist in a family \n"
                                    )
                                    flag = False

    print("User Story 25 Completed")
    return flag
예제 #3
0
def us39(indi, fam, f):
    print("User Story 39 - List upcoming Anniversary, running")
    f.write("Info: INDIVIDUAL: US39: List upcoming Anniversary \n")
    # Created empty list to store upcoming anniversary
    upcoming_anniversary = list()
    ftable = prettytable.PrettyTable()
    ftable.field_names = ["INDI ID", "NAME"]
    # Iterating in families to check over each marriage
    for families in fam:
        # Getting Data of Husband and Wife to check if they are alive
        husband = getIndiByID(indi, families["HUSB"])
        wife = getIndiByID(indi, families["WIFE"])
        if wife["DEAT"] == "NA" and husband["DEAT"] == "NA":
            # Checking there marriage with current date
            todays_date = datetime.today()
            aniversary = families["MARR"]
            # To do math operation changing year to current date
            aniversary = aniversary.replace(year=todays_date.year)

            if 0 < (aniversary - todays_date).days <= 30:
                # If criteria matches we append object to list
                upcoming_anniversary.append(husband)
                upcoming_anniversary.append(wife)
    for upa in upcoming_anniversary:
        ftable.add_row([upa["INDI"], upa["NAME"]])
    f.write(f"{str(ftable)} \n")
    print("User Story 39 Completed")
    return upcoming_anniversary
def us11(indi, fam, f):
    print(
        "User Story 11 - Marriage should not occur during marriage to another spouse, Running"
    )
    flag = True
    for individual in indi:
        if individual["FAMS"] != 'NA':
            if len(individual["FAMS"]) > 1:
                spouse = list()
                for sp in individual["FAMS"]:
                    s = getFamByID(fam, sp)
                    spouse.append(s)
                for sp1 in spouse:
                    check = sp1['DIV']
                    for sp2 in spouse:
                        if sp1 != sp2:
                            if sp2["MARR"] != 'NA':
                                if check != 'NA':
                                    if sp1["MARR"] < sp2["MARR"]:
                                        if sp2["MARR"] < check:
                                            f.write(
                                                f"ERROR: FAMILY : US11 : {individual['INDI']} : Individual is in mutliple families at once  \n"
                                            )
                                            flag = False
                if individual["SEX"] == 'F':
                    spouse2 = list()
                    for sp3 in individual["FAMS"]:
                        s = getFamByID(fam, sp3)
                        infoindi = getIndiByID(indi, s["HUSB"])
                        spouse2.append(infoindi)
                    for sp1 in spouse:
                        for sp2 in spouse2:
                            if sp1["HUSB"] != sp2["INDI"]:
                                if sp2["DEAT"] != 'NA':
                                    if sp1["MARR"] < sp2["DEAT"]:
                                        f.write(
                                            f"ERROR: FAMILY : US11 : {individual['INDI']} : Individual is in mutliple families at once  \n"
                                        )
                                        flag = False
                if individual["SEX"] == 'M':
                    spouse2 = list()
                    for sp3 in individual["FAMS"]:
                        s = getFamByID(fam, sp3)
                        infoindi = getIndiByID(indi, s["WIFE"])
                        spouse2.append(infoindi)
                    for sp1 in spouse:
                        for sp2 in spouse2:
                            if sp1["WIFE"] != sp2["INDI"]:
                                if sp2["DEAT"] != 'NA':
                                    if sp1["MARR"] < sp2["DEAT"]:
                                        f.write(
                                            f"ERROR: FAMILY : US11 : {individual['INDI']} : Individual is in mutliple families at once  \n"
                                        )
                                        flag = False
    print("User Story 11 Completed")
    return flag
def us37(indi, fam, f):
    print("Userstory 37 Running ")
    # f.write("List all living spouses and descendants of people in a GEDCOM file who died in the last 30 days")
    # List of people who died in past 30 days
    dead_people_recent = list()
    # List of all the people who died
    dead_people_list = list()
    list_to_rtrn = list()
    for person in indi:
        if person['DEAT'] != 'NA':
            dead_people_list.append(person['INDI'])
            if abs(person['DEAT'] - datetime.today()) <= timedelta(days=30):
                dead_people_recent.append(person['INDI'])

    for dead_person in dead_people_recent:

        dead_person_obj = getIndiByID(indi, dead_person)

        if dead_person_obj['FAMS'] != 'NA':
            for family in dead_person_obj['FAMS']:
                family_obj = getFamByID(fam, family)

                if family_obj['HUSB'] == dead_person:
                    if not dead_people_list.__contains__(family_obj['WIFE']):
                        list_to_rtrn.append(family_obj['WIFE'])
                elif family_obj['WIFE'] == dead_person:
                    if not dead_people_list.__contains__(family_obj['HUSB']):
                        list_to_rtrn.append(family_obj['HUSB'])

                if family_obj['CHIL'] != 'NA':
                    children_list = family_obj['CHIL']

                    for child in range(len(children_list)):
                        if not dead_people_list.__contains__(children_list[child]):
                            list_to_rtrn.append(children_list[child])

    ftable = prettytable.PrettyTable()
    ftable.field_names = ["INDI ID", "NAME"]
    for i in range(len(list_to_rtrn)):
        person = getIndiByID(indi, list_to_rtrn[i])
        ftable.add_row([list_to_rtrn[i],person['NAME']])
    f.write(f"ERROR: INDIVIDUAL US37: List all living spouses and descendants of people who died in the last 30 days: \n")
    f.write(f"{str(ftable)} \n")
    print(f"{str(ftable)} \n")
    print("Userstory 37 Completed")
    return list_to_rtrn
예제 #6
0
 def test_us37(self):
     f = open("test.txt", "a")
     value = us37(self.d[0], self.d[1], f)
     flag = True
     for id in value:
         person = getIndiByID(self.d[0], id)
         if person['DEAT'] != 'NA':
             flag = False
     f.close()
     self.assertTrue(flag)
예제 #7
0
    def test_us33(self):
        # list of orphaned kids
        f = open("test.txt", "a")
        value = us33(self.d[0], self.d[1], f)
        f.close()
        flag = True
        if len(value) == 0:
            flag = False
        for individual in value:
            if individual["DEAT"] != "NA" or int(
                    calculateage(individual["BIRT"], "NA")) > 18:
                flag = False
                break
            indi_famc = getFamByID(self.d[1], individual["FAMC"][0])
            indi_mom = getIndiByID(self.d[0], indi_famc["WIFE"])
            indi_dad = getIndiByID(self.d[0], indi_famc["HUSB"])
            if indi_dad["DEAT"] == "NA" or indi_mom["DEAT"] == "NA":
                flag = False
                break

        self.assertTrue(flag)
예제 #8
0
 def test_us31(self):
     f = open("test.txt", "a")
     value = us31(self.d[0], self.d[1], f)
     flag = False
     for id in value:
         person = getIndiByID(self.d[0], id)
         age = calculateage(person["BIRT"], person["DEAT"])
         if (person["DEAT"] == 'NA' and person["FAMS"] == 'NA'):
             if (str(age) > '30'):
                 flag = True
     f.close()
     self.assertTrue(flag)
def us24(indi, fam, f):
    print("Userstory 24 Running")
    famlist = list()
    flag = True
    for family in fam:
        current_fam_id = family['FAM']
        husband = getIndiByID(indi, family['HUSB'])['NAME']
        wife = getIndiByID(indi, family['WIFE'])['NAME']
        currList = [husband, wife, family['MARR']]
        if famlist.__contains__(currList):
            print(
                f"ERROR: FAMILY: US24: LINENUMBER: {family['FAM']}: has same named spouses {husband}, {wife} and marriage date {family['MARR']} with more than one family")
            f.write(
                f"ERROR: FAMILY: US24: LINENUMBER: {family['FAM']}: has same named spouses {husband}, {wife} and marriage date {family['MARR']} with more than one family \n")
            flag = False
        elif not famlist.__contains__(currList):
            famlist.append(currList)
    print("User Story 24 Completed")
    if flag:
        return True
    else:
        return False
def us39(indi, fam, f):
    print("User Story 39 - List upcoming Anniversary, running")
    # Created empty list to store upcoming anniversary
    upcoming_anniversary = list()
    # Iterating in families to check over each marriage
    for families in fam:
        # Getting Data of Husband and Wife to check if they are alive
        husband = getIndiByID(indi, families["HUSB"])
        wife = getIndiByID(indi, families["WIFE"])
        if wife["DEAT"] == "NA" and husband["DEAT"] == "NA":
            # Checking there marriage with current date
            todays_date = datetime.today()
            aniversary = families["MARR"]
            # To do math operation changing year to current date
            aniversary = aniversary.replace(year=todays_date.year)

            if 0 < (aniversary - todays_date).days <= 30:
                # If criteria matches we append object to list
                upcoming_anniversary.append(husband)
                upcoming_anniversary.append(wife)

    print("User Story 39 Completed")
    return upcoming_anniversary
def us19(indi, fam, f):
    flag = True
    print("User Story 19 - First cousins should not marry, running")
    for family in fam:
        grandfatherfamc = 0
        grandmotherfamc = 1
        husband = getIndiByID(indi, family["HUSB"])  # Getting Husband Data
        if husband["FAMC"] != 'NA':
            husbandfamc = getFamByID(fam, husband["FAMC"][0])
            # Getting Husband family child id
            if husbandfamc["HUSB"] != 'NA':
                grandfather = getIndiByID(indi, husbandfamc["HUSB"])
                # Comparing family id of paternal grandfather
                if grandfather["FAMC"] != 'NA':
                    grandfatherfamc = getFamByID(fam, grandfather["FAMC"][0])
                else:
                    # if match not found setting random value
                    grandfatherfamc = 0
            if husbandfamc["WIFE"] != 'NA':
                grandmother = getIndiByID(indi, husbandfamc["WIFE"])
                if grandmother["FAMC"] != 'NA':
                    grandmotherfamc = getFamByID(fam, grandmother["FAMC"][0])
                else:
                    # if match not found setting random value
                    grandmotherfamc = 1
        wife = getIndiByID(indi, family["WIFE"])
        if wife["FAMC"] != 'NA':
            wifefamc = getFamByID(fam, wife["FAMC"][0])
            # Comparing family id of maternal grandfather
            if wifefamc["HUSB"] != 'NA':
                wgrandfather = getIndiByID(indi, wifefamc["HUSB"])
                if wgrandfather["FAMC"] != 'NA':
                    wgrandfatherfamc = getFamByID(fam, wgrandfather["FAMC"][0])
                else:
                    # if match not found setting random value
                    wgrandfatherfamc = 2
            if wifefamc["WIFE"] != 'NA':
                wgrandmother = getIndiByID(indi, wifefamc["WIFE"])
                if wgrandmother["FAMC"] != 'NA':
                    wgrandmotherfamc = getFamByID(fam, wgrandmother["FAMC"][0])
                else:
                    # if match not found setting random value
                    wgrandmotherfamc = 3
            # Preventing the case if siblings are married
            if wife["FAMC"] != husband["FAMC"]:
                if wgrandfatherfamc == grandfatherfamc or wgrandfatherfamc == grandmotherfamc or wgrandmotherfamc == grandmotherfamc or wgrandmotherfamc == grandfatherfamc:
                    print(
                        f'Error: FAMILY: US19: spouses {family["HUSB"]} and {family["WIFE"]} are first cousins'
                    )
                    f.write(
                        f'Error: FAMILY: US19: spouses {family["HUSB"]} and {family["WIFE"]} are first cousins\n'
                    )
                    flag = False

    print("User Story 19 Completed")
    return flag
def us20(indi, fam, f):
    print(
        "User Story 20 - Aunts and Uncles should not marry their nieces and nephews , Running"
    )
    flag = True
    for individual in indi:
        if individual["FAMC"] == "NA" or individual["FAMS"] == "NA":
            continue
        # get parents of spouses for an individual
        parents_of_spouses = list()
        spouse_gender = "HUSB"
        if individual["SEX"] == "M":
            spouse_gender = "WIFE"
        for family_id in individual["FAMS"]:
            family = getFamByID(fam, family_id)
            spouse = getIndiByID(indi, family[spouse_gender])
            if spouse["FAMC"] == "NA":
                continue
            else:
                famc_spouse = getFamByID(fam, spouse["FAMC"][0])
                parents_of_spouses.append(
                    (spouse["INDI"], famc_spouse["HUSB"]))
                parents_of_spouses.append(
                    (spouse["INDI"], famc_spouse["WIFE"]))
        if len(parents_of_spouses) == 0:
            continue

        # for an individual check in "FAMC", if siblings are present as parents of spouses
        famc_individual = getFamByID(fam, individual["FAMC"][0])
        for child in famc_individual["CHIL"]:
            if child == individual["INDI"]:
                continue
            for spouse, parent in parents_of_spouses:
                if child == parent:
                    flag = False
                    print(
                        f"Error: US 20 Individual {spouse} has married their aunt/uncle {individual['INDI']}"
                    )
                    f.write(
                        f"Error: INDIVIDUAL US 20  {spouse} has married their aunt/uncle {individual['INDI']} \n "
                    )

    print("User Story 20 Completed \n \n")
    print("---------------- SPRINT 2 COMPLETED -------------------\n \n")
    return flag
예제 #13
0
def us29(indi, fam, f):
    print("US 29 - deceased List")
    flag = False
    deceasedList = []
    for i in indi:
        if (i["DEAT"] != 'NA'):
            deceasedList.append(i["INDI"])

    f.write("US 29: deceased list: " + "\n")
    ftable = prettytable.PrettyTable()
    ftable.field_names = ["INDI ID", "Deceased Individual"]
    for i in range(len(deceasedList)):
        individual = getIndiByID(indi, deceasedList[i])
        ftable.add_row([deceasedList[i], individual["NAME"]])
    f.write(f"{str(ftable)} \n")
    print(f"{str(ftable)} \n")
    print("US 29 - completed")
    return deceasedList
예제 #14
0
def us31(indi, fam, f):
    single = []
    print("US 31 - Living list of singles ")
    for i in indi:
        age = calculateage(i["BIRT"], i["DEAT"])
        if (i["DEAT"] == 'NA' and i["FAMS"] == 'NA'):
            if (str(age) > '30'):
                single.append(str(i["INDI"]))

    f.write("US 31: single's list: " + "\n")
    ftable = prettytable.PrettyTable()
    ftable.field_names = ["INDI ID", "Deceased Individual"]
    for i in range(len(single)):
        individual = getIndiByID(indi, single[i])
        ftable.add_row([single[i], individual["NAME"]])
    f.write(f"{str(ftable)} \n")
    print(f"{str(ftable)} \n")
    print("US 31 completed")
    return single
예제 #15
0
def us37(indi, fam, f):
    print("Userstory 37 Running ")
    # List of people who died in past 30 days
    dead_people_recent = list()
    # List of all the people who died
    dead_people_list = list()
    list_to_rtrn = list()
    for person in indi:
        if person['DEAT'] != 'NA':
            dead_people_list.append(person['INDI'])
            if abs(person['DEAT'] - datetime.today()) <= timedelta(days=30):
                dead_people_recent.append(person['INDI'])

    for dead_person in dead_people_recent:

        dead_person_obj = getIndiByID(indi, dead_person)

        if dead_person_obj['FAMS'] != 'NA':
            for family in dead_person_obj['FAMS']:
                family_obj = getFamByID(fam, family)

                if family_obj['HUSB'] == dead_person:
                    if not dead_people_list.__contains__(family_obj['WIFE']):
                        list_to_rtrn.append(family_obj['WIFE'])
                elif family_obj['WIFE'] == dead_person:
                    if not dead_people_list.__contains__(family_obj['HUSB']):
                        list_to_rtrn.append(family_obj['HUSB'])

                if family_obj['CHIL'] != 'NA':
                    children_list = family_obj['CHIL']

                    for child in range(len(children_list)):
                        if not dead_people_list.__contains__(
                                children_list[child]):
                            list_to_rtrn.append(children_list[child])
    print("Userstory 37 Completed")
    return list_to_rtrn