diff --git a/src/solo_turnier/competition_class.py b/src/solo_turnier/competition_class.py index 9fe88c8..20e1107 100644 --- a/src/solo_turnier/competition_class.py +++ b/src/solo_turnier/competition_class.py @@ -44,6 +44,11 @@ class CompetitionClassParser: 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: @@ -57,6 +62,9 @@ class CompetitionClassParser: 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) diff --git a/src/solo_turnier/html_parser.py b/src/solo_turnier/html_parser.py index 7117e4b..45b3f32 100644 --- a/src/solo_turnier/html_parser.py +++ b/src/solo_turnier/html_parser.py @@ -57,12 +57,17 @@ class HtmlParser: if len(tds) != 2: return + if tds[1].contents[0].startswith('Alle Starter weiter genommen.'): + self.l.info('No excluded starters found.') + return + regex = re.compile('(.*) \\(([0-9]+)\\)') place = tds[0].contents[0] match = regex.fullmatch(tds[1].contents[0]) 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') name = match.group(1) number = match.group(2) diff --git a/src/solo_turnier/worker.py b/src/solo_turnier/worker.py index 9968e61..b5aa7ba 100644 --- a/src/solo_turnier/worker.py +++ b/src/solo_turnier/worker.py @@ -159,7 +159,10 @@ class PreviewWorker: for file in parsers: parser = parsers[file] - self.__extractPersonsFromSinglePreview(parser) + try: + 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) @@ -467,11 +470,11 @@ class Worker: self.l.log(5, 'Obtained result %s', 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._fixNativePlacesFromTable(dances, results, importedData.htmlResults) - # self.l.log(5, 'Result after native fixing: %s', pformat(results)) - self.l.log(5,'Data %s', results) + self._fixNativeDataFromTable(dances, results, importedData.htmlResults) + self.l.log(5, 'Result after native fixing: %s', pformat(results)) + # self.l.log(5,'Fixed data %s', results) totalResult[group] = types.TotalGroupResult(dances, results) @@ -547,7 +550,9 @@ class Worker: raise Exception('Multiple results found with same key') 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) ret = types.SingleParticipantResult( @@ -562,13 +567,15 @@ class Worker: return results - def _fixNativePlacesFromTable( + def _fixNativeDataFromTable( self, dances: list[str], data: dict[types.HtmlPreviewParticipant, list[types.SingleParticipantResult]], importedData: types.HtmlCompetitionTotalResults ): rePlace = re.compile('([0-9]+)(?:-([0-9]+))?') + classParser = competition_class.CompetitionClassParser() + for participant in data.keys(): self.l.log(5, 'fixing participant %s', participant) results = data[participant] @@ -595,6 +602,9 @@ class Worker: result.placeNative = matcher.group(1) result.placeNativeTo = matcher.group(2) + if raw[1] is not None: + result.nativeClass = classParser.parseAbbreviatedClass(raw[1]) + pass def _fixNativePlaces(