diff --git a/src/solo_turnier/batch.py b/src/solo_turnier/batch.py index f942763..428bc73 100644 --- a/src/solo_turnier/batch.py +++ b/src/solo_turnier/batch.py @@ -31,4 +31,7 @@ class BatchWorker: worker.filterOutFinalists(combinedData, removeFilteredParicipants) - return combinedData + outputShaper = solo_turnier.workers.OutputShaper.OutputShaper() + shapedData = outputShaper.shapeResults(combinedData) + + return shapedData diff --git a/src/solo_turnier/output.py b/src/solo_turnier/output.py index 02daaa3..8be659c 100644 --- a/src/solo_turnier/output.py +++ b/src/solo_turnier/output.py @@ -86,17 +86,21 @@ class ConsoleOutputter(AbstractOutputter): return ret def _outputGroup( - self, group: solo_turnier.group.Group, groupResults: types.TotalGroupResult + self, + group: solo_turnier.group.Group, + groupResults: solo_turnier.types.GroupTableData, ): - print(f"Einzeltanzwettbewerb der Gruppe {group}") + if group is not None: + print(f"Einzeltanzwettbewerb der Gruppe {group}") + else: + print("Einzeltanzwettbewerbe ohne eindeutige Gruppenzuordnung") tableData = [["Tanz"] + groupResults.dances] - participants = list(groupResults.results.keys()) + participants = list(groupResults.resultsInGroup.keys()) participants.sort(key=lambda x: (x.id, x.name)) for participant in participants: - results = groupResults.results[participant] - results = self._reshapeRow(results, groupResults.dances) + results = groupResults.resultsInGroup[participant] self.l.log(5, "Results of %s: %s", participant, results) @@ -128,14 +132,14 @@ class ConsoleOutputter(AbstractOutputter): self.l.log(5, "table data: %s", pprint.pformat(tableData)) print(tabulate(tableData, headers="firstrow", tablefmt="fancy_grid")) - def output(self, data: types.State4): - for idx, group in enumerate(data.results): + def output(self, data: types.Stage5): + for idx, group in enumerate(data.resultsPerGroup): if idx > 0: print() self.l.debug("Output for group %s", group) - self._outputGroup(group, data.results[group]) + self._outputGroup(group, data.resultsPerGroup[group]) # self.groups = self.worker.collectPersonsInGroups(data) # self.dances = self.worker.getAllDancesInCompetitions(data) diff --git a/src/solo_turnier/templates/index.html b/src/solo_turnier/templates/index.html index 67f77bb..a62df9a 100644 --- a/src/solo_turnier/templates/index.html +++ b/src/solo_turnier/templates/index.html @@ -13,7 +13,11 @@ {% for group in data.groups %} {% block groupBlk scoped %}
+ {% if group is none %} +

Auswertung ohne eindeutige Gruppe

+ {% else %}

Auswertung Gruppe {{ group.name }}

+ {% endif %} @@ -39,9 +43,10 @@ {% if not participant.finalist %} Kein/e Finalist/in {% endif %} - {{ res.getNativePlace() }} ({{ res.nativeClass }})
+ {{ res.getNativePlace() }} + ({{ res.nativeClass }})
- {{ res.getPlace() }} in {{ res.competitionClass }} + {{ res.place }} in {{ res.competitionClass }} {% endif %} diff --git a/src/solo_turnier/types/__init__.py b/src/solo_turnier/types/__init__.py index 09f5ff1..b1aa540 100644 --- a/src/solo_turnier/types/__init__.py +++ b/src/solo_turnier/types/__init__.py @@ -13,5 +13,6 @@ from .htmlCompetitionTotalResults import HtmlCompetitionTotalResults from .singleParticipantResult import SingleParticipantResult from .totalGroupResult import TotalGroupResult from .participant import Participant +from .tableData import * from .stages import * diff --git a/src/solo_turnier/types/participant.py b/src/solo_turnier/types/participant.py index eacbbce..8c6efd8 100644 --- a/src/solo_turnier/types/participant.py +++ b/src/solo_turnier/types/participant.py @@ -19,5 +19,5 @@ class Participant(Person): return f"Part({self.id} {self.name},F)" return f"Part({self.id} {self.name})" - def __ge__(self, other): - return self.id >= other.id + def __gt__(self, other): + return self.id > other.id diff --git a/src/solo_turnier/types/singleParticipantResult.py b/src/solo_turnier/types/singleParticipantResult.py index bf548cf..969fe88 100644 --- a/src/solo_turnier/types/singleParticipantResult.py +++ b/src/solo_turnier/types/singleParticipantResult.py @@ -24,3 +24,6 @@ class SingleParticipantResult: asFinalist = " as finalist" if self.finalist else "" return f"SR[{self.place} in {self.dance} {self.competitionClass} ({self.nativePlace} {self.nativeClass}){asFinalist}]" + + def getNativePlace(self) -> str: + return str(self.nativePlace) diff --git a/src/solo_turnier/types/stages.py b/src/solo_turnier/types/stages.py index 301c11d..dbad5d2 100644 --- a/src/solo_turnier/types/stages.py +++ b/src/solo_turnier/types/stages.py @@ -2,12 +2,23 @@ import solo_turnier from .totalGroupResult import TotalGroupResult from .htmlCompetitionTotalResults import HtmlCompetitionTotalResults +from .singleParticipantResult import SingleParticipantResult +from .participant import Participant +from .tableData import GroupTableData + +NullableGroup = solo_turnier.group.Group | None + + +class Stage5: + def __init__( + self, + resultsPerGroup: dict[NullableGroup, GroupTableData], + ): + self.resultsPerGroup = resultsPerGroup class State4: - def __init__( - self, resultPerGroup: dict[solo_turnier.group.Group | None, TotalGroupResult] - ): + def __init__(self, resultPerGroup: dict[NullableGroup, TotalGroupResult]): parser = solo_turnier.group.GroupParser() self.groups = parser.getGroupsAsSortedList(resultPerGroup.keys()) self.results = resultPerGroup diff --git a/src/solo_turnier/types/tableData.py b/src/solo_turnier/types/tableData.py new file mode 100644 index 0000000..c4478eb --- /dev/null +++ b/src/solo_turnier/types/tableData.py @@ -0,0 +1,11 @@ +import solo_turnier +from .participant import Participant +from .singleParticipantResult import SingleParticipantResult + +SortedResultList = dict[Participant, list[SingleParticipantResult | None]] + + +class GroupTableData: + def __init__(self, dances: list[str], results: SortedResultList): + self.dances = dances + self.resultsInGroup = results diff --git a/src/solo_turnier/workers/OutputShaper.py b/src/solo_turnier/workers/OutputShaper.py new file mode 100644 index 0000000..c06c2c5 --- /dev/null +++ b/src/solo_turnier/workers/OutputShaper.py @@ -0,0 +1,58 @@ +import solo_turnier +import logging + + +class OutputShaper: + def __init__(self): + self.l = logging.getLogger("solo_turnier.worker.OutputShaper") + + def shapeResults( + self, results: solo_turnier.types.State4 + ) -> solo_turnier.types.Stage5: + ret = {} + for group in results.results: + ret[group] = self._handleGroup(results.results[group]) + + return solo_turnier.types.Stage5(ret) + + def _handleGroup( + self, + totalGroupResult: solo_turnier.types.TotalGroupResult, + ) -> solo_turnier.types.GroupTableData: + sortedResultList = {} + for participant in totalGroupResult.results: + sortedResultList[participant] = [None for x in totalGroupResult.dances] + + for result in totalGroupResult.results[participant]: + if result.dance not in totalGroupResult.dances: + self.l.error( + "Result in unknown dance found in table. This is a bug. (%s)", + result, + ) + continue + + idx = totalGroupResult.dances.index(result.dance) + sortedResultList[participant][idx] = result + return solo_turnier.types.GroupTableData( + totalGroupResult.dances, sortedResultList + ) + + 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 diff --git a/src/solo_turnier/workers/__init__.py b/src/solo_turnier/workers/__init__.py index 2ca2255..b5deb20 100644 --- a/src/solo_turnier/workers/__init__.py +++ b/src/solo_turnier/workers/__init__.py @@ -1,3 +1,4 @@ from . import ResultExtractor from . import DataWorker from . import Worker +from . import OutputShaper
Teilnehmer