Sort persons according to the best ordering
This commit is contained in:
parent
fb7b1f72eb
commit
04d8cdf52b
@ -358,3 +358,28 @@ def test_collectPersonsInGroups(mocker):
|
|||||||
assert groups['Jun.'] == [persons[2], persons[8]]
|
assert groups['Jun.'] == [persons[2], persons[8]]
|
||||||
assert groups['Jug.'] == [persons[5]]
|
assert groups['Jug.'] == [persons[5]]
|
||||||
assert groups['Sonst'] == [persons[4], persons[6], persons[7]]
|
assert groups['Sonst'] == [persons[4], persons[6], persons[7]]
|
||||||
|
|
||||||
|
def test_sortPersons_withId(mocker):
|
||||||
|
def mockPerson(id):
|
||||||
|
mock = mocker.patch('solo_turnier.worker.ResultPerson')
|
||||||
|
mock.id = id
|
||||||
|
return mock
|
||||||
|
persons = [mockPerson(2), mockPerson(1), mockPerson(5), mockPerson(3)]
|
||||||
|
dataWorker = worker.DataWorker()
|
||||||
|
sorted, showIds = dataWorker.sortPersonsInGroup(persons)
|
||||||
|
assert sorted == [persons[1], persons[0], persons[3], persons[2]]
|
||||||
|
assert showIds == True
|
||||||
|
|
||||||
|
def test_sortPersons_withoutId(mocker):
|
||||||
|
def mockPerson(name):
|
||||||
|
mock = mocker.patch('solo_turnier.worker.ResultPerson')
|
||||||
|
mock.id = 3
|
||||||
|
mock.name = name
|
||||||
|
mock.club = 'TSC Entenhausen'
|
||||||
|
return mock
|
||||||
|
persons = [mockPerson('Max'), mockPerson('Isabel'), mockPerson('Reimund'), mockPerson('Anna')]
|
||||||
|
persons[2].id = None
|
||||||
|
dataWorker = worker.DataWorker()
|
||||||
|
sorted, showIds = dataWorker.sortPersonsInGroup(persons)
|
||||||
|
assert sorted == [persons[3], persons[1], persons[0], persons[2]]
|
||||||
|
assert showIds == False
|
||||||
|
@ -243,3 +243,24 @@ class DataWorker:
|
|||||||
found = groups['Kin.'] + groups['Jun.'] + groups['Jug.']
|
found = groups['Kin.'] + groups['Jun.'] + groups['Jug.']
|
||||||
groups['Sonst'] = [p for p in data.keys() if p not in found]
|
groups['Sonst'] = [p for p in data.keys() if p not in found]
|
||||||
return groups
|
return groups
|
||||||
|
|
||||||
|
def sortPersonsInGroup(self, persons: list[ResultPerson]) -> list[ResultPerson]:
|
||||||
|
ids = [p.id for p in persons]
|
||||||
|
|
||||||
|
def decorateByName(p: ResultPerson):
|
||||||
|
return (f'{p.name} ({p.club})', p)
|
||||||
|
def decorateById(p: ResultPerson):
|
||||||
|
return (p.id, p)
|
||||||
|
|
||||||
|
if any([id == None for id in ids]):
|
||||||
|
# We need to sort by name
|
||||||
|
decorated = [decorateByName(p) for p in persons]
|
||||||
|
showIds = False
|
||||||
|
else:
|
||||||
|
decorated = [decorateById(p) for p in persons]
|
||||||
|
showIds = True
|
||||||
|
|
||||||
|
decorated.sort()
|
||||||
|
|
||||||
|
return ([d[1] for d in decorated], showIds)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user