Map individual results onto common table rows
This commit is contained in:
parent
04d8cdf52b
commit
3dfc022b08
@ -383,3 +383,14 @@ def test_sortPersons_withoutId(mocker):
|
|||||||
sorted, showIds = dataWorker.sortPersonsInGroup(persons)
|
sorted, showIds = dataWorker.sortPersonsInGroup(persons)
|
||||||
assert sorted == [persons[3], persons[1], persons[0], persons[2]]
|
assert sorted == [persons[3], persons[1], persons[0], persons[2]]
|
||||||
assert showIds == False
|
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]]
|
||||||
|
@ -264,3 +264,15 @@ class DataWorker:
|
|||||||
|
|
||||||
return ([d[1] for d in decorated], showIds)
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user