diff --git a/src/solo_turnier/html_parser.py b/src/solo_turnier/html_parser.py index 48661cd..5db8900 100644 --- a/src/solo_turnier/html_parser.py +++ b/src/solo_turnier/html_parser.py @@ -8,6 +8,9 @@ class HtmlParticipant: self.name = name self.place = place self.finalist = finalist + + def __str__(self): + return f'{self.name} (with place {self.place})' class HtmlImport: def __init__(self, title: str, participants: dict[int, HtmlParticipant]): diff --git a/src/solo_turnier/tests/test_worker.py b/src/solo_turnier/tests/test_worker.py index 9fbe0d2..8fcc828 100644 --- a/src/solo_turnier/tests/test_worker.py +++ b/src/solo_turnier/tests/test_worker.py @@ -1,4 +1,4 @@ -from solo_turnier import worker +from solo_turnier import worker, html_parser import os import json import pytest @@ -216,3 +216,97 @@ def test_createHtmlLUT(mocker): ('group3', 'class3', 'dance3'): importMock3, } assert expected == structure + +def test_mergeHtmlData(mocker): + person1 = worker.ResultPerson('Max 1', 'Mustermann', 'TSC Entenhausen') + person2 = worker.ResultPerson('Max 2', 'Mustermann', 'TSC Entenhausen') + person3 = worker.ResultPerson('Max 3', 'Mustermann', 'TSC Entenhausen') + person4 = worker.ResultPerson('Max 4', 'Mustermann', 'TSC Entenhausen') + + data = { + person1: [ + worker.CompetitionResult('Rumba', 'Kin.', 'Beg.', '1', '1', 1, 'Kin./Jun.', 'Beg.'), + worker.CompetitionResult('Cha Cha', 'Kin.', 'Adv.', '1', '1', 1, 'Kin.', 'Adv.'), + worker.CompetitionResult('Jive', 'Kin.', 'Beg.', '1', '2', 1, 'Kin.', 'Beg.'), + worker.CompetitionResult('Langs. Walzer', 'Kin.', 'Beg.', '1', '1', 1, 'Kin.', 'Newc./Beg.'), + ], + person2: [ + worker.CompetitionResult('Rumba', 'Kin.', 'Beg.', '2', '2', 2, 'Kin./Jun.', 'Beg.'), + worker.CompetitionResult('Cha Cha', 'Kin.', 'Adv.', '2', '2', 2, 'Kin.', 'Adv.'), + worker.CompetitionResult('Jive', 'Kin.', 'Beg.', '1', '2', 2, 'Kin.', 'Beg.'), + worker.CompetitionResult('Langs. Walzer', 'Kin.', 'Newc.', '1', '1', 2, 'Kin.', 'Newc./Beg.'), + ], + person3: [ + worker.CompetitionResult('Rumba', 'Jun.', 'Beg.', '1', '1', 3, 'Kin./Jun.', 'Beg.'), + # worker.CompetitionResult('Cha Cha', 'Jun.', 'Adv.', '1', '1', 3, 'Kin.', 'Adv.'), + # worker.CompetitionResult('Jive', 'Jun.', 'Beg.', '2', '2', 3, 'Kin.', 'Beg.'), + # worker.CompetitionResult('Langs. Walzer', 'Jun.', 'Newc./Beg.', '1', '1', 3, 'Kin.', 'Beg.'), + ], + person4: [ + worker.CompetitionResult('Rumba', 'Kin.', 'Beg.', '3', '3', 4, 'Kin./Jun.', 'Beg.'), + # worker.CompetitionResult('Cha Cha', 'Kin.', 'Adv.', '1', '1', 4, 'Kin.', 'Adv.'), + # worker.CompetitionResult('Jive', 'Kin.', 'Beg.', '2', '2', 4, 'Kin.', 'Beg.'), + # worker.CompetitionResult('Langs. Walzer', 'Kin.', 'Newc./Beg.', '1', '1', 4, 'Kin.', 'Beg.'), + ], + } + + htmlParticipant1Dance1 = html_parser.HtmlParticipant('Max 1 Mustermann', '1.', True) + htmlParticipant1Dance2 = html_parser.HtmlParticipant('Max 1 Mustermann', '1.', True) + htmlParticipant1Dance3 = html_parser.HtmlParticipant('Max 1 Mustermann', '1.-2.', True) + htmlParticipant1Dance4 = html_parser.HtmlParticipant('Max 1 Mustermann', '1.', True) + + htmlParticipant2Dance1 = html_parser.HtmlParticipant('Max 2 Mustermann', '2.', True) + htmlParticipant2Dance2 = html_parser.HtmlParticipant('Max 2 Mustermann', '2.', True) + htmlParticipant2Dance3 = html_parser.HtmlParticipant('Max 2 Mustermann', '1.-2.', True) + htmlParticipant2Dance4 = html_parser.HtmlParticipant('Max 2 Mustermann', '1.', True) + + htmlParticipant3Dance1 = html_parser.HtmlParticipant('Max 3 Mustermann', '1.', True) + + htmlParticipant4Dance1 = html_parser.HtmlParticipant('Max 4 Mustermann', '3.', False) + + htmlParticipantsDance1 = { + '1': htmlParticipant1Dance1, + '2': htmlParticipant2Dance1, + '3': htmlParticipant3Dance1, + '4': htmlParticipant4Dance1 + } + htmlParticipantsDance2 = { + '1': htmlParticipant1Dance2, + '2': htmlParticipant2Dance2, + } + htmlParticipantsDance3 = { + '1': htmlParticipant1Dance3, + '2': htmlParticipant2Dance3, + } + htmlParticipantsDance4 = { + '1': htmlParticipant1Dance4, + '2': htmlParticipant2Dance4, + } + + htmlCompetition1 = html_parser.HtmlImport('ETW, Solos Kin./Jun. Beginner Rumba', htmlParticipantsDance1) + htmlCompetition2 = html_parser.HtmlImport('ETW, Solos Kin. Advanced Cha Cha', htmlParticipantsDance2) + htmlCompetition3 = html_parser.HtmlImport('ETW, Solos Kinder Beginner Jive', htmlParticipantsDance3) + htmlCompetition4 = html_parser.HtmlImport('ETW, Solos Kin. Newc./Beg. Langs. Walzer', htmlParticipantsDance4) + + dataWorker = worker.DataWorker() + + dataWorker.mergeHtmlData(data, [htmlCompetition1, htmlCompetition2, htmlCompetition3, htmlCompetition4]) + + person1Finalist = [c.finalist for c in data[person1]] + person2Finalist = [c.finalist for c in data[person2]] + person3Finalist = [c.finalist for c in data[person3]] + person4Finalist = [c.finalist for c in data[person4]] + finalists = { + person1: person1Finalist, + person2: person2Finalist, + person3: person3Finalist, + person4: person4Finalist, + } + expectedFinalists = { + person1: [True, True, True, True], + person2: [True, True, True, True], + person3: [True], + person4: [False], + } + + assert finalists == expectedFinalists diff --git a/src/solo_turnier/worker.py b/src/solo_turnier/worker.py index 1ecd835..9e9cbe4 100644 --- a/src/solo_turnier/worker.py +++ b/src/solo_turnier/worker.py @@ -1,6 +1,7 @@ import logging from solo_turnier import html_parser + class ResultRow: def __init__(self, firstName, lastName, club, id, group, class_, dance, place, placeTo, competitionGroup, competitionClass): self.firstName = firstName @@ -207,3 +208,14 @@ class DataWorker: ret[key] = imp return ret + def mergeHtmlData(self, data:dict[ResultPerson, list[CompetitionResult]], htmlImports: list[html_parser.HtmlImport]): + lut = self._createHtmlLUT(htmlImports) + + for person in data: + for competition in data[person]: + key = (competition.competitionGroup, competition.competitionClass, competition.dance) + htmlImport = lut[key] + participant = htmlImport.participants[str(competition.id)] + if participant.name != person.name: + self.l.error(f'Names for {person} and participant in HTML import ({participant}) do not match. Please check carefully.') + competition.finalist = participant.finalist