Make output work in general
This commit is contained in:
parent
0d1310f287
commit
04803e21ed
@ -186,7 +186,10 @@ class BatchWorker:
|
||||
|
||||
worker = solo_turnier.worker.Worker()
|
||||
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())
|
||||
# self.l.info('Loading the total result CSV file %s', self.config.importCSVPath())
|
||||
|
@ -1,8 +1,10 @@
|
||||
|
||||
import logging
|
||||
from tabulate import tabulate
|
||||
import pprint
|
||||
|
||||
import solo_turnier
|
||||
from solo_turnier import types
|
||||
|
||||
sections = ('Kin.', 'Jun.', 'Jug.', 'Sonst')
|
||||
sectionMap = {
|
||||
@ -60,10 +62,50 @@ class ConsoleOutputter(AbstractOutputter):
|
||||
print(tabulate(tableData, headers='firstrow', tablefmt='fancy_grid'))
|
||||
print()
|
||||
|
||||
def output(self, data):
|
||||
self.groups = self.worker.collectPersonsInGroups(data)
|
||||
self.dances = self.worker.getAllDancesInCompetitions(data)
|
||||
def _outputGroup(self, group: solo_turnier.group.Group, groupResults: types.TotalGroupResult):
|
||||
print(f"Einzeltanzwettbewerb der Gruppe {group}")
|
||||
|
||||
for section in sections:
|
||||
if len(self.groups[section]) > 0:
|
||||
self.__outputSection(data, section)
|
||||
tableData = [['Tanz'] + groupResults.dances]
|
||||
participants = list(groupResults.results.keys())
|
||||
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)
|
||||
|
@ -167,12 +167,14 @@ class SingleParticipantResult:
|
||||
def __init__(
|
||||
self,
|
||||
competitionClass: competition_class.Class_t,
|
||||
nativeClass: competition_class.CompetitionClass,
|
||||
dance: str,
|
||||
finalist: bool,
|
||||
place: int,
|
||||
placeTo: int|None
|
||||
):
|
||||
self.competitionClass = competitionClass
|
||||
self.nativeClass = nativeClass
|
||||
self.dance = dance
|
||||
self.finalist = finalist
|
||||
self.place = place
|
||||
@ -185,9 +187,9 @@ class SingleParticipantResult:
|
||||
asFinalist = ' as finalist' if self.finalist else ''
|
||||
|
||||
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:
|
||||
def __init__(self, dances: list[str], results: dict[HtmlPreviewParticipant, list[SingleParticipantResult]]):
|
||||
|
@ -441,7 +441,8 @@ class Worker:
|
||||
for participant in participants:
|
||||
self.l.log(5, 'Collecting data for %s', participant)
|
||||
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)
|
||||
results[participant] = resultsOfParticipant
|
||||
@ -486,7 +487,7 @@ class Worker:
|
||||
self,
|
||||
previewData: types.HtmlPreviewImport,
|
||||
group: solo_turnier.group.Group
|
||||
) -> list[types.HtmlPreviewParticipant]:
|
||||
) -> list[types.HtmlPreviewParticipant]:
|
||||
ret = []
|
||||
for id in previewData.participants:
|
||||
participantList = previewData.participants[id]
|
||||
@ -502,7 +503,7 @@ class Worker:
|
||||
previewResults: types.HtmlPreviewImport,
|
||||
totalResults: types.HtmlCompetitionTotalResults,
|
||||
allDances: list[str]
|
||||
) -> list[types.SingleParticipantResult|None]:
|
||||
) -> list[types.SingleParticipantResult|None]:
|
||||
rawResults = totalResults.getById(participant.id)
|
||||
self.l.log(5, 'Found result data (raw): %s', rawResults)
|
||||
|
||||
@ -520,9 +521,11 @@ class Worker:
|
||||
raise Exception('Multiple results found with same key')
|
||||
rawResult = rawResult[0]
|
||||
|
||||
nativeClass = previewResults.results[participant][dance]
|
||||
|
||||
# self.l.log(5, 'Result %s => %s', key, rawResult)
|
||||
return types.SingleParticipantResult(
|
||||
key[2], dance, rawResult.finalist,
|
||||
key[2], nativeClass, dance, rawResult.finalist,
|
||||
rawResult.place, rawResult.placeTo
|
||||
)
|
||||
return None
|
||||
|
Loading…
Reference in New Issue
Block a user