86 lines
2.3 KiB
Python
86 lines
2.3 KiB
Python
import re
|
|
|
|
|
|
class CompetitionClass:
|
|
def __init__(self, text: str):
|
|
self.name = text
|
|
|
|
def __repr__(self):
|
|
return self.name
|
|
|
|
|
|
class CombinedCompetitionClass:
|
|
def __init__(
|
|
self,
|
|
clsA: CompetitionClass,
|
|
clsB: CompetitionClass,
|
|
clsC: CompetitionClass = None,
|
|
):
|
|
self.clsA = clsA
|
|
self.clsB = clsB
|
|
self.clsC = clsC
|
|
|
|
def __repr__(self):
|
|
if self.clsC is None:
|
|
return f"{self.clsA}/{self.clsB}"
|
|
else:
|
|
return f"{self.clsA}/{self.clsB}/{self.clsC}"
|
|
|
|
|
|
Class_t = CompetitionClass | CombinedCompetitionClass
|
|
|
|
|
|
class CompetitionClassParser:
|
|
NEWC = CompetitionClass("Newc.")
|
|
BEG = CompetitionClass("Beg.")
|
|
ADV = CompetitionClass("Adv.")
|
|
|
|
PREVIEW = CompetitionClass("Sichtung")
|
|
|
|
def __init__(self):
|
|
self.mapNames = {
|
|
"Newc": self.NEWC,
|
|
"Newc.": self.NEWC,
|
|
"Newcomer": self.NEWC,
|
|
"Beg": self.BEG,
|
|
"Beg.": self.BEG,
|
|
"Beginner": self.BEG,
|
|
"Adv": self.ADV,
|
|
"Adv.": self.ADV,
|
|
"Advanced": self.ADV,
|
|
}
|
|
self.namesPreview = ["Sichtung"]
|
|
self.mapShortNames = {
|
|
"N": self.NEWC,
|
|
"B": self.BEG,
|
|
"A": self.ADV,
|
|
}
|
|
|
|
def parseClass(self, cls: str, allowPreview: bool = False) -> Class_t:
|
|
if allowPreview and cls in self.namesPreview:
|
|
return self.PREVIEW
|
|
|
|
match = re.compile("^(\\w+\\.?)/(\\w+\\.?)$").match(cls)
|
|
if match is not None:
|
|
clsA = self.mapNames[match.group(1)]
|
|
clsB = self.mapNames[match.group(2)]
|
|
return CombinedCompetitionClass(clsA, clsB)
|
|
else:
|
|
return self.mapNames[cls]
|
|
|
|
def parseAbbreviatedClass(self, cls: str) -> Class_t:
|
|
return self.mapShortNames[cls]
|
|
|
|
def isPureClass(self, cls: str, allowPreview: bool = False) -> bool:
|
|
parsedClass = self.parseClass(cls, allowPreview)
|
|
return isinstance(parsedClass, CompetitionClass)
|
|
|
|
def getAllClasses(self) -> list[CompetitionClass]:
|
|
return [self.NEWC, self.BEG, self.ADV]
|
|
|
|
def isABetterThanB(self, a: CompetitionClass, b: CompetitionClass) -> bool:
|
|
classes = self.getAllClasses()
|
|
idxA = classes.index(a)
|
|
idxB = classes.index(b)
|
|
return idxA > idxB
|