70 lines
2.1 KiB
Python
70 lines
2.1 KiB
Python
|
|
||
|
import logging
|
||
|
from tabulate import tabulate
|
||
|
|
||
|
import solo_turnier
|
||
|
|
||
|
sections = ('Kin.', 'Jun.', 'Jug.', 'Sonst')
|
||
|
sectionMap = {
|
||
|
'Kin.': 'Kinder',
|
||
|
'Jun.': 'Junioren',
|
||
|
'Jug.': 'Jugend',
|
||
|
'Sonst': 'Undefiniert'
|
||
|
}
|
||
|
|
||
|
class AbstractOutputter:
|
||
|
def __init__(self):
|
||
|
self.worker = solo_turnier.worker.DataWorker()
|
||
|
self.groups = []
|
||
|
self.dances = []
|
||
|
self.showIds = False
|
||
|
|
||
|
def getRowData(self, person: solo_turnier.worker.ResultPerson, results):
|
||
|
mappedResults = self.worker.mapPersonResultsToDanceList(results, self.dances)
|
||
|
if self.showIds:
|
||
|
name = f'{person.name} ({person.id})'
|
||
|
else:
|
||
|
name = person.name
|
||
|
|
||
|
ret = [name]
|
||
|
for result in mappedResults:
|
||
|
if result is None:
|
||
|
ret.append('')
|
||
|
elif result.finalist == False:
|
||
|
ret.append('x')
|
||
|
elif result.place == result.placeTo:
|
||
|
ret.append(f'{result.place}. ({result.class_})')
|
||
|
else:
|
||
|
ret.append(f'{result.place}.-{result.placeTo}. ({result.class_})')
|
||
|
return ret
|
||
|
|
||
|
def getTabularData(self, data, section):
|
||
|
sortedPersons, self.showIds = self.worker.sortPersonsInGroup(self.groups[section])
|
||
|
|
||
|
tableData = []
|
||
|
for person in sortedPersons:
|
||
|
tableData.append(self.getRowData(person, data[person]))
|
||
|
|
||
|
return tableData
|
||
|
|
||
|
class ConsoleOutputter(AbstractOutputter):
|
||
|
def __init__(self):
|
||
|
super().__init__()
|
||
|
self.l = logging.getLogger('solo_turnier.output.console')
|
||
|
|
||
|
def __outputSection(self, data, section):
|
||
|
tableData = self.getTabularData(data, section)
|
||
|
tableData = [['Name'] + self.dances] + tableData
|
||
|
|
||
|
print(f"Einzeltanzwettbewerb der {sectionMap[section]}")
|
||
|
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)
|
||
|
|
||
|
for section in sections:
|
||
|
if len(self.groups[section]) > 0:
|
||
|
self.__outputSection(data, section)
|