Skip to content

Commit 2d3a327

Browse files
committed
calculate age of father and mother at birth
1 parent a06e502 commit 2d3a327

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

gramps/data.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gramps_import.py

+29-4
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,15 @@ def convert_json(config, **kwargs):
160160
medias[handle]['filepath'] = Path(base_media + '/' + jl['path'])
161161

162162
persons_out = {}
163+
persons_temp = {}
163164
for handle in persons:
164165
id = persons[handle]['id']
165-
166166
persons_out[id] = {}
167-
168167
persons_out[id]['id'] = id
169168

169+
persons_temp[handle] = {}
170+
persons_temp[handle]['id'] = id
171+
170172
persons_out[id]['name'] = persons[handle]['firstname'] + ' ' + persons[handle]['surname']
171173
persons_out[id]['longname'] = persons[handle]['givenname'] + ' ' + persons[handle]['surname']
172174
if persons[handle]['title']:
@@ -199,11 +201,19 @@ def convert_json(config, **kwargs):
199201
persons_out[id]['deathplace'] = '?' #make sure deathplace is set, so missing deathyear won't make someone immortal
200202
if birthdate and deathdate:
201203
persons_out[id]['age'] = relativedelta(deathdate, birthdate).years
204+
205+
persons_temp[handle]['birthdate'] = birthdate
206+
persons_temp[handle]['deathdate'] = deathdate
207+
202208
persons_out[id]['own_unions'] = []
203209
for handle2 in families:
204210
#person is the child of a family
205211
if handle in families[handle2]['children']:
206212
persons_out[id]['parent_union'] = families[handle2]['id']
213+
if families[handle2]['father']:
214+
persons_temp[handle]['fhandle'] = families[handle2]['father']
215+
if families[handle2]['mother']:
216+
persons_temp[handle]['mhandle'] = families[handle2]['mother']
207217

208218
#person has own families
209219
if ((families[handle2]['father'] and handle in families[handle2]['father']) or
@@ -254,7 +264,22 @@ def convert_json(config, **kwargs):
254264
unions_out[id]['children'].append(persons[handle2]['id'])
255265
links_out.append([id,persons[handle2]['id']])
256266

257-
#print('data = '+json.dumps({'start':'I0036','openup':['I0000', 'I0033'], 'persons':persons_out, 'unions':unions_out, 'links':links_out}, indent=4))
267+
for handle in persons_temp:
268+
id = persons_temp[handle]['id']
269+
birthdate = persons_temp[handle]['birthdate']
270+
if 'fhandle' in persons_temp[handle]:
271+
handle2 = persons_temp[handle]['fhandle']
272+
if handle2 in persons_temp:
273+
parent_birthdate = persons_temp[handle2]['birthdate']
274+
if birthdate and parent_birthdate:
275+
persons_out[id]['fageab'] = relativedelta(birthdate, parent_birthdate).years
276+
if 'mhandle' in persons_temp[handle]:
277+
handle2 = persons_temp[handle]['mhandle']
278+
if handle2 in persons_temp:
279+
parent_birthdate = persons_temp[handle2]['birthdate']
280+
if birthdate and parent_birthdate:
281+
persons_out[id]['mageab'] = relativedelta(birthdate, parent_birthdate).years
282+
258283
jsoncontent = {}
259284
jsoncontent['start'] = START
260285
if OPENUP:
@@ -264,4 +289,4 @@ def convert_json(config, **kwargs):
264289
jsoncontent['links'] = links_out
265290
filecontent = 'data = ' + json.dumps(jsoncontent) + ";"
266291
with open(Path(cur_dir + '/' + filename_out), 'w') as file:
267-
file.write(filecontent)
292+
file.write(filecontent)

0 commit comments

Comments
 (0)