Map individual results onto common table rows

This commit is contained in:
Christian Wolf 2022-11-15 19:37:08 +01:00
parent 04d8cdf52b
commit 3dfc022b08
2 changed files with 23 additions and 0 deletions

View File

@ -383,3 +383,14 @@ def test_sortPersons_withoutId(mocker):
sorted, showIds = dataWorker.sortPersonsInGroup(persons)
assert sorted == [persons[3], persons[1], persons[0], persons[2]]
assert showIds == False
def test_mapPersonResultsToDanceList(mocker):
def mockResult(dance):
mock = mocker.patch('solo_turnier.worker.CompetitionResult')
mock.dance = dance
return mock
dances = ['Cha Cha', 'Rumba', 'Langs. Walzer', 'Quickstep']
results = [mockResult('Rumba'), mockResult('Quickstep'), mockResult('Cha Cha')]
dataWorker = worker.DataWorker()
mappedResults = dataWorker.mapPersonResultsToDanceList(results, dances)
assert mappedResults == [results[2], results[0], None, results[1]]

View File

@ -264,3 +264,15 @@ class DataWorker:
return ([d[1] for d in decorated], showIds)
def mapPersonResultsToDanceList(self, results: list[CompetitionResult], dances: list[str]) -> list[CompetitionResult|None]:
ret = []
for dance in dances:
competitions = [c for c in results if c.dance == dance]
if len(competitions) == 0:
ret.append(None)
elif len(competitions) > 1:
raise Exception(f'Multiple competitions with the same dance "{dance}" found.')
else:
ret.append(competitions[0])
return ret