1010from ged4py .date import DateValueVisitor
1111from ged4py .model import NameRec , Record
1212from gedcomoptions import gvOptions
13- from models .Human import Human , LifeEvent
14- from models .Pos import Pos
13+ from models .Person import Person , LifeEvent
14+ from models .LatLon import LatLon
1515
1616_log = logging .getLogger (__name__ .lower ())
1717
1818homelocationtags = ('OCCU' , 'CENS' , 'EDUC' )
1919otherlocationtags = ('CHR' , 'BAPM' , 'BASM' , 'BAPL' , 'IMMI' , 'NATU' , 'ORDN' ,'ORDI' , 'RETI' ,
20- 'EVEN' , 'CEME' , 'CREM' )
20+ 'EVEN' , 'CEME' , 'CREM' , 'FACT' )
2121
2222bitstags = {"OCCU" : ("Occupation" , True ), "RELI" : ("Religion" , True ), "EDUC" : ("Education" , True ),
2323
@@ -74,38 +74,38 @@ def getplace(gedcomtag : Record, placetag ="PLAC"):
7474
7575 return None
7676
77- def CheckAge (humans : Dict [str , Human ], thisXrefID ):
77+ def CheckAge (people : Dict [str , Person ], thisXrefID ):
7878 ""
7979 problems :list [str ] = []
80- if humans [thisXrefID ]:
81- thishuman = humans [thisXrefID ]
80+ if people [thisXrefID ]:
81+ thisperson = people [thisXrefID ]
8282 born = None
8383 died = None
84- if thishuman .birth :
85- born = thishuman .birth .whenyearnum ()
86- if thishuman .death :
87- died = thishuman .death .whenyearnum ()
84+ if thisperson .birth :
85+ born = thisperson .birth .whenyearnum ()
86+ if thisperson .death :
87+ died = thisperson .death .whenyearnum ()
8888 if born and died :
8989 if died < born :
9090 problems .append ("Died before Born" )
9191 if died - born > maxage :
9292 problems .append (f"Too old { died - born } > { maxage } " )
93- if thishuman .children :
94- for childId in thishuman .children :
95- if humans [childId ]:
96- child = humans [childId ]
93+ if thisperson .children :
94+ for childId in thisperson .children :
95+ if people [childId ]:
96+ child = people [childId ]
9797 if child .birth and child .birth .whenyearnum ():
9898 if born :
9999 parentatage = child .birth .whenyearnum () - born
100- if thishuman .sex == "F" :
100+ if thisperson .sex == "F" :
101101 if parentatage > maxmotherage :
102102 problems .append (f"Mother too old { parentatage } > { maxmotherage } for { child .name } [{ child .xref_id } ]" )
103103 if parentatage < minmother :
104104 problems .append (f"Mother too young { parentatage } < { minmother } for { child .name } [{ child .xref_id } ]" )
105105
106106 if died and died < parentatage :
107107 problems .append (f"Mother after death for { child .name } [{ child .xref_id } ]" )
108- elif thishuman .sex == "M" :
108+ elif thisperson .sex == "M" :
109109 if parentatage > maxfatherage :
110110 problems .append (f"Father too old { parentatage } > { maxfatherage } for { child .name } [{ child .xref_id } ]" )
111111 if parentatage < minfather :
@@ -127,7 +127,7 @@ class GetPosFromTag:
127127 def __init__ (self , gedcomtag : Record , tag : str , placetag = "PLAC" ):
128128 self .when = None
129129 self .place = None
130- self .pos = Pos (None , None )
130+ self .pos = LatLon (None , None )
131131 self .event = None
132132 if tag :
133133 subtag = gedcomtag .sub_tag (tag )
@@ -151,12 +151,12 @@ def __init__(self, gedcomtag : Record, tag : str, placetag ="PLAC"):
151151 lat = maploc .sub_tag ("LATI" )
152152 lon = maploc .sub_tag ("LONG" )
153153 if lat and lon :
154- self .pos = Pos (lat .value ,lon .value )
154+ self .pos = LatLon (lat .value ,lon .value )
155155 else :
156156 lat = maploc .sub_tag ("_LATI" )
157157 lon = maploc .sub_tag ("_LONG" )
158158 if lat and lon :
159- self .pos = Pos (lat .value ,lon .value )
159+ self .pos = LatLon (lat .value ,lon .value )
160160 else :
161161 if hasattr (plactag , 'value' ) :
162162 # Conderation for :
@@ -173,7 +173,7 @@ def __init__(self, gedcomtag : Record, tag : str, placetag ="PLAC"):
173173 lat = match .group (2 )
174174 lon = match .group (3 )
175175 if lat and lon :
176- self .pos = Pos (float (lat ),float (lon ))
176+ self .pos = LatLon (float (lat ),float (lon ))
177177 self .event = LifeEvent (self .place , self .when , self .pos , tag )
178178
179179
@@ -183,6 +183,7 @@ def __init__(self, gOp :gvOptions):
183183 self .gOp = gOp
184184 gOp .totalGEDpeople = None
185185 gOp .totalGEDfamily = None
186+ gOp .timeframe = [None ,None ]
186187 global thisgvOps
187188 thisgvOps = gOp
188189 if self .file_path == '' :
@@ -200,30 +201,30 @@ def __init__(self, gOp :gvOptions):
200201
201202
202203 @staticmethod
203- def __create_human (record : Record ) -> Human :
204+ def __create_person (record : Record ) -> Person :
204205 global thisgvOps
205206 thisgvOps .step ()
206- human = Human (record .xref_id )
207- human .name = ''
207+ person = Person (record .xref_id )
208+ person .name = ''
208209 name : NameRec = record .sub_tag ("NAME" )
209- _log .debug (f"Create Human : { name } " )
210+ _log .debug (f"Create Person : { name } " )
210211 if name :
211- human .first = record .name .first
212- human .surname = record .name .surname
213- human .maiden = record .name .maiden
214- human .name = "{}" .format (record .name .format ())
215- # human .name = "{} {}".format(name.value[0], name.value[1])
216- if human .name == '' :
217- human .first = "Unknown"
218- human .surname = "Unknown"
219- human .maiden = "Unknown"
212+ person .first = record .name .first
213+ person .surname = record .name .surname
214+ person .maiden = record .name .maiden
215+ person .name = "{}" .format (record .name .format ())
216+ # person .name = "{} {}".format(name.value[0], name.value[1])
217+ if person .name == '' :
218+ person .first = "Unknown"
219+ person .surname = "Unknown"
220+ person .maiden = "Unknown"
220221
221222 title = record .sub_tag ("TITL" )
222- human .title = title .value if title else ""
223+ person .title = title .value if title else ""
223224
224225 # Grab a link to the photo
225226 obj = record .sub_tag ("OBJE" )
226- human .photo = None
227+ person .photo = None
227228 if (obj ):
228229 if obj .sub_tag ("FILE" ):
229230 # Depending on how the GEDCOM was created the FORM maybe at 2 or 3 it may be in a sub tag and it may or may not have the right extension
@@ -233,20 +234,26 @@ def __create_human(record: Record) -> Human:
233234 else :
234235 ext = obj .sub_tag ("FILE" ).value .lower ().split ('.' )[- 1 ]
235236 if ext in ('jpg' ,'bmp' ,'jpeg' ,'png' ,'gif' ):
236- human .photo = obj .sub_tag ("FILE" ).value
237+ person .photo = obj .sub_tag ("FILE" ).value
237238 else :
238239 form = obj .sub_tag ("FORM" )
239240 if form and obj .sub_tag ("FORM" ).value .lower () in ('jpg' ,'bmp' ,'jpeg' ,'png' ,'gif' ):
240- human .photo = obj .sub_tag ("FILE" ).value
241+ person .photo = obj .sub_tag ("FILE" ).value
241242 else :
242243 form = obj .sub_tag ("FILE" ).sub_tag ("FORM" )
243244 if form and form .value .lower () in ('jpg' ,'bmp' ,'jpeg' ,'png' ,'gif' ):
244- human .photo = obj .sub_tag ("FILE" ).value
245- human .sex = record .sex
245+ person .photo = obj .sub_tag ("FILE" ).value
246+ person .sex = record .sex
246247 # BIRTH TAG
247248 birthtag = GetPosFromTag (record , "BIRT" )
248- human .birth = birthtag .event
249- human .pos = birthtag .pos
249+ person .birth = birthtag .event
250+ # Build a time range
251+ if thisgvOps .timeframe [0 ]:
252+ if person .birth and person .birth .whenyearnum () and person .birth .whenyearnum () < thisgvOps .timeframe [0 ]:
253+ thisgvOps .timeframe [0 ] = person .birth .whenyearnum ()
254+ else :
255+ thisgvOps .timeframe [0 ] = person .birth .whenyearnum ()
256+ person .pos = birthtag .pos
250257
251258 # Use the Burial Tag as a backup for the Death attributes
252259 # TODO need to code this as backup
@@ -258,15 +265,20 @@ def __create_human(record: Record) -> Human:
258265 deathtagAge = deathtag .sub_tag_value ("AGE" )
259266 deathtagCause = deathtag .sub_tag_value ("CAUS" )
260267 if deathtagAge :
261- human .age = deathtagAge
262- if deathtagCause : human .age = f"{ deathtagAge } of { deathtagCause } "
268+ person .age = deathtagAge
269+ if deathtagCause : person .age = f"{ deathtagAge } of { deathtagCause } "
263270 deathtagPos = GetPosFromTag (record , "DEAT" )
264- human .death = deathtagPos .event
271+ person .death = deathtagPos .event
272+ if thisgvOps .timeframe [1 ]:
273+ if person .death and person .death .whenyearnum () and person .death .whenyearnum () > thisgvOps .timeframe [0 ]:
274+ thisgvOps .timeframe [1 ] = person .death .whenyearnum ()
275+ else :
276+ thisgvOps .timeframe [1 ] = person .death .whenyearnum ()
265277
266278
267279 # Last Possible is death (or birth)
268- if human .death and Pos .hasLocation (human .death .pos ):
269- human .pos = human .death .pos
280+ if person .death and LatLon .hasLocation (person .death .pos ):
281+ person .pos = person .death .pos
270282
271283 homes = {}
272284 allhomes = record .sub_tags ("RESI" )
@@ -283,7 +295,7 @@ def __create_human(record: Record) -> Human:
283295 if alladdr != '' :
284296 homedate = getgdate (hom .sub_tag ("DATE" ))
285297 if homedate in homes :
286- _log .debug ("**Double RESI location for : %s on %s @ %s" , human .name , homedate , alladdr )
298+ _log .debug ("**Double RESI location for : %s on %s @ %s" , person .name , homedate , alladdr )
287299 homes [homedate ] = LifeEvent (alladdr , hom .sub_tag ("DATE" ))
288300 for tags in (homelocationtags ):
289301 allhomes = record .sub_tags (tags )
@@ -312,10 +324,10 @@ def __create_human(record: Record) -> Human:
312324 # Sort them by year
313325 if (homes ):
314326 for i in sorted (homes .keys ()) :
315- if human .home :
316- human .home .append (homes [i ])
327+ if person .home :
328+ person .home .append (homes [i ])
317329 else :
318- human .home = [homes [i ]]
330+ person .home = [homes [i ]]
319331
320332 # bits = ""
321333 # for tags in (bitstags):
@@ -334,17 +346,17 @@ def __create_human(record: Record) -> Human:
334346
335347
336348
337- return human
349+ return person
338350
339351 @staticmethod
340- def __create_humans (records0 ) -> Dict [str , Human ]:
352+ def __create_people (records0 ) -> Dict [str , Person ]:
341353 global thisgvOps
342- humans : Dict [str , Human ] = dict ()
354+ people : Dict [str , Person ] = dict ()
343355 thisgvOps .step ("Reading GED" , target = (thisgvOps .totalGEDpeople + thisgvOps .totalGEDfamily ))
344356 for record in records0 ("INDI" ):
345357 if thisgvOps .ShouldStop ():
346358 break
347- humans [record .xref_id ] = GedcomParser .__create_human (record )
359+ people [record .xref_id ] = GedcomParser .__create_person (record )
348360 familyloop = 0
349361 for record in records0 ("FAM" ):
350362 if thisgvOps .ShouldStop ():
@@ -357,37 +369,37 @@ def __create_humans(records0) -> Dict[str, Human]:
357369 for marry in record .sub_tags ("MARR" ):
358370 marryevent = GetPosFromTag (marry , None ).event
359371 if husband and wife :
360- if humans [husband .xref_id ].marriage :
361- humans [husband .xref_id ].marriage .append ((wife .xref_id , marryevent ))
372+ if people [husband .xref_id ].marriage :
373+ people [husband .xref_id ].marriage .append ((wife .xref_id , marryevent ))
362374 else :
363- humans [husband .xref_id ].marriage = [(wife .xref_id , marryevent )]
364- if humans [wife .xref_id ].marriage :
365- humans [wife .xref_id ].marriage .append ((husband .xref_id , marryevent ))
375+ people [husband .xref_id ].marriage = [(wife .xref_id , marryevent )]
376+ if people [wife .xref_id ].marriage :
377+ people [wife .xref_id ].marriage .append ((husband .xref_id , marryevent ))
366378 else :
367- humans [wife .xref_id ].marriage = [(husband .xref_id , marryevent )]
379+ people [wife .xref_id ].marriage = [(husband .xref_id , marryevent )]
368380 if husband :
369- if humans [husband .xref_id ].name == "Unknown" :
370- humans [husband .xref_id ].name = "Unknown [Father]"
381+ if people [husband .xref_id ].name == "Unknown" :
382+ people [husband .xref_id ].name = "Unknown [Father]"
371383 if wife :
372- if humans [wife .xref_id ].name == "Unknown" :
373- humans [wife .xref_id ].name = "Unknown [Mother]"
384+ if people [wife .xref_id ].name == "Unknown" :
385+ people [wife .xref_id ].name = "Unknown [Mother]"
374386
375387 for chil in record .sub_tags ("CHIL" ):
376388 if chil :
377- if chil .xref_id not in humans .keys ():
389+ if chil .xref_id not in people .keys ():
378390 continue
379391 if husband :
380- humans [chil .xref_id ].father = husband .xref_id
381- humans [husband .xref_id ].children .append (chil .xref_id )
392+ people [chil .xref_id ].father = husband .xref_id
393+ people [husband .xref_id ].children .append (chil .xref_id )
382394 if wife :
383- humans [chil .xref_id ].mother = wife .xref_id
384- humans [wife .xref_id ].children .append (chil .xref_id )
395+ people [chil .xref_id ].mother = wife .xref_id
396+ people [wife .xref_id ].children .append (chil .xref_id )
385397 else :
386398 _log .warning ("Family has missing INDI record for one of the CHIL: %s" , record .xref_id )
387399
388- return humans
400+ return people
389401
390- def create_humans (self ) -> Dict [str , Human ]:
402+ def create_people (self ) -> Dict [str , Person ]:
391403 global thisgvOps
392404 if self .file_path == '' :
393405 return None
@@ -411,7 +423,7 @@ def create_humans(self) -> Dict[str, Human]:
411423 return None
412424
413425 thisgvOps .totalGEDfamily = sum (1 for value in parser .xref0 .values () if value [1 ] == 'FAM' )
414- return self .__create_humans (parser .records0 )
426+ return self .__create_people (parser .records0 )
415427
416428
417429
0 commit comments