diff --git a/server/const.py b/server/const.py index e8e0c57e9..5fdfa6c35 100644 --- a/server/const.py +++ b/server/const.py @@ -1,5 +1,6 @@ from __future__ import annotations from datetime import timedelta +from enum import global_enum, IntEnum, StrEnum import re from settings import static_url, PROD @@ -39,14 +40,36 @@ # 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) +@global_enum +class TStatus(IntEnum): + T_CREATED = 0 + T_STARTED = 1 + T_ABORTED = 2 + T_FINISHED = 3 + T_ARCHIVED = 4 + # tournament frequency -HOURLY, DAILY, WEEKLY, MONTHLY, YEARLY, MARATHON, SHIELD = "h", "d", "w", "m", "y", "a", "s" +@global_enum +class TFreq(StrEnum): + HOURLY = "h" + DAILY = "d" + WEEKLY = "w" + MONTHLY = "m" + YEARLY = "y" + MARATHON = "a" + SHIELD = "s" + # tournament pairing -ARENA, RR, SWISS = range(3) +@global_enum +class TPairing(IntEnum): + ARENA = 0 + RR = 1 + SWISS = 2 + # translations LANGUAGES = [ @@ -70,37 +93,48 @@ "zh_TW", ] + # fishnet work types -MOVE, ANALYSIS = 0, 1 +@global_enum +class WorkType(IntEnum): + MOVE = 0 + ANALYSIS = 1 + # game types -CASUAL, RATED, IMPORTED = 0, 1, 2 +@global_enum +class GameType(IntEnum): + CASUAL = 0 + RATED = 1 + IMPORTED = 2 + # game status -( - CREATED, - STARTED, - ABORTED, - MATE, - RESIGN, - STALEMATE, - TIMEOUT, - DRAW, - FLAG, - ABANDON, - CHEAT, - BYEGAME, - INVALIDMOVE, - UNKNOWNFINISH, - VARIANTEND, - CLAIM, -) = range(-2, 14) +@global_enum +class GameStatus(IntEnum): + CREATED = -2 + STARTED = -1 + ABORTED = 0 + MATE = 1 + RESIGN = 2 + STALEMATE = 3 + TIMEOUT = 4 + DRAW = 5 + FLAG = 6 + ABANDON = 7 + CHEAT = 8 + BYEGAME = 9 + INVALIDMOVE = 10 + UNKNOWNFINISH = 11 + VARIANTEND = 12 + CLAIM = 13 + LOSERS = { - "abandon": ABANDON, - "abort": ABORTED, - "resign": RESIGN, - "flag": FLAG, + "abandon": GameStatus.ABANDON, + "abort": GameStatus.ABORTED, + "resign": GameStatus.RESIGN, + "flag": GameStatus.FLAG, } GRANDS = ("xiangqi", "manchu", "grand", "grandhouse", "shako", "janggi") diff --git a/server/scheduler.py b/server/scheduler.py index be703508b..6c9e7e1b2 100644 --- a/server/scheduler.py +++ b/server/scheduler.py @@ -8,13 +8,14 @@ ARENA, CATEGORIES, GRANDS, + variant_display_name, + SCHEDULE_MAX_DAYS, + TYPE_CHECKING, DAILY, WEEKLY, MONTHLY, + YEARLY, SHIELD, - variant_display_name, - SCHEDULE_MAX_DAYS, - TYPE_CHECKING, ) if TYPE_CHECKING: @@ -23,8 +24,8 @@ from tournaments import new_tournament from logger import log +from calendar import MONDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY -MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY = range(7) Plan = namedtuple("Plan", "freq, date, hour, variant, is960, base, inc, byo, duration") SHIELDS = ["crazyhouse960", "atomic960", "kingofthehill960", "3check960", "makruk"] @@ -269,6 +270,8 @@ def new_scheduled_tournaments(already_scheduled, now=None): if plan.freq == SHIELD: name = "%s Shield Arena" % variant_name + elif plan.freq == YEARLY: + name = "Yearly %s Arena" % variant_name elif plan.freq == MONTHLY: if plan.variant in CATEGORIES["makruk"]: name = "SEAturday %s Arena" % variant_name diff --git a/tests/test_scheduler.py b/tests/test_scheduler.py index 12bbcb2c2..2bd2fc7d9 100644 --- a/tests/test_scheduler.py +++ b/tests/test_scheduler.py @@ -6,8 +6,6 @@ from const import SHIELD, SCHEDULE_MAX_DAYS from scheduler import new_scheduled_tournaments, MONTHLY_VARIANTS, SHIELDS, Scheduler -MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY = range(7) - # Crazhouse960 Shield scheduled at second MONDAY of month SHIELD_ZH_2021_09 = ( SHIELD,