Enhance data structure to reuse common class objects

This commit is contained in:
Christian Wolf 2023-11-20 11:12:50 +01:00
parent 16d78e18f3
commit 69e20dd4c8
4 changed files with 19 additions and 17 deletions

View File

@ -16,7 +16,7 @@ sectionMap = {
class AbstractOutputter:
def __init__(self):
self.worker = solo_turnier.worker.DataWorker()
self.worker = solo_turnier.workers.DataWorker.DataWorker()
self.groups = []
self.dances = []
self.showIds = False

View File

@ -1,6 +1,15 @@
from .reader import ResultRow
# import logging
# from pprint import pformat
# import re
# import solo_turnier
# from .types import HtmlCompetitionResultRow as CompetitionResult
# from . import types
# from . import competition_class
class HtmlPerson:

View File

@ -2,6 +2,7 @@ from ..reader import ResultRow
from ..worker import ResultPerson
from ..types import HtmlCompetitionResultRow as CompetitionResult
from solo_turnier import html_parser
import logging
class DataWorker:

View File

@ -42,6 +42,7 @@ class Worker:
self.l.log(5, "Inverted group maping: %s", invertedGroupMapping)
totalResult = {}
ret = types.State4(totalResult)
for group in groups:
self.l.debug("Collecting data for total result of group %s", group)
@ -75,32 +76,27 @@ class Worker:
self.l.log(5, "Total result of all groups: %s", pformat(totalResult))
ret = types.State4(totalResult)
return ret
def _extractGroups(self, data: types.State3):
groupParser = solo_turnier.group.GroupParser()
groupSet = set([])
# for id in data.previewImport.participants:
# participants = data.previewImport.participants[id]
# for participant in participants:
# groupSet.add(participant.group)
for tup in data.htmlResults.results.keys():
gr = groupParser.parseClass(tup[0])
gr = self._groupParser.parseClass(tup[0])
# groupSet.add(gr)
groupSet.update(gr.getContainedGroups())
# self.l.log(5, 'Group type %s', type(gr))
self.l.log(5, "Set of active groups: %s", groupSet)
groups = groupParser.getGroupsAsSortedList(groupSet)
groups = self._groupParser.getGroupsAsSortedList(groupSet)
return groups
def _getGroupMapping(
self, importedData: types.State3
) -> dict[int, solo_turnier.group.Group | None]:
groupParser = solo_turnier.group.GroupParser()
def _getBestGroupGuess(groups, id):
counts = {}
grNones = 0
@ -141,11 +137,11 @@ class Worker:
groupsPerId = {}
for tup in importedData.htmlResults.results:
competitionGroup = groupParser.parseClass(tup[0])
competitionGroup = self._groupParser.parseClass(tup[0])
fixture = importedData.htmlResults.tabges.get(tup, (None, None, None))
id = int(tup[3])
if fixture[2] is not None:
group = groupParser.parseClass(fixture[2])
group = self._groupParser.parseClass(fixture[2])
else:
containedGroups = competitionGroup.getContainedGroups()
if len(containedGroups) > 1:
@ -202,13 +198,11 @@ class Worker:
def _extractDancesPerGroup(
self, data: types.State3, group: solo_turnier.group.Group
):
groupParser = solo_turnier.group.GroupParser()
dances = set()
additionalDances = set()
foundDances = set()
for tup in data.htmlResults.results.keys():
currentGroup = groupParser.parseClass(tup[0])
currentGroup = self._groupParser.parseClass(tup[0])
if group not in currentGroup.getContainedGroups():
continue
foundDances.add(tup[2])
@ -233,15 +227,13 @@ class Worker:
# previewData: types.HtmlPreviewImport,
group: solo_turnier.group.Group,
) -> list[types.HtmlPreviewParticipant]:
groupParser = types.group.GroupParser()
ret = []
# self.l.log(5, 'Table %s', pformat(importedData.htmlResults.tabges))
# self.l.log(5, 'Results %s', pformat(importedData.htmlResults.results))
for tup in importedData.htmlResults.results.keys():
currentGroup = groupParser.parseClass(tup[0])
currentGroup = self._groupParser.parseClass(tup[0])
activeGroups = currentGroup.getContainedGroups()
if group not in activeGroups:
continue
@ -252,7 +244,7 @@ class Worker:
else:
if (
fixture[2] is not None
and groupParser.parseClass(fixture[2]) != group
and self._groupParser.parseClass(fixture[2]) != group
):
self.l.log(
5,