Add celebrations + fixes
This commit is contained in:
parent
fcdfe6c6a3
commit
f7b543a41a
4 changed files with 94 additions and 8 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -143,3 +143,4 @@ cython_debug/
|
||||||
# Specific
|
# Specific
|
||||||
src/data/*
|
src/data/*
|
||||||
html_template/*.psd
|
html_template/*.psd
|
||||||
|
.configs/
|
||||||
21
src/celebration.py
Normal file
21
src/celebration.py
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
from datetime import date
|
||||||
|
|
||||||
|
celeb_types = ['O'] # O = Ordination
|
||||||
|
|
||||||
|
|
||||||
|
class Celebration:
|
||||||
|
def __init__(self, id_a: int, event_date: date, celeb_type: str):
|
||||||
|
self._id_a = id_a
|
||||||
|
self._date = event_date
|
||||||
|
if celeb_type not in celeb_types:
|
||||||
|
raise ValueError('{} is not in {}'.format(celeb_type, celeb_types))
|
||||||
|
self._celeb_type = celeb_type
|
||||||
|
|
||||||
|
def event_date(self):
|
||||||
|
return self._date
|
||||||
|
|
||||||
|
def id_a(self):
|
||||||
|
return self._id_a
|
||||||
|
|
||||||
|
def celeb_type(self):
|
||||||
|
return self._celeb_type
|
||||||
|
|
@ -7,7 +7,7 @@ from argparse import ArgumentParser
|
||||||
from datetime import date, timedelta
|
from datetime import date, timedelta
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from event import create_events_from_span, load_persons_to_dict, load_mariage_to_list
|
from event import create_events_from_span, load_persons_to_dict, load_mariage_to_list, load_celebrations_to_list
|
||||||
|
|
||||||
|
|
||||||
week_days = ['Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi', 'Dimanche']
|
week_days = ['Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi', 'Dimanche']
|
||||||
|
|
@ -233,19 +233,23 @@ def get_events(data_paths: DataPaths):
|
||||||
|
|
||||||
id_to_person = load_persons_to_dict(data_paths.members())
|
id_to_person = load_persons_to_dict(data_paths.members())
|
||||||
mariages = load_mariage_to_list(data_paths.mariages())
|
mariages = load_mariage_to_list(data_paths.mariages())
|
||||||
|
celebrations = load_celebrations_to_list(data_paths.mariages())
|
||||||
|
|
||||||
previous_week_events = create_events_from_span(previous_monday,
|
previous_week_events = create_events_from_span(previous_monday,
|
||||||
previous_monday + timedelta(days=6),
|
previous_monday + timedelta(days=6),
|
||||||
id_to_person,
|
id_to_person,
|
||||||
mariages)
|
mariages,
|
||||||
|
celebrations)
|
||||||
this_week_events = create_events_from_span(monday,
|
this_week_events = create_events_from_span(monday,
|
||||||
monday + timedelta(days=6),
|
monday + timedelta(days=6),
|
||||||
id_to_person,
|
id_to_person,
|
||||||
mariages)
|
mariages,
|
||||||
|
celebrations)
|
||||||
next_week_events = create_events_from_span(next_monday,
|
next_week_events = create_events_from_span(next_monday,
|
||||||
next_monday + timedelta(days=6),
|
next_monday + timedelta(days=6),
|
||||||
id_to_person,
|
id_to_person,
|
||||||
mariages)
|
mariages,
|
||||||
|
celebrations)
|
||||||
return previous_week_events, this_week_events, next_week_events
|
return previous_week_events, this_week_events, next_week_events
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
66
src/event.py
66
src/event.py
|
|
@ -1,9 +1,14 @@
|
||||||
from datetime import date
|
from datetime import date
|
||||||
from person import Person
|
from person import Person
|
||||||
from mariage import Mariage
|
from mariage import Mariage
|
||||||
|
from celebration import Celebration
|
||||||
|
|
||||||
|
# N = Naissance
|
||||||
event_types = ['N', 'M', 'A', 'D']
|
# M = Marriage
|
||||||
|
# A = Autre union officielle
|
||||||
|
# D = Décès
|
||||||
|
# O = Ordination
|
||||||
|
event_types = ['N', 'M', 'A', 'D', 'O']
|
||||||
|
|
||||||
|
|
||||||
class Event:
|
class Event:
|
||||||
|
|
@ -56,6 +61,13 @@ class Event:
|
||||||
's' if y > 1 else ''
|
's' if y > 1 else ''
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if self._type == 'O':
|
||||||
|
return '{} a été ordonné il y a {} an{}'.format(
|
||||||
|
self._p_a.formatted_name(),
|
||||||
|
y,
|
||||||
|
's' if y > 1 else ''
|
||||||
|
)
|
||||||
|
|
||||||
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(),
|
||||||
union_str,
|
union_str,
|
||||||
|
|
@ -114,6 +126,10 @@ def load_mariage_to_list(mariages_file: str) -> list:
|
||||||
if first_line:
|
if first_line:
|
||||||
first_line = False
|
first_line = False
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if "Ordination" in line:
|
||||||
|
continue
|
||||||
|
|
||||||
line.strip()
|
line.strip()
|
||||||
infos = line.split(',')
|
infos = line.split(',')
|
||||||
|
|
||||||
|
|
@ -143,6 +159,32 @@ def load_mariage_to_list(mariages_file: str) -> list:
|
||||||
return mariage_lst
|
return mariage_lst
|
||||||
|
|
||||||
|
|
||||||
|
def load_celebrations_to_list(mariages_file: str) -> list:
|
||||||
|
celebrations = []
|
||||||
|
first_line = True
|
||||||
|
with open(mariages_file, 'r', encoding='utf-8') as mariages:
|
||||||
|
for line in mariages:
|
||||||
|
if first_line:
|
||||||
|
first_line = False
|
||||||
|
continue
|
||||||
|
line.strip()
|
||||||
|
|
||||||
|
celeb = None
|
||||||
|
if "Ordination" in line:
|
||||||
|
# DD/MM/YYYY,NAME,FIRSTNAME,Ordination,DoB
|
||||||
|
infos = line.split(',')
|
||||||
|
doe = infos[0].split('/')
|
||||||
|
name = infos[1]
|
||||||
|
first_name = infos[2]
|
||||||
|
dob = infos[4].strip()[4:].split('/')
|
||||||
|
id_person = Person.get_id(first_name, name, date(int(dob[2]), int(dob[1]), int(dob[0])))
|
||||||
|
celeb = Celebration(id_person, date(int(doe[2]), int(doe[1]), int(doe[0])), 'O')
|
||||||
|
|
||||||
|
if celeb is not None:
|
||||||
|
celebrations.append(celeb)
|
||||||
|
return celebrations
|
||||||
|
|
||||||
|
|
||||||
def find_significant_other(mariages: list, uid: int) -> (int, str):
|
def find_significant_other(mariages: list, uid: int) -> (int, str):
|
||||||
matches = sorted([m for m in mariages if m.in_this_union(uid)], key=lambda union: union.event_date())
|
matches = sorted([m for m in mariages if m.in_this_union(uid)], key=lambda union: union.event_date())
|
||||||
if not matches:
|
if not matches:
|
||||||
|
|
@ -150,7 +192,7 @@ def find_significant_other(mariages: list, uid: int) -> (int, str):
|
||||||
return matches[-1].get_so(uid), matches[-1].union()
|
return matches[-1].get_so(uid), matches[-1].union()
|
||||||
|
|
||||||
|
|
||||||
def create_events_from_span(start: date, end: date, id_to_person: dict, mariages: list) -> list:
|
def create_events_from_span(start: date, end: date, id_to_person: dict, mariages: list, celebrations: list) -> list:
|
||||||
cur_year = start.year
|
cur_year = start.year
|
||||||
|
|
||||||
events = []
|
events = []
|
||||||
|
|
@ -159,6 +201,9 @@ def create_events_from_span(start: date, end: date, id_to_person: dict, mariages
|
||||||
so, union = 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 so != -1 and so not in id_to_person.keys():
|
||||||
|
print(so, "Missing SO in members")
|
||||||
|
so = -1
|
||||||
if not p.is_dead():
|
if not p.is_dead():
|
||||||
birth = p.birth()
|
birth = p.birth()
|
||||||
birth_in_year = date(cur_year, birth.month, birth.day)
|
birth_in_year = date(cur_year, birth.month, birth.day)
|
||||||
|
|
@ -200,4 +245,19 @@ def create_events_from_span(start: date, end: date, id_to_person: dict, mariages
|
||||||
id_to_person[m.id_a()], id_to_person[m.id_b()])
|
id_to_person[m.id_a()], id_to_person[m.id_b()])
|
||||||
events.append(e)
|
events.append(e)
|
||||||
|
|
||||||
|
for c in celebrations:
|
||||||
|
m_date = c.event_date()
|
||||||
|
date_in_year = date(cur_year, m_date.month, m_date.day)
|
||||||
|
if start <= date_in_year <= end:
|
||||||
|
e = Event(c.celeb_type(), m_date, date_in_year,
|
||||||
|
id_to_person[c.id_a()])
|
||||||
|
events.append(e)
|
||||||
|
|
||||||
|
date_in_year = date(cur_year + 1, m_date.month, m_date.day)
|
||||||
|
if start <= date_in_year <= end:
|
||||||
|
e = Event(c.celeb_type(), m_date, date_in_year,
|
||||||
|
id_to_person[c.id_a()])
|
||||||
|
events.append(e)
|
||||||
|
|
||||||
|
|
||||||
return events
|
return events
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue