diff --git a/src/solo_turnier/batch.py b/src/solo_turnier/batch.py index 5cbc44e..23d8e4e 100644 --- a/src/solo_turnier/batch.py +++ b/src/solo_turnier/batch.py @@ -29,5 +29,8 @@ class BatchWorker: importedData = worker.collectAllData(htmlCandidatesPreview, htmlResultFiles) combinedData = worker.combineData(importedData) + if not self.config.showAllParticipants(): + worker.filterOutFinalists(combinedData) + consoleOutputtter = solo_turnier.output.ConsoleOutputter() consoleOutputtter.output(combinedData) diff --git a/src/solo_turnier/cli.py b/src/solo_turnier/cli.py index 632b22d..fe869d4 100644 --- a/src/solo_turnier/cli.py +++ b/src/solo_turnier/cli.py @@ -10,6 +10,7 @@ class Cli: parser.add_argument('html', help='The path from where to look for HTML export files', nargs=1, default=['.']) parser.add_argument('-o', '--output', help='Set the output path of the script', nargs=1, default=[None]) + parser.add_argument('--all-participants', '-a', action='store_true', help='Show all participants not only finalists') parser.add_argument('-v', '--verbose', help='Increase verbosity', action='count', default=0) parser.add_argument('-d', '--debug', action='store_true', help='Activate debugging during startup') @@ -43,3 +44,6 @@ class Cli: def getLogLevel(self): return self.__args.verbose + + def showAllParticipants(self): + return self.__args.all_participants diff --git a/src/solo_turnier/worker.py b/src/solo_turnier/worker.py index 8cacbd8..8324b23 100644 --- a/src/solo_turnier/worker.py +++ b/src/solo_turnier/worker.py @@ -651,4 +651,27 @@ class Worker: # self.l.log(5, '(Partially) fixed places: %s', (data)) - + def filterOutFinalists(self, data: types.State4): + for group in data.results: + self.l.debug('Cleaning up group %s', group.name) + participants = data.results[group].results.keys() + droppedParticipants = [] + + for participant in participants: + self.l.debug('Checking %s', participant) + + def isFinalistInDance(x: types.HtmlSingleCompetitionResult|None): + if x is None: + return False + return x.finalist + mapped = list(map(isFinalistInDance, data.results[group].results[participant])) + finalist = True in mapped + self.l.log(5,'Check for finalist (in dances %s): %s', mapped, finalist) + + if not finalist: + self.l.warning('Dropping %s from the output as no finalist', participant) + droppedParticipants.append(participant) + + for droppedParticipant in droppedParticipants: + data.results[group].results.pop(droppedParticipant) + pass