Group persons according to their groups
This commit is contained in:
parent
32ed966e74
commit
fb7b1f72eb
@ -339,3 +339,22 @@ def test_getAllDancesInCompetitions(fixture_getAllDancesInCompetition):
|
|||||||
dataWorker = worker.DataWorker()
|
dataWorker = worker.DataWorker()
|
||||||
ret = dataWorker.getAllDancesInCompetitions(data)
|
ret = dataWorker.getAllDancesInCompetitions(data)
|
||||||
assert ret == fixture_getAllDancesInCompetition[1]
|
assert ret == fixture_getAllDancesInCompetition[1]
|
||||||
|
|
||||||
|
def test_collectPersonsInGroups(mocker):
|
||||||
|
def mockPerson(group):
|
||||||
|
mock = mocker.patch('solo_turnier.worker.ResultPerson')
|
||||||
|
mock.group = group
|
||||||
|
return mock
|
||||||
|
persons = (
|
||||||
|
mockPerson('Kin.'), mockPerson('Kin.'), mockPerson('Jun.'),
|
||||||
|
mockPerson('Kin.'), mockPerson(None), mockPerson('Jug.'),
|
||||||
|
mockPerson(None), mockPerson('Kin./Jun.'), mockPerson('Jun.')
|
||||||
|
)
|
||||||
|
data = {p: [] for p in persons}
|
||||||
|
dataWorker = worker.DataWorker()
|
||||||
|
groups = dataWorker.collectPersonsInGroups(data)
|
||||||
|
|
||||||
|
assert groups['Kin.'] == [persons[0], persons[1], persons[3]]
|
||||||
|
assert groups['Jun.'] == [persons[2], persons[8]]
|
||||||
|
assert groups['Jug.'] == [persons[5]]
|
||||||
|
assert groups['Sonst'] == [persons[4], persons[6], persons[7]]
|
||||||
|
@ -233,3 +233,13 @@ class DataWorker:
|
|||||||
dancesPresent[competition.dance] = True
|
dancesPresent[competition.dance] = True
|
||||||
|
|
||||||
return [d for d in allDances if dancesPresent[d]]
|
return [d for d in allDances if dancesPresent[d]]
|
||||||
|
|
||||||
|
def collectPersonsInGroups(self, data:dict[ResultPerson, list[CompetitionResult]]) -> list[tuple[str, list[ResultPerson]]]:
|
||||||
|
groups = {
|
||||||
|
'Kin.': [p for p in data.keys() if p.group == 'Kin.'],
|
||||||
|
'Jun.': [p for p in data.keys() if p.group == 'Jun.'],
|
||||||
|
'Jug.': [p for p in data.keys() if p.group == 'Jug.'],
|
||||||
|
}
|
||||||
|
found = groups['Kin.'] + groups['Jun.'] + groups['Jug.']
|
||||||
|
groups['Sonst'] = [p for p in data.keys() if p not in found]
|
||||||
|
return groups
|
||||||
|
Loading…
Reference in New Issue
Block a user