Merge branch 'fix/incomplete-tables'

This commit is contained in:
Christian Wolf 2023-11-08 21:33:06 +01:00
commit 88bffcad8a
3 changed files with 30 additions and 7 deletions

View File

@ -44,6 +44,11 @@ class CompetitionClassParser:
self.namesPreview = [ self.namesPreview = [
'Sichtung' 'Sichtung'
] ]
self.mapShortNames = {
'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: if allowPreview and cls in self.namesPreview:
@ -57,6 +62,9 @@ class CompetitionClassParser:
else: else:
return self.mapNames[cls] return self.mapNames[cls]
def parseAbbreviatedClass(self, cls: str) -> Class_t:
return self.mapShortNames[cls]
def isPureClass(self, cls: str, allowPreview: bool = False) -> bool: def isPureClass(self, cls: str, allowPreview: bool = False) -> bool:
parsedClass = self.parseClass(cls, allowPreview) parsedClass = self.parseClass(cls, allowPreview)
return isinstance(parsedClass, CompetitionClass) return isinstance(parsedClass, CompetitionClass)

View File

@ -57,12 +57,17 @@ class HtmlParser:
if len(tds) != 2: if len(tds) != 2:
return return
if tds[1].contents[0].startswith('Alle Starter weiter genommen.'):
self.l.info('No excluded starters found.')
return
regex = re.compile('(.*) \\(([0-9]+)\\)') regex = re.compile('(.*) \\(([0-9]+)\\)')
place = tds[0].contents[0] place = tds[0].contents[0]
match = regex.fullmatch(tds[1].contents[0]) match = regex.fullmatch(tds[1].contents[0])
if match is None: if match is None:
self.l.error('Could not match %s to regex search pattern', str(tds))
raise Exception(f'Could not match {tds} to regex search pattern') raise Exception(f'Could not match {tds} to regex search pattern')
name = match.group(1) name = match.group(1)
number = match.group(2) number = match.group(2)

View File

@ -159,7 +159,10 @@ class PreviewWorker:
for file in parsers: for file in parsers:
parser = parsers[file] parser = parsers[file]
try:
self.__extractPersonsFromSinglePreview(parser) self.__extractPersonsFromSinglePreview(parser)
except:
self.l.error('Failed to parse preview round in file %s. Skipping this file\'s content.', parser.fileName)
return types.HtmlPreviewImport(self.participants, self.previewResults) return types.HtmlPreviewImport(self.participants, self.previewResults)
@ -467,11 +470,11 @@ class Worker:
self.l.log(5, 'Obtained result %s', resultsOfParticipant) self.l.log(5, 'Obtained result %s', resultsOfParticipant)
results[participant] = resultsOfParticipant results[participant] = resultsOfParticipant
self.l.log(5, 'Result before native fixing: %s', (results)) self.l.log(5, 'Result before native fixing: %s', pformat(results))
# self._fixNativePlaces(dances, results) # self._fixNativePlaces(dances, results)
self._fixNativePlacesFromTable(dances, results, importedData.htmlResults) self._fixNativeDataFromTable(dances, results, importedData.htmlResults)
# self.l.log(5, 'Result after native fixing: %s', pformat(results)) self.l.log(5, 'Result after native fixing: %s', pformat(results))
self.l.log(5,'Data %s', results) # self.l.log(5,'Fixed data %s', results)
totalResult[group] = types.TotalGroupResult(dances, results) totalResult[group] = types.TotalGroupResult(dances, results)
@ -547,7 +550,9 @@ class Worker:
raise Exception('Multiple results found with same key') raise Exception('Multiple results found with same key')
rawResult = rawResult[0] rawResult = rawResult[0]
nativeClass = previewResults.results[participant][dance] nativeClass = key[2]
# nativeClass = previewResults.results[participant][dance]
# nativeClass = key[2]
# self.l.log(5, 'Result %s => %s', key, rawResult) # self.l.log(5, 'Result %s => %s', key, rawResult)
ret = types.SingleParticipantResult( ret = types.SingleParticipantResult(
@ -562,13 +567,15 @@ class Worker:
return results return results
def _fixNativePlacesFromTable( def _fixNativeDataFromTable(
self, self,
dances: list[str], dances: list[str],
data: dict[types.HtmlPreviewParticipant, list[types.SingleParticipantResult]], data: dict[types.HtmlPreviewParticipant, list[types.SingleParticipantResult]],
importedData: types.HtmlCompetitionTotalResults importedData: types.HtmlCompetitionTotalResults
): ):
rePlace = re.compile('([0-9]+)(?:-([0-9]+))?') rePlace = re.compile('([0-9]+)(?:-([0-9]+))?')
classParser = competition_class.CompetitionClassParser()
for participant in data.keys(): for participant in data.keys():
self.l.log(5, 'fixing participant %s', participant) self.l.log(5, 'fixing participant %s', participant)
results = data[participant] results = data[participant]
@ -595,6 +602,9 @@ class Worker:
result.placeNative = matcher.group(1) result.placeNative = matcher.group(1)
result.placeNativeTo = matcher.group(2) result.placeNativeTo = matcher.group(2)
if raw[1] is not None:
result.nativeClass = classParser.parseAbbreviatedClass(raw[1])
pass pass
def _fixNativePlaces( def _fixNativePlaces(