Skip to content

Commit

Permalink
update and refactor commemoration algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
corei8 committed Jul 17, 2024
1 parent 90d5bb5 commit d599066
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 48 deletions.
123 changes: 76 additions & 47 deletions ordotools/tools/commemorations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,96 +3,125 @@
from ordotools.tools.helpers import days
from ordotools.tools.helpers import weeks


"""
Commemorations are a bit tricky to implement. Everything
in this file is for determing the "seasonal commemorations"
for each feast, as well as the Fidélium prayer. The non-seasonal
commemorations are then added on top of these and ordering
the commemorations is handled by the Feast class.
"""


def advent_season(feast):
feast.com_1["code"] = 99906
feast.com_2["code"] = 99909
return feast

def epiphany_octave_to_septuagesima(feast):
def epiphany_octave_to_septuagesima(year: int, feast):
if feast.date > day(year, 2, 2):
feast.com_1["code"] = 99911
feast.com_2["code"] = 99913
else:
feast.com_1["code"] = 99907
feast.com_2["code"] = 99909 # TODO: or for the pope
return feast

def septuagesima_to_lent(feast):
# TODO: special secret of BVM if before February 2nd
feast.com_1["code"] = 99907
feast.com_2["code"] = 99909 # or for the pope
return feast

def lent_to_passiontide(feast):
feast.com_1["code"] = 99911
feast.com_2["code"] = 99914
return feast

def passiontide(feast):
feast.com_1["code"] = 99909 # or for the pope
return feast

def easter_octave(feast):
feast.com_1["code"] = 99909 # or for the pope
return feast

def easter_season(feast):
feast.com_1["code"] = 99908
feast.com_2["code"] = 99909 # or for the pope
return feast

def pentecost_season(feast):
feast.com_1["code"] = 99911
feast.com_2["code"] = 99913
return feast

def seasonal_commemorations(feasts: tuple, year: int) -> tuple:
mark = LiturgicalYearMarks(year)
processed_feasts = ()
month_indicator = ""

for feast in feasts:
# assuming that a double never takes the seasonal commemorations
if feast.rank_n > 15:

if mark.first_advent < feast.date < mark.christmas:
feast.com_1["code"] = 99906
feast.com_2["code"] = 99909
feast = advent_season(feast)

elif mark.christmas+days(19) < feast.date < mark.lent_begins-weeks(3)-days(3):
if feast.date > day(year, 2, 2):
feast.com_1["code"] = 99911
feast.com_2["code"] = 99913
else:
feast.com_1["code"] = 99907
feast.com_2["code"] = 99909 # TODO: or for the pope
feast = epiphany_octave_to_septuagesima(year, feast)

elif mark.lent_begins-weeks(3)-days(3) < feast.date < mark.lent_begins:
# TODO: special secret of BVM if before February 2nd
feast.com_1["code"] = 99907
feast.com_2["code"] = 99909 # or for the pope
processed_feasts += (feast,)
continue
feast = septuagesima_to_lent(feast)

elif mark.lent_begins < feast.date <= mark.lent_ends-weeks(2):
feast.com_1["code"] = 99911
feast.com_2["code"] = 99914
processed_feasts += (feast,)
continue
feast = lent_to_passiontide(feast)

elif mark.lent_ends-weeks(2) < feast.date < mark.lent_ends:
feast.com_1["code"] = 99909 # or for the pope
processed_feasts += (feast,)
continue
feast = passiontide(feast)

elif mark.easter+days(2) < feast.date < mark.easter+days(7):
feast.com_1["code"] = 99909 # or for the pope
processed_feasts += (feast,)
continue
feast = easter_octave(feast)

elif mark.easter+days(7) < feast.date < mark.easter_season_end:
feast.com_1["code"] = 99908
feast.com_2["code"] = 99909 # or for the pope
processed_feasts += (feast,)
continue
feast = easter_season(feast)

elif mark.pentecost_season_start < feast.date < mark.first_advent:
feast.com_1["code"] = 99911
feast.com_2["code"] = 99913
feast = pentecost_season(feast)

else:
pass

# FIDELIUM
if feast.rank_n == 23: # assuming that 23 never occurs outside our range...
# NOTE: can 23 be an impeded Sunday
if feast.date.strftime("%w") == 1:
feast.com_2 = {"code": 99912}
processed_feasts += (feast,)
continue
if feast.rank_n == 23: # NOTE: can 23 be an impeded Sunday
if month_indicator == feast.date.strftime("%B"):
continue
pass
else:
month_indicator = feast.date.strftime("%B")
if month_indicator == "November":
continue
elif mark.first_advent < feast.date < mark.christmas:
continue
pass
elif (
mark.first_advent < feast.date < mark.christmas or
mark.lent_begins < feast.date < mark.lent_ends or
mark.easter_season_start < feast.date < mark.easter_season_end
):
pass
else:
feast.com_2 = {"code": 99912}
processed_feasts += (feast,)
continue
else:
processed_feasts += (feast,)
month_indicator = feast.date.strftime("%B")

if feast.date.strftime("%w") == 1:
if mark.first_advent < feast.date < mark.christmas:
pass
elif mark.lent_begins < feast.date < mark.lent_ends:
pass
else:
if feast.com_2["code"] == 99912:
pass
else:
feast.com_2 = {"code": 99912}

else:
processed_feasts += (feast,)
pass

processed_feasts += (feast,)

return processed_feasts
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = ordotools
version = 0.0.39
version = 0.0.40
description = A set of tools for producing a traditional Catholic Ordo, given a year and diocese
long_description = file: README.rst
long_desciption_content_type = text/rst
Expand Down

0 comments on commit d599066

Please sign in to comment.