Allow to filter only for finalists in the output of the script

This commit is contained in:
Christian Wolf 2023-09-26 12:59:41 +02:00
parent 62035b01b4
commit d7d72e83b5
3 changed files with 31 additions and 1 deletions

View File

@ -29,5 +29,8 @@ class BatchWorker:
importedData = worker.collectAllData(htmlCandidatesPreview, htmlResultFiles) importedData = worker.collectAllData(htmlCandidatesPreview, htmlResultFiles)
combinedData = worker.combineData(importedData) combinedData = worker.combineData(importedData)
if not self.config.showAllParticipants():
worker.filterOutFinalists(combinedData)
consoleOutputtter = solo_turnier.output.ConsoleOutputter() consoleOutputtter = solo_turnier.output.ConsoleOutputter()
consoleOutputtter.output(combinedData) consoleOutputtter.output(combinedData)

View File

@ -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('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('-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('-v', '--verbose', help='Increase verbosity', action='count', default=0)
parser.add_argument('-d', '--debug', action='store_true', help='Activate debugging during startup') parser.add_argument('-d', '--debug', action='store_true', help='Activate debugging during startup')
@ -43,3 +44,6 @@ class Cli:
def getLogLevel(self): def getLogLevel(self):
return self.__args.verbose return self.__args.verbose
def showAllParticipants(self):
return self.__args.all_participants

View File

@ -651,4 +651,27 @@ class Worker:
# self.l.log(5, '(Partially) fixed places: %s', (data)) # 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