From c690ce755ab8e9905916820492a0d973960d6537 Mon Sep 17 00:00:00 2001 From: Christian Wolf Date: Wed, 22 Nov 2023 16:33:02 +0100 Subject: [PATCH] Fixed bug with pure string group --- src/solo_turnier/html_parser.py | 16 +++++++++++++--- src/solo_turnier/output.py | 23 +++++++++++++++++++++++ src/solo_turnier/types/participant.py | 3 +++ src/solo_turnier/workers/Worker.py | 4 +--- 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/solo_turnier/html_parser.py b/src/solo_turnier/html_parser.py index 81b04bf..53077a7 100644 --- a/src/solo_turnier/html_parser.py +++ b/src/solo_turnier/html_parser.py @@ -114,6 +114,9 @@ class HtmlParser: rePlaceParser = re.compile("([0-9]+)(?:-([0-9]+))?") + groupParser = solo_turnier.group.GroupParser() + classParser = solo_turnier.competition_class.CompetitionClassParser() + def __parseTable(table): rows = table.find_all("tr") @@ -176,7 +179,12 @@ class HtmlParser: classRow = findRowIndex("Startklasse") if classRow is not None: classTags = rows[classRow]("td")[1 : (numIds + 1)] - return list(map(lambda x: x.contents[0], classTags)) + return list( + map( + lambda x: classParser.parseAbbreviatedClass(x.contents[0]), + classTags, + ) + ) return None classes = getClass() @@ -185,8 +193,10 @@ class HtmlParser: def getGroups(): groupRow = findRowIndex("Startgruppe") if groupRow is not None: - classTags = rows[groupRow]("td")[1 : (numIds + 1)] - return list(map(lambda x: x.contents[0], classTags)) + groupTags = rows[groupRow]("td")[1 : (numIds + 1)] + return list( + map(lambda x: groupParser.parseGroup(x.contents[0]), groupTags) + ) return None groups = getGroups() diff --git a/src/solo_turnier/output.py b/src/solo_turnier/output.py index 69816ce..02daaa3 100644 --- a/src/solo_turnier/output.py +++ b/src/solo_turnier/output.py @@ -65,6 +65,26 @@ class ConsoleOutputter(AbstractOutputter): print(tabulate(tableData, headers="firstrow", tablefmt="fancy_grid")) print() + def _reshapeRow( + self, + results: list[solo_turnier.types.SingleParticipantResult], + dances: list[str], + ) -> list[solo_turnier.types.SingleParticipantResult]: + ret = [None for x in dances] + + for result in results: + if result.dance not in dances: + self.l.error( + "Result in unknown dance found in table. This is a bug. (%s)", + result, + ) + continue + + idx = dances.index(result.dance) + ret[idx] = result + + return ret + def _outputGroup( self, group: solo_turnier.group.Group, groupResults: types.TotalGroupResult ): @@ -76,6 +96,9 @@ class ConsoleOutputter(AbstractOutputter): for participant in participants: results = groupResults.results[participant] + results = self._reshapeRow(results, groupResults.dances) + + self.l.log(5, "Results of %s: %s", participant, results) def mapResultColumn(result: types.SingleParticipantResult): def getPlace(place, placeTo): diff --git a/src/solo_turnier/types/participant.py b/src/solo_turnier/types/participant.py index c69fece..eacbbce 100644 --- a/src/solo_turnier/types/participant.py +++ b/src/solo_turnier/types/participant.py @@ -18,3 +18,6 @@ class Participant(Person): if self.finalist == True: return f"Part({self.id} {self.name},F)" return f"Part({self.id} {self.name})" + + def __ge__(self, other): + return self.id >= other.id diff --git a/src/solo_turnier/workers/Worker.py b/src/solo_turnier/workers/Worker.py index cb7b5e3..8cf04c9 100644 --- a/src/solo_turnier/workers/Worker.py +++ b/src/solo_turnier/workers/Worker.py @@ -356,9 +356,7 @@ class Worker: singleResult.nativePlace = fixture.place if fixture.class_ is not None: - singleResult.nativeClass = self._classParser.parseAbbreviatedClass( - fixture.class_ - ) + singleResult.nativeClass = fixture.class_ def _extractDancesPerGroup( self, data: types.State3, group: solo_turnier.group.Group