Make output work in general

This commit is contained in:
Christian Wolf 2023-09-13 16:07:55 +02:00
parent 0d1310f287
commit 04803e21ed
4 changed files with 63 additions and 13 deletions

View File

@ -186,7 +186,10 @@ class BatchWorker:
worker = solo_turnier.worker.Worker() worker = solo_turnier.worker.Worker()
importedData = worker.collectAllData(htmlCandidatesPreview, self.config.importCSVPath(), htmlResultFiles) importedData = worker.collectAllData(htmlCandidatesPreview, self.config.importCSVPath(), htmlResultFiles)
worker.combineData(importedData) combinedData = worker.combineData(importedData)
consoleOutputtter = solo_turnier.output.ConsoleOutputter()
consoleOutputtter.output(combinedData)
# csvReader = solo_turnier.reader.CSVResultReader(self.config.importCSVPath()) # csvReader = solo_turnier.reader.CSVResultReader(self.config.importCSVPath())
# self.l.info('Loading the total result CSV file %s', self.config.importCSVPath()) # self.l.info('Loading the total result CSV file %s', self.config.importCSVPath())

View File

@ -1,8 +1,10 @@
import logging import logging
from tabulate import tabulate from tabulate import tabulate
import pprint
import solo_turnier import solo_turnier
from solo_turnier import types
sections = ('Kin.', 'Jun.', 'Jug.', 'Sonst') sections = ('Kin.', 'Jun.', 'Jug.', 'Sonst')
sectionMap = { sectionMap = {
@ -60,10 +62,50 @@ class ConsoleOutputter(AbstractOutputter):
print(tabulate(tableData, headers='firstrow', tablefmt='fancy_grid')) print(tabulate(tableData, headers='firstrow', tablefmt='fancy_grid'))
print() print()
def output(self, data): def _outputGroup(self, group: solo_turnier.group.Group, groupResults: types.TotalGroupResult):
self.groups = self.worker.collectPersonsInGroups(data) print(f"Einzeltanzwettbewerb der Gruppe {group}")
self.dances = self.worker.getAllDancesInCompetitions(data)
for section in sections: tableData = [['Tanz'] + groupResults.dances]
if len(self.groups[section]) > 0: participants = list(groupResults.results.keys())
self.__outputSection(data, section) participants.sort(key=lambda x: (x.id, x.name))
for participant in participants:
results = groupResults.results[participant]
def mapResultColumn(result: types.SingleParticipantResult):
def getPlace():
if result.placeTo is None:
return f'{result.place}.'
else:
return f'{result.place}.-{result.placeTo}.'
if result is None:
return ''
place = getPlace()
if not result.finalist:
return f'kein/e Finalist/in\n({place} in {result.nativeClass})'
return f'{place} ({result.nativeClass})'
mappedResults = map(mapResultColumn, results)
tableRow = [f'{participant.name} ({participant.id})'] + list(mappedResults)
tableData.append(tableRow)
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.groups):
if idx > 0:
print()
self.l.debug('Output for group %s', group)
self._outputGroup(group, data.results[group])
# self.groups = self.worker.collectPersonsInGroups(data)
# self.dances = self.worker.getAllDancesInCompetitions(data)
# for section in sections:
# if len(self.groups[section]) > 0:
# self.__outputSection(data, section)

View File

@ -167,12 +167,14 @@ class SingleParticipantResult:
def __init__( def __init__(
self, self,
competitionClass: competition_class.Class_t, competitionClass: competition_class.Class_t,
nativeClass: competition_class.CompetitionClass,
dance: str, dance: str,
finalist: bool, finalist: bool,
place: int, place: int,
placeTo: int|None placeTo: int|None
): ):
self.competitionClass = competitionClass self.competitionClass = competitionClass
self.nativeClass = nativeClass
self.dance = dance self.dance = dance
self.finalist = finalist self.finalist = finalist
self.place = place self.place = place
@ -185,9 +187,9 @@ class SingleParticipantResult:
asFinalist = ' as finalist' if self.finalist else '' asFinalist = ' as finalist' if self.finalist else ''
if self.placeTo is None: if self.placeTo is None:
return f'SR[{self.place} in {self.dance} {self.competitionClass}{asFinalist}]' return f'SR[{self.place} in {self.dance} {self.competitionClass} ({self.nativeClass}){asFinalist}]'
return f'SR[{self.place}-{self.placeTo} in {self.dance} {self.competitionClass}{asFinalist}]' return f'SR[{self.place}-{self.placeTo} in {self.dance} {self.competitionClass} ({self.nativeClass}){asFinalist}]'
class TotalGroupResult: class TotalGroupResult:
def __init__(self, dances: list[str], results: dict[HtmlPreviewParticipant, list[SingleParticipantResult]]): def __init__(self, dances: list[str], results: dict[HtmlPreviewParticipant, list[SingleParticipantResult]]):

View File

@ -441,7 +441,8 @@ class Worker:
for participant in participants: for participant in participants:
self.l.log(5, 'Collecting data for %s', participant) self.l.log(5, 'Collecting data for %s', participant)
resultsOfParticipant = self._getResultOfSingleParticipant( resultsOfParticipant = self._getResultOfSingleParticipant(
participant, group, importedData.previewImport, importedData.htmlResults, dances participant, group, importedData.previewImport,
importedData.htmlResults, dances
) )
self.l.log(5, 'Obtained result %s', resultsOfParticipant) self.l.log(5, 'Obtained result %s', resultsOfParticipant)
results[participant] = resultsOfParticipant results[participant] = resultsOfParticipant
@ -486,7 +487,7 @@ class Worker:
self, self,
previewData: types.HtmlPreviewImport, previewData: types.HtmlPreviewImport,
group: solo_turnier.group.Group group: solo_turnier.group.Group
) -> list[types.HtmlPreviewParticipant]: ) -> list[types.HtmlPreviewParticipant]:
ret = [] ret = []
for id in previewData.participants: for id in previewData.participants:
participantList = previewData.participants[id] participantList = previewData.participants[id]
@ -502,7 +503,7 @@ class Worker:
previewResults: types.HtmlPreviewImport, previewResults: types.HtmlPreviewImport,
totalResults: types.HtmlCompetitionTotalResults, totalResults: types.HtmlCompetitionTotalResults,
allDances: list[str] allDances: list[str]
) -> list[types.SingleParticipantResult|None]: ) -> list[types.SingleParticipantResult|None]:
rawResults = totalResults.getById(participant.id) rawResults = totalResults.getById(participant.id)
self.l.log(5, 'Found result data (raw): %s', rawResults) self.l.log(5, 'Found result data (raw): %s', rawResults)
@ -520,9 +521,11 @@ class Worker:
raise Exception('Multiple results found with same key') raise Exception('Multiple results found with same key')
rawResult = rawResult[0] rawResult = rawResult[0]
nativeClass = previewResults.results[participant][dance]
# self.l.log(5, 'Result %s => %s', key, rawResult) # self.l.log(5, 'Result %s => %s', key, rawResult)
return types.SingleParticipantResult( return types.SingleParticipantResult(
key[2], dance, rawResult.finalist, key[2], nativeClass, dance, rawResult.finalist,
rawResult.place, rawResult.placeTo rawResult.place, rawResult.placeTo
) )
return None return None