Reformat union string
This commit is contained in:
parent
6b391c5222
commit
ccb11e2be4
1 changed files with 20 additions and 11 deletions
31
src/event.py
31
src/event.py
|
|
@ -8,7 +8,7 @@ event_types = ['N', 'M', 'A', 'D']
|
||||||
|
|
||||||
class Event:
|
class Event:
|
||||||
def __init__(self, event_type: str, event_date: date, current_date: date,
|
def __init__(self, event_type: str, event_date: date, current_date: date,
|
||||||
person_a: Person, person_b: Person = None):
|
person_a: Person, person_b: Person = None, union_type=None):
|
||||||
if event_type not in event_types:
|
if event_type not in event_types:
|
||||||
raise ValueError('{} is not in {}'.format(event_type, event_types))
|
raise ValueError('{} is not in {}'.format(event_type, event_types))
|
||||||
self._type = event_type
|
self._type = event_type
|
||||||
|
|
@ -16,16 +16,25 @@ class Event:
|
||||||
self._current_date = current_date
|
self._current_date = current_date
|
||||||
self._p_a = person_a
|
self._p_a = person_a
|
||||||
self._p_b = person_b
|
self._p_b = person_b
|
||||||
|
self._union_type = union_type
|
||||||
|
|
||||||
def get_year_span(self) -> int:
|
def get_year_span(self) -> int:
|
||||||
return self._current_date.year - self._date.year
|
return self._current_date.year - self._date.year
|
||||||
|
|
||||||
def event_description(self) -> str:
|
def event_description(self) -> str:
|
||||||
y = self.get_year_span()
|
y = self.get_year_span()
|
||||||
|
|
||||||
|
union_descr = ''
|
||||||
|
if self._union_type == 'A':
|
||||||
|
union_descr = 's\'est uni{} à'.format('' if self._p_a.is_male() else 'e')
|
||||||
|
elif self._union_type == 'M':
|
||||||
|
union_descr = 'a épousé'
|
||||||
|
union_str = ' ({} {})'.format(union_descr, self._p_b.formatted_name()) if self._p_b else ''
|
||||||
|
|
||||||
if self._type == 'N':
|
if self._type == 'N':
|
||||||
return '{}{} né{} il y a {} an{}'.format(
|
return '{}{} né{} il y a {} an{}'.format(
|
||||||
self._p_a.formatted_name(),
|
self._p_a.formatted_name(),
|
||||||
' (a épousé {})'.format(self._p_b.formatted_name()) if self._p_b else '',
|
union_str,
|
||||||
'' if self._p_a.is_male() else 'e',
|
'' if self._p_a.is_male() else 'e',
|
||||||
y,
|
y,
|
||||||
's' if y > 1 else ''
|
's' if y > 1 else ''
|
||||||
|
|
@ -49,7 +58,7 @@ class Event:
|
||||||
|
|
||||||
return '{}{} décédé{} il y a {} an{}'.format(
|
return '{}{} décédé{} il y a {} an{}'.format(
|
||||||
self._p_a.formatted_name(),
|
self._p_a.formatted_name(),
|
||||||
' (a épousé {})'.format(self._p_b.formatted_name()) if self._p_b else '',
|
union_str,
|
||||||
'' if self._p_a.is_male() else 'e',
|
'' if self._p_a.is_male() else 'e',
|
||||||
y,
|
y,
|
||||||
's' if y > 1 else ''
|
's' if y > 1 else ''
|
||||||
|
|
@ -134,11 +143,11 @@ def load_mariage_to_list(mariages_file: str) -> list:
|
||||||
return mariage_lst
|
return mariage_lst
|
||||||
|
|
||||||
|
|
||||||
def find_significant_other(mariages: list, uid: int) -> int:
|
def find_significant_other(mariages: list, uid: int) -> (int, str):
|
||||||
for m in mariages:
|
for m in mariages:
|
||||||
if m.in_this_union(uid):
|
if m.in_this_union(uid):
|
||||||
return m.get_so(uid)
|
return m.get_so(uid), m.union()
|
||||||
return -1
|
return -1, ''
|
||||||
|
|
||||||
|
|
||||||
def create_events_from_span(start: date, end: date, members_file: str, mariages_file: str) -> list:
|
def create_events_from_span(start: date, end: date, members_file: str, mariages_file: str) -> list:
|
||||||
|
|
@ -149,7 +158,7 @@ def create_events_from_span(start: date, end: date, members_file: str, mariages_
|
||||||
events = []
|
events = []
|
||||||
|
|
||||||
for p in id_to_person.values():
|
for p in id_to_person.values():
|
||||||
so = find_significant_other(mariages, p.get_hash_id())
|
so, union = find_significant_other(mariages, p.get_hash_id())
|
||||||
if so == p.get_hash_id():
|
if so == p.get_hash_id():
|
||||||
print(f"What ??? {so}")
|
print(f"What ??? {so}")
|
||||||
if not p.is_dead():
|
if not p.is_dead():
|
||||||
|
|
@ -157,26 +166,26 @@ def create_events_from_span(start: date, end: date, members_file: str, mariages_
|
||||||
birth_in_year = date(cur_year, birth.month, birth.day)
|
birth_in_year = date(cur_year, birth.month, birth.day)
|
||||||
if start <= birth_in_year <= end:
|
if start <= birth_in_year <= end:
|
||||||
e = Event('N', birth, birth_in_year,
|
e = Event('N', birth, birth_in_year,
|
||||||
p, None if so == -1 else id_to_person[so])
|
p, None if so == -1 else id_to_person[so], None if so == -1 else union)
|
||||||
events.append(e)
|
events.append(e)
|
||||||
|
|
||||||
birth_in_year = date(cur_year + 1, birth.month, birth.day)
|
birth_in_year = date(cur_year + 1, birth.month, birth.day)
|
||||||
if start <= birth_in_year <= end:
|
if start <= birth_in_year <= end:
|
||||||
e = Event('N', birth, birth_in_year,
|
e = Event('N', birth, birth_in_year,
|
||||||
p, None if so == -1 else id_to_person[so])
|
p, None if so == -1 else id_to_person[so], None if so == -1 else union)
|
||||||
events.append(e)
|
events.append(e)
|
||||||
else:
|
else:
|
||||||
death = p.death()
|
death = p.death()
|
||||||
death_in_year = date(cur_year, death.month, death.day)
|
death_in_year = date(cur_year, death.month, death.day)
|
||||||
if start <= death_in_year <= end:
|
if start <= death_in_year <= end:
|
||||||
e = Event('D', death, death_in_year,
|
e = Event('D', death, death_in_year,
|
||||||
p, None if so == -1 else id_to_person[so])
|
p, None if so == -1 else id_to_person[so], None if so == -1 else union)
|
||||||
events.append(e)
|
events.append(e)
|
||||||
|
|
||||||
death_in_year = date(cur_year + 1, death.month, death.day)
|
death_in_year = date(cur_year + 1, death.month, death.day)
|
||||||
if start <= death_in_year <= end:
|
if start <= death_in_year <= end:
|
||||||
e = Event('D', death, death_in_year,
|
e = Event('D', death, death_in_year,
|
||||||
p, None if so == -1 else id_to_person[so])
|
p, None if so == -1 else id_to_person[so], None if so == -1 else union)
|
||||||
events.append(e)
|
events.append(e)
|
||||||
|
|
||||||
for m in mariages:
|
for m in mariages:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue