Fix names of classes and allow for combined competitions with other classes

This commit is contained in:
Christian Wolf 2024-03-06 18:18:29 +01:00
parent 8d227af0e4
commit b36d5a81ce
2 changed files with 23 additions and 29 deletions

View File

@ -36,43 +36,34 @@ class CombinedCompetitionClass:
Class_t = CompetitionClass | CombinedCompetitionClass Class_t = CompetitionClass | CombinedCompetitionClass
class CompetitionClassParser: class NoEClassException(Exception):
NEWC = CompetitionClass("Newc.") def __init__(self, *args):
BEG = CompetitionClass("Beg.") super(NoEClassException, self).__init__(*args)
ADV = CompetitionClass("Adv.")
PREVIEW = CompetitionClass("Sichtung")
class CompetitionClassParser:
E = CompetitionClass('E')
def __init__(self): def __init__(self):
self.mapNames = { self.mapNames = {
"Newc": self.NEWC, "E": self.E,
"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.namesPreview = ["Sichtung"]
self.mapShortNames = { self.mapShortNames = self.mapNames
"N": self.NEWC,
"B": self.BEG,
"A": self.ADV,
}
def parseClass(self, cls: str, allowPreview: bool = False) -> Class_t: def parseClass(self, cls: str, allowPreview: bool = False) -> Class_t:
if allowPreview and cls in self.namesPreview: # match = re.compile("^(\\w+\\.?)/(\\w+\\.?)$").match(cls)
return self.PREVIEW # 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]
match = re.compile("^(\\w+\\.?)/(\\w+\\.?)$").match(cls) if cls in self.mapNames:
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] return self.mapNames[cls]
else:
raise NoEClassException(f'The class "{cls}" is not parsable.')
def parseAbbreviatedClass(self, cls: str) -> Class_t: def parseAbbreviatedClass(self, cls: str) -> Class_t:
return self.mapShortNames[cls] return self.mapShortNames[cls]

View File

@ -31,8 +31,11 @@ class ResultExtractor:
try: try:
data = parser.guessDataFromHtmlTitle() data = parser.guessDataFromHtmlTitle()
except competition_class.NoEClassException as ex:
self.l.info('The HTML file %s does not represent a solo E class. Skipping it. (%s)', filePair[0], ex)
continue
except: except:
self.l.error( self.l.warning(
"Cannot parse HTML file %s to check if it is a valid result. Check manually.", "Cannot parse HTML file %s to check if it is a valid result. Check manually.",
filePair[0], filePair[0],
) )