-
Notifications
You must be signed in to change notification settings - Fork 0
/
userStory.py
512 lines (449 loc) · 22.2 KB
/
userStory.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
from collections import Counter
errorList = []
deathList = []
marriedList = []
newBornList = []
deadPeopleList = []
singleList = []
orphanList = []
upcomingBirthdayList = []
upcomingAnniversaryList = []
multipleBirthList = []
livingPeopleList = []
def checkUserStory(individuals, families):
#Sprint 1
us_01_dates_before_current(individuals, families)
us_02_birth_before_marriage(individuals, families)
us03_birth_before_death(individuals)
us04_marriage_before_divorce(families)
us07_less_than_150year_old(individuals)
us_08_birthbefore_marriage_after9monthsdivorce(individuals,families)
#Sprint2
US05_marriage_before_death(individuals,families)
US06_divorce_before_death(individuals,families)
US14_mutiple_birth_5(individuals, families)
US16_males_same_lastname(individuals, families)
us10_marriage_after_14yrs(individuals, families)
us21_correct_gender(individuals, families)
#Sprint 3
us22_unique_indivdual_family_id(individuals, families)
us23_unique_name_birthday(individuals)
us_29_list_all_deceased_individuals(individuals)
us30_list_living_married_people(individuals, families)
us35_people_born_in_30days(individuals)
us36_people_died_in_last30_days(individuals)
#Sprint4
us31_single_over_30years(individuals, families)
us33_list_orphans_below18years(individuals, families)
us38_upcoming_birthdays(individuals)
us39_upcoming_anniversaries(families)
us32_multiple_births_in_family(individuals, families)
us37_list_living_spouses_descendents(individuals, families)
#User story 1 dates are before current date
def us_01_dates_before_current(individuals, families):
return_flag = True
for individual in individuals:
if individual.birthday and individual.birthday > datetime.now().date():
error_description = "Birth of "+ individual.id+ " occurs after current date"
report_error('ERROR: INDIVIDUAL: US01: ', error_description)
return_flag = False
if individual.death and individual.death > datetime.now().date():
error_description = "Death of "+individual.id+" occurs after current date"
report_error('ERROR: INDIVIDUAL: US01: ', error_description)
return_flag = False
for family in families:
if family.married and family.married > datetime.now().date():
error_description = "In family "+family.id+" marriage of "+family.husbandId+" and "+family.wifeId+" occurs after current date"
report_error('ERROR: FAMILY: US01: ', error_description)
return_flag = False
if family.divorced and family.divorced > datetime.now().date():
error_description = "In family " +family.id+" divorce of "+ family.husbandId+" and "+family.wifeId+" occurs after current date"
report_error('ERROR: FAMILY: US01: ', error_description)
return_flag = False
return return_flag
#User story 2 birth should be before marriage
def us_02_birth_before_marriage(individuals, families):
return_flag = True
for family in families:
if family.married:
for individual in individuals:
if individual.id == family.husbandId:
husband = individual
if individual.id == family.wifeId:
wife = individual
if wife.birthday and wife.birthday > family.married:
error_description = "Birth of wife "+wife.id+" occurs after marriage"
report_error('ERROR: FAMILY: US02:', error_description)
return_flag = False
if husband.birthday and husband.birthday > family.married:
error_description = "Birth of husband "+husband.id+" occurs after marraige"
report_error('ERROR: FAMILY: US02: ',error_description)
return_flag = False
return return_flag
#User story 3 birth should occur before death
def us03_birth_before_death(individuals):
return_flag = True
for individual in individuals:
if individual.death and individual.birthday:
if individual.death < individual.birthday:
error_description = individual.id+": Birthday "+str(individual.birthday)+" occurs after death. "+str(individual.death)
report_error('ERROR: INDIVIDUAL: US03: ', error_description)
return_flag = False
return return_flag
#user story 4 marriage should occur before divorce
def us04_marriage_before_divorce(families):
return_flag = True
for family in families:
if family.married and family.divorced:
if family.married > family.divorced:
error_description = family.id+" "+family.husbandId+" "+family.wifeId+" Marriage "+str(family.married)+" occurs after divorce "+str(family.divorced)
report_error('ERROR: FAMILY: US04: ', error_description)
return_flag = False
return return_flag
#user story 7 check if individual lived more than 150 years
def us07_less_than_150year_old(individuals):
return_flag = True
today = datetime.now()
for individual in individuals:
if individual.alive == False and relativedelta(individual.death, individual.birthday).years > 150:
error_description = individual.id+" lived longer than 150 years"
report_error('ANOMALY: INDIVIDUAL: US07: ', error_description)
return_flag= False
if individual.alive == True and relativedelta(today,individual.birthday).years > 150:
error_description = individual.id+" is living longer than 150 years"
report_error('ANOMALY: INDIVIDUAL: US07:', error_description)
return_flag = False
return return_flag
#user story 8 birth before marriage and not after 9 months of divorce
def us_08_birthbefore_marriage_after9monthsdivorce(individuals, families):
return_flag = True
for family in families:
if family.married:
for individual in individuals:
id = individual.id
bday = individual.birthday
if id in family.children and family.divorced is not None:
if bday < family.married:
error_description = "Child "+individual.id+" born "+str(individual.birthday)+" before marriage"+str(family.married)
report_error('ANOMALY: FAMILY: US08:',error_description)
return_flag = False
if relativedelta(bday,family.divorced).months+9:
error_description="Child "+individual.id+" born "+str(individual.birthday)+" after 9 months of divorce on "+str(family.divorced)
report_error('ANOMALY: FAMILY: US08:', error_description)
return_flag=False
return return_flag
#user story 5:marriage occuring before the death of either spouse
def US05_marriage_before_death(individuals,families):
return_flag=True
for family in families:
##searching through individuals to get husband and wife
if family.married:
for individual in individuals:
if individual.id==family.husbandId:
husband=individual
if individual.id==family.wifeId:
wife=individual
if wife.alive==False:
if family.married<wife.death:
error_description="Death of Wife"+str(wife.id)+"occurs before marriage."+str(family.married)
report_error('ERROR:FAMILY:US05:',error_description)
return_flag=False
if husband.alive==False:
if family.married>husband.death:
error_description="Death of Husband"+str(husband.id)+"occurs before marriage."+str(family.married)
report_error('ERROR:FAMILY:US05:',error_description)
return_flag=False
return return_flag
# User story 6: divorce before death
def US06_divorce_before_death(individuals,families):
return_flag=True
for family in families:
if family.divorced :
for individual in individuals:
if individual.id==family.husbandId:
husband=individual
if individual.id==family.wifeId:
wife=individual
if wife.alive==False:
if family.divorced<wife.death:
error_description="Death of Wife"+str(wife.id)+"occurs before divorce."+str(family.divorced)
report_error('ERROR:FAMILY:US06:',error_description)
return_flag=False
if husband.alive==False:
if family.divorced>husband.death:
print(husband)
error_description="Death of Husband"+str(husband.id)+"occurs before divorce."+str(family.divorced)
report_error('ERROR:FAMILY:US06:',error_description)
return_flag=False
return return_flag
#US14: No more than five siblings should be born at the same time
def US14_mutiple_birth_5(individuals,families):
return_flag=True
for family in families:
siblings_id=family.children
siblings=list(x for x in individuals if x.id in siblings_id)
sib_birthday=[]
for sibling in siblings:
sib_birthday.append(sibling.birthday)
result = Counter(sib_birthday).most_common(1)
for(a,b) in result:
if b>5:
error_description = family.id+"More than 5 siblings born at once"
report_error('ERROR: FAMILY: US14: ' ,error_description)
return_flag = False
return return_flag
#US16: All male members of a family should have the same last name
def US16_males_same_lastname(individuals,families):
return_flag=True
for family in families:
if family.married:
# Search through individuals to get husband and wife
lastname=family.husbandName[1]
for individual in individuals:
id=individual.id
name=individual.name
gender=individual.gender
if id in family.children:
if gender == "M":
if lastname not in name:
error_description = individual.id+" Lastname not the same as father "
report_error('ERROR:INDIVIDUAL: US16: ',error_description)
return_flag = False
return return_flag
#US10 - Marriage should be atleast 14 years after the birth of both spouses
def us10_marriage_after_14yrs(individuals, families):
return_flag = True
for family in families:
for individual in individuals:
if individual.id == family.husbandId:
husband = individual
if individual.id == family.wifeId:
wife = individual
if husband.age < 14:
error_description = family.id+" "+husband.id+" Husband is married before age of 14"
report_error('ANOMALY: FAMILY: US10:',error_description)
return_flag = False
if wife.age < 14:
error_description = family.id + " " + wife.id + " Wife is married before age of 14"
report_error('ANOMALY: FAMILY: US10:', error_description)
return_flag = False
return return_flag
#US21 - Correct Gender for Role; husband should be male, wife should be female
def us21_correct_gender(individuals, families):
return_flag = True
for family in families:
for individual in individuals:
if individual.id == family.husbandId:
husband = individual
if individual.id == family.wifeId:
wife = individual
if husband.gender is not "M":
error_description = family.id+" "+husband.id+" Husband is not a male"
report_error('ANOMALY: FAMILY: US21: ',error_description)
return_flag = False
if wife.gender is not "F":
error_description = family.id + " " + wife.id + " Wife is not a female"
report_error('ANOMALY: FAMILY: US21: ', error_description)
return_flag = False
return return_flag
#US22 - All individual id and family id must be unique
def us22_unique_indivdual_family_id(individuals,families):
return_flag = True
idset1 = set()
idset2=set()
idlist=[]
for individual in individuals:
individualId=individual.id
idlist.append(individualId)
for family in families:
familyId=family.id
idlist.append(familyId)
for item in idlist:
if item not in idset1:
idset1.add(item)
else:
idset2.add(item)
for duplicateId in idset2:
if duplicateId.startswith('@I'):
error_description =" Duplicate ID "+duplicateId+" Found"
report_error('ERROR: INDIVIDUAL: US22: ', error_description)
if duplicateId.startswith('@F'):
error_description = " Duplicate ID "+duplicateId+" Found"
report_error('ERROR: FAMILY: US22: ', error_description)
return_flag = False
return return_flag
#US23 - No more than one individual with same name and birth date must be present
def us23_unique_name_birthday(individuals):
return_flag = True
for individual in individuals:
for other_individual in individuals:
if individual.name and other_individual.name and individual.name == other_individual.name and individual.id != other_individual.id:
if other_individual.birthday and individual.birthday and other_individual.birthday and individual.birthday:
error_description ="The two individuals "+individual.id+" and "+other_individual.id+"have same name and bithdate"
report_error('ERROR: INDIVIDUAL: US23: ', error_description)
return_flag = False
return return_flag
#US29 - List all deceased individuals in gedcom file
def us_29_list_all_deceased_individuals(individuals):
for individual in individuals:
if individual.death is not None:
value = individual.id+" "+str(individual.name)
deathList.append(value)
#US30 - List all living married people in gedcom file
def us30_list_living_married_people(individuals, families):
for family in families:
for individual in individuals:
if individual.id == family.husbandId:
husband = individual
if individual.id == family.wifeId:
wife = individual
if husband.alive is True and wife.alive is True:
marriedPeople = husband.id+" "+str(husband.name)+" and "+wife.id+" "+str(wife.name)
marriedList.append(marriedPeople)
# US35 List of people born in last 30 days.
def us35_people_born_in_30days(individuals):
today = datetime.today()
for individual in individuals:
individual_birthday = individual.birthday
daysBefore = (today.date() - individual_birthday).days
if daysBefore > 0 and daysBefore <= 30:
newBornList.append(individual.id+" "+str(individual.name[0])+" "+str(individual.name[1]))
# US36 List of people who died in last 30 days
def us36_people_died_in_last30_days(individuals):
today = datetime.today()
for individual in individuals:
if individual.death:
daysBefore= (today.date() - individual.death).days
if daysBefore>0 and daysBefore<= 30:
deadPeopleList.append(individual.id+" "+str(individual.name[0])+" "+str(individual.name[1]))
# US31 List all single people over 30 years
def us31_single_over_30years(individuals, families):
marriedPeople=[]
for family in families:
husband = family.husbandId
wife = family.wifeId
marriedPeople.append(husband)
marriedPeople.append(wife)
for individual in individuals:
if individual.age > 30:
if individual.id not in marriedPeople:
singleList.append(individual.id+" "+str(individual.name[0])+" "+str(individual.name[1]))
# US33 List orphan children below 18 years of age
def us33_list_orphans_below18years(individuals, families):
for family in families:
if len(family.children) == 0:
break
for individual in individuals:
if individual.id == family.husbandId:
husband = individual
if individual.id == family.wifeId:
wife = individual
if husband.alive is False and wife.alive is False:
orphanChildren = list(child for child in individuals if child.id in family.children)
for orphan in orphanChildren:
if orphan.age < 18:
orphanList.append(orphan.id+" "+str(orphan.name[0])+" "+str(orphan.name[1]))
#US38 List upcoming birthdays
def us38_upcoming_birthdays(individuals):
todaysDate = datetime.today()
for individual in individuals:
if individual.alive == True:
individualBirthday = individual.birthday
individualBirthday = datetime(todaysDate.year, individualBirthday.month, individualBirthday.day)
upcomingBirthdayDays = (individualBirthday - todaysDate).days
if upcomingBirthdayDays <= 30 and upcomingBirthdayDays >= 0:
upcomingBirthdayList.append(individual.id+" "+str(individual.name)+" Birthday: "+str(individual.birthday.month)+"/"+str(individual.birthday.day))
#US39 List upcoming anniversaries
def us39_upcoming_anniversaries(families):
todaysDate = datetime.today()
for family in families:
if family.married:
weddingDate = family.married
weddingDate = datetime(todaysDate.year, weddingDate.month, weddingDate.day)
upcomingAnniversaryDays = (weddingDate - todaysDate).days
if upcomingAnniversaryDays <= 30 and upcomingAnniversaryDays >= 0:
upcomingAnniversaryList.append(family.id+" Anniversary Date: "+str(family.married.month)+"/"+str(family.married.day))
#US32 List multiple births in family
def us32_multiple_births_in_family(individuals,families):
for family in families:
children = family.children
siblings = list(child for child in individuals if child.id in children)
birthdayList = []
for sibling in siblings:
birthdayList.append(sibling.birthday)
numberOfChildren = Counter(birthdayList).most_common(1)
for (a,b) in numberOfChildren:
if b > 2:
multipleBirthList.append("Family: "+family.id+" Children: "+str(family.children))
#US37 List the living spouses and descendents of the people who died in last 30 days
def us37_list_living_spouses_descendents(individuals,families):
for individual in individuals:
if individual.alive == False:
differnceInDays = (datetime.now().date() - individual.death).days
if differnceInDays <= 30 and len(individual.spouse) > 0:
for family in families:
if family.id == individual.spouse[0]:
if individual.id == family.husbandId:
livingPeopleList.append("Person Died: "+individual.id+" "+str(individual.name)+
" Living spouse: "+family.wifeId+" "+str(family.wifeName)+" Descendents: "+str(family.children))
if individual.id == family.wifeId:
livingPeopleList.append("Person Died: " + individual.id +" "+str(individual.name)+
" Living spouse: " + family.husbandId +" "+str(family.husbandName)+" Descendents: " + str(family.children))
def report_error(errortype, description):
err = errortype + description
errorList.append(err)
def display():
for err in errorList:
print(err)
print(" ")
print("INFORMATION: INDIVIDUAL: US29: Deceased individuals in file")
print("-------------------------------------------------------------")
for person in deathList:
print(person)
print(" ")
print("INFORMATION: FAMILY: US30: Living married people in file")
print("---------------------------------------------------------")
for married_person in marriedList:
print(married_person)
print(" ")
print("INFORMATION: INDIVIDUAL: US35: List of people born in last 30 days")
print("-------------------------------------------------------------------")
for newBorn in newBornList:
print(newBorn)
print(" ")
print("INFORMATION: INDIVIDUAL: US36: List of people who died in the last 30 days")
print("---------------------------------------------------------------------------")
for deadPeople in deadPeopleList:
print(deadPeople)
print(" ")
print("INFORMATION: INDIVIDUAL: US31: List of single people over 30 years")
print("---------------------------------------------------------------------------")
for singles in singleList:
print(singles)
print(" ")
print("INFORMATION: INDIVIDUAL: US33: List of orphan children below 18 years")
print("---------------------------------------------------------------------------")
for orphans in orphanList:
print(orphans)
print(" ")
print("INFORMATION: INDIVIDUAL: US38: List upcoming birthdays in 30 days")
print("---------------------------------------------------------------------------")
for birthdayPeople in upcomingBirthdayList:
print(birthdayPeople)
print(" ")
print("INFORMATION: INDIVIDUAL: US39: List upcoming anniversaries in 30 days")
print("---------------------------------------------------------------------------")
for anniversaryPeople in upcomingAnniversaryList:
print(anniversaryPeople)
print(" ")
print("INFORMATION: INDIVIDUAL: US32: List multiple births in file")
print("---------------------------------------------------------------------------")
for multipleBirth in multipleBirthList:
print(multipleBirth)
print(" ")
print("INFORMATION: INDIVIDUAL: US37: List living spouses and descendents of people who died in last 30 days")
print("------------------------------------------------------------------------------------------------------")
for livingPeople in livingPeopleList:
print(livingPeople)