diff --git a/server/const.py b/server/const.py index e8e0c57e9..e6ba63534 100644 --- a/server/const.py +++ b/server/const.py @@ -1,5 +1,6 @@ from __future__ import annotations from datetime import timedelta +from enum import IntEnum, StrEnum import re from settings import static_url, PROD @@ -39,11 +40,33 @@ # Show the number of spectators only after this limit MAX_NAMED_SPECTATORS = 20 + # tournament status -T_CREATED, T_STARTED, T_ABORTED, T_FINISHED, T_ARCHIVED = range(5) +class TStatus(IntEnum): + CREATED = 0 + STARTED = 1 + ABORTED = 2 + FINISHED = 3 + ARCHIVED = 4 + + +T_CREATED = TStatus.CREATED +T_STARTED = TStatus.STARTED +T_ABORTED = TStatus.ABORTED +T_FINISHED = TStatus.FINISHED +T_ARCHIVED = TStatus.ARCHIVED + # tournament frequency -HOURLY, DAILY, WEEKLY, MONTHLY, YEARLY, MARATHON, SHIELD = "h", "d", "w", "m", "y", "a", "s" +class TFreq(StrEnum): + HOURLY = "h" + DAILY = "d" + WEEKLY = "w" + MONTHLY = "m" + YEARLY = "y" + MARATHON = "a" + SHIELD = "s" + # tournament pairing ARENA, RR, SWISS = range(3) diff --git a/server/generate_shield.py b/server/generate_shield.py index 7b5925d99..812f83640 100644 --- a/server/generate_shield.py +++ b/server/generate_shield.py @@ -1,6 +1,6 @@ from __future__ import annotations from compress import V2C -from const import SHIELD, VARIANTS, T_STARTED, TYPE_CHECKING +from const import TFreq, VARIANTS, T_STARTED, TYPE_CHECKING if TYPE_CHECKING: from pychess_global_app_state import PychessGlobalAppState @@ -17,7 +17,7 @@ async def generate_shield(app_state: PychessGlobalAppState): app_state.shield[variant] = [] cursor = app_state.db.tournament.find( - {"v": v, "z": z, "fr": SHIELD}, sort=[("startsAt", -1)], limit=5 + {"v": v, "z": z, "fr": TFreq.SHIELD}, sort=[("startsAt", -1)], limit=5 ) async for doc in cursor: if doc["status"] > T_STARTED: diff --git a/server/pychess_global_app_state.py b/server/pychess_global_app_state.py index 628192e68..54fcb8a7f 100644 --- a/server/pychess_global_app_state.py +++ b/server/pychess_global_app_state.py @@ -25,14 +25,12 @@ VARIANTS, LANGUAGES, MAX_CHAT_LINES, - MONTHLY, ARENA, - WEEKLY, - SHIELD, T_CREATED, T_STARTED, SCHEDULE_MAX_DAYS, ABORTED, + TFreq, ) from broadcast import round_broadcast from discord_bot import DiscordBot, FakeDiscordBot @@ -385,14 +383,14 @@ def __init_translations(self): or variant in SEATURDAY or variant in PAUSED_MONTHLY_VARIANTS ): - tname = translated_tournament_name(variant, MONTHLY, ARENA, translation) - self.tourneynames[lang][(variant, MONTHLY, ARENA)] = tname + tname = translated_tournament_name(variant, TFreq.MONTHLY, ARENA, translation) + self.tourneynames[lang][(variant, TFreq.MONTHLY, ARENA)] = tname if variant in SEATURDAY or variant in WEEKLY_VARIANTS: - tname = translated_tournament_name(variant, WEEKLY, ARENA, translation) - self.tourneynames[lang][(variant, WEEKLY, ARENA)] = tname + tname = translated_tournament_name(variant, TFreq.WEEKLY, ARENA, translation) + self.tourneynames[lang][(variant, TFreq.WEEKLY, ARENA)] = tname if variant in SHIELDS: - tname = translated_tournament_name(variant, SHIELD, ARENA, translation) - self.tourneynames[lang][(variant, SHIELD, ARENA)] = tname + tname = translated_tournament_name(variant, TFreq.SHIELD, ARENA, translation) + self.tourneynames[lang][(variant, TFreq.SHIELD, ARENA)] = tname def __start_bots(self): rm = self.users["Random-Mover"] diff --git a/server/scheduler.py b/server/scheduler.py index be703508b..bf1b84c8b 100644 --- a/server/scheduler.py +++ b/server/scheduler.py @@ -8,13 +8,10 @@ ARENA, CATEGORIES, GRANDS, - DAILY, - WEEKLY, - MONTHLY, - SHIELD, variant_display_name, SCHEDULE_MAX_DAYS, TYPE_CHECKING, + TFreq, ) if TYPE_CHECKING: @@ -182,7 +179,7 @@ def schedule_plan(self): except ValueError: log.error("schedule_plan() ValueError") break - plans.append(Plan(MONTHLY, date, 14, v.rstrip("960"), is_960, base, inc, byo, 90)) + plans.append(Plan(TFreq.MONTHLY, date, 14, v.rstrip("960"), is_960, base, inc, byo, 90)) for i, v in enumerate(MONTHLY_VARIANTS): if i + 1 > number_of_days: @@ -194,27 +191,25 @@ def schedule_plan(self): except ValueError: log.error("schedule_plan() ValueError") break - plans.append(Plan(MONTHLY, date, 16, v.rstrip("960"), is_960, base, inc, byo, 90)) + plans.append(Plan(TFreq.MONTHLY, date, 16, v.rstrip("960"), is_960, base, inc, byo, 90)) plans += [ - Plan( - SHIELD, self.first_monthly(MONDAY), 18, "kingofthehill", True, 3, 2, 0, 180 - ), # 960 - Plan(SHIELD, self.second_monthly(MONDAY), 18, "crazyhouse", True, 3, 2, 0, 180), # 960 - Plan(SHIELD, self.third_monthly(MONDAY), 18, "3check", True, 3, 2, 0, 180), # 960 - # Plan(SHIELD, self.second_monthly(THURSDAY), 18, "shinobi", False, 3, 4, 0, 180), - Plan(SHIELD, self.second_monthly(SATURDAY), 12, "makruk", False, 5, 3, 0, 180), - Plan(SHIELD, self.third_monthly(SUNDAY), 12, "atomic", True, 3, 2, 0, 180), # 960 - Plan(MONTHLY, self.first_monthly(SATURDAY), 12, "asean", False, 3, 2, 0, 90), + Plan(TFreq.SHIELD, self.first_monthly(MONDAY), 18, "kingofthehill", True, 3, 2, 0, 180), # 960 + Plan(TFreq.SHIELD, self.second_monthly(MONDAY), 18, "crazyhouse", True, 3, 2, 0, 180), # 960 + Plan(TFreq.SHIELD, self.third_monthly(MONDAY), 18, "3check", True, 3, 2, 0, 180), # 960 + # Plan(TFreq.SHIELD, self.second_monthly(THURSDAY), 18, "shinobi", False, 3, 4, 0, 180), + Plan(TFreq.SHIELD, self.second_monthly(SATURDAY), 12, "makruk", False, 5, 3, 0, 180), + Plan(TFreq.SHIELD, self.third_monthly(SUNDAY), 12, "atomic", True, 3, 2, 0, 180), # 960 + Plan(TFreq.MONTHLY, self.first_monthly(SATURDAY), 12, "asean", False, 3, 2, 0, 90), # The second Saturday is Makruk Shield - Plan(MONTHLY, self.third_monthly(SATURDAY), 12, SEA, False, 3, 2, 0, 90), - Plan(MONTHLY, self.fourth_monthly(SATURDAY), 12, "makpong", False, 3, 2, 0, 90), - # Plan(WEEKLY, self.next_day_of_week(FRIDAY), 18, "crazyhouse", True, 3, 0, 0, 60), # 960 - # Plan(WEEKLY, self.next_day_of_week(TUESDAY), 18, "atomic", True, 3, 0, 0, 60), # 960 - Plan(WEEKLY, self.next_day_of_week(THURSDAY), 12, "makruk", False, 3, 2, 0, 90), - Plan(WEEKLY, self.next_day_of_week(SUNDAY), 18, "duck", False, 3, 5, 0, 90), - Plan(WEEKLY, self.next_day_of_week(FRIDAY), 12, "xiangqi", False, 5, 3, 0, 90), - Plan(WEEKLY, self.next_day_of_week(WEDNESDAY), 12, "janggi", False, 5, 15, 1, 90), + Plan(TFreq.MONTHLY, self.third_monthly(SATURDAY), 12, SEA, False, 3, 2, 0, 90), + Plan(TFreq.MONTHLY, self.fourth_monthly(SATURDAY), 12, "makpong", False, 3, 2, 0, 90), + # Plan(TFreq.WEEKLY, self.next_day_of_week(FRIDAY), 18, "crazyhouse", True, 3, 0, 0, 60), # 960 + # Plan(TFreq.WEEKLY, self.next_day_of_week(TUESDAY), 18, "atomic", True, 3, 0, 0, 60), # 960 + Plan(TFreq.WEEKLY, self.next_day_of_week(THURSDAY), 12, "makruk", False, 3, 2, 0, 90), + Plan(TFreq.WEEKLY, self.next_day_of_week(SUNDAY), 18, "duck", False, 3, 5, 0, 90), + Plan(TFreq.WEEKLY, self.next_day_of_week(FRIDAY), 12, "xiangqi", False, 5, 3, 0, 90), + Plan(TFreq.WEEKLY, self.next_day_of_week(WEDNESDAY), 12, "janggi", False, 5, 15, 1, 90), ] return plans @@ -267,16 +262,16 @@ def new_scheduled_tournaments(already_scheduled, now=None): plan.variant + ("960" if plan.is960 else "") ).title() - if plan.freq == SHIELD: + if plan.freq == TFreq.SHIELD: name = "%s Shield Arena" % variant_name - elif plan.freq == MONTHLY: + elif plan.freq == TFreq.MONTHLY: if plan.variant in CATEGORIES["makruk"]: name = "SEAturday %s Arena" % variant_name else: name = "Monthly %s Arena" % variant_name - elif plan.freq == WEEKLY: + elif plan.freq == TFreq.WEEKLY: name = "Weekly %s Arena" % variant_name - elif plan.freq == DAILY: + elif plan.freq == TFreq.DAILY: name = "Daily %s Arena" % variant_name else: name = "%s Arena" % variant_name