-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUS09_birth_before_death_of_parents.py
64 lines (56 loc) · 1.98 KB
/
US09_birth_before_death_of_parents.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from print_data import *
connection = MongoClient('localhost', 27017)
db = connection['GEDCOMDB']
def US09_birth_before_death_of_parents():
userStoryName('US09')
family = get_family()
valid_difference_mom_and_child = True
for doc in family:
if (("CHILDREN" in doc) and ("HUSBAND" in doc) and ("WIFE" in doc)):
mom_deathDate = get_death_date(doc["WIFE"])
dad_deathDate = get_death_date(doc["HUSBAND"])
for child in doc["CHILDREN"]:
child_birthDate = get_birth_date(child)
if(child_birthDate != ""):
valid_difference_mom_and_child = check_valid_birth_wrt_mom(mom_deathDate, child_birthDate)
valid_difference_dad_and_child = check_valid_birth_wrt_dad(dad_deathDate, child_birthDate)
if(valid_difference_mom_and_child == False or valid_difference_dad_and_child == False):
output('\t'+doc["FAMID"] +'\t\t%-10s'+ str(child_birthDate) + '\t\t%-10s' % str(dad_deathDate) + '\t\t%-10s' % str(mom_deathDate))
def get_birth_date(individual):
indi = get_person_details(individual)
for doc in indi:
if "birthday" in doc:
birth_date = datetime.date(datetime.strptime(doc["birthday"],"%Y-%m-%d %H:%M:%S") )
else:
birth_date = ""
return birth_date
def get_death_date(individual):
indi = get_person_details(individual)
for doc in indi:
if "deathDate" in doc and doc['deathDate'] is not None:
death_date = datetime.date(datetime.strptime(doc["deathDate"],"%Y-%m-%d %H:%M:%S") )
else:
death_date = ""
return death_date
def check_valid_birth_wrt_mom(death_date, child_birthDate):
if(death_date == ""):
return True
else:
delta = death_date - child_birthDate
if(int(delta.days/30.4) < 0):
return False
else:
return True
def check_valid_birth_wrt_dad(death_date, child_birthDate):
if(death_date == ""):
return True
else:
delta = death_date - child_birthDate
if(int(delta.days/30.4) > -9 and int(delta.days/30.4) <= 0):
return False
else:
return True
def main():
US09_birth_before_death_of_parents()
if __name__ == "__main__":
main()