Created first running example but not working with test case 2
This commit is contained in:
parent
c10f5a8774
commit
35edc622c1
1
requiremnts.txt
Normal file
1
requiremnts.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
tabulate==0.9.0
|
@ -2,6 +2,9 @@
|
|||||||
import solo_turnier
|
import solo_turnier
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import pprint
|
||||||
|
|
||||||
|
import tabulate
|
||||||
|
|
||||||
class BatchWorker:
|
class BatchWorker:
|
||||||
def __init__(
|
def __init__(
|
||||||
@ -30,6 +33,11 @@ class BatchWorker:
|
|||||||
'Slowfox': 14,
|
'Slowfox': 14,
|
||||||
'Quickstep': 15
|
'Quickstep': 15
|
||||||
}
|
}
|
||||||
|
self.__groupFinalMap = {
|
||||||
|
'Kinder': 'Kin.',
|
||||||
|
'Junioren': 'Jun.',
|
||||||
|
'Jugend': 'Jug.'
|
||||||
|
}
|
||||||
|
|
||||||
def __extractDataFromFiles(self):
|
def __extractDataFromFiles(self):
|
||||||
allResultName = os.path.join(self.config.importPath(), 'allresults.csv')
|
allResultName = os.path.join(self.config.importPath(), 'allresults.csv')
|
||||||
@ -39,20 +47,20 @@ class BatchWorker:
|
|||||||
finals = []
|
finals = []
|
||||||
|
|
||||||
# Do this in a loop
|
# Do this in a loop
|
||||||
# finalName = os.path.join(self.config.importPath(), 'wert_er.txt')
|
finalName = os.path.join(self.config.importPath(), 'wert_er.txt')
|
||||||
# readerFinal = solo_turnier.reader.ERReader(finalName)
|
readerFinal = solo_turnier.reader.ERReader(finalName)
|
||||||
# result = readerFinal.readFile()
|
result = readerFinal.readFile()
|
||||||
# finals.append(result)
|
finals.append(result)
|
||||||
|
|
||||||
return (allResults, finals)
|
return (allResults, finals)
|
||||||
|
|
||||||
def __convertFinalToTuple(self, result):
|
def __convertFinalToTuple(self, result):
|
||||||
return (
|
return {
|
||||||
result['gruppe'],
|
'group': result['gruppe'],
|
||||||
result['klasse'],
|
'class': result['klasse'],
|
||||||
result['tanz'],
|
'dance': result['tanz'],
|
||||||
result['finalisten']
|
'finalists': result['finalisten']
|
||||||
)
|
}
|
||||||
|
|
||||||
def __extractAllData(self, r):
|
def __extractAllData(self, r):
|
||||||
return {
|
return {
|
||||||
@ -84,27 +92,34 @@ class BatchWorker:
|
|||||||
return person
|
return person
|
||||||
|
|
||||||
def __extractPersons(self, allResults):
|
def __extractPersons(self, allResults):
|
||||||
personRows = [self.__extractPersonData(r) for r in allResults['data']]
|
def decorate(person,i):
|
||||||
return list(set(personRows))
|
return (person.firstName, person.lastName, person.club, i, person)
|
||||||
|
|
||||||
def __extractDanceResult(self, r):
|
personRows = [self.__extractPersonData(r) for r in allResults['data']]
|
||||||
data = self.__extractAllData(r)
|
persons = list(set(personRows))
|
||||||
try:
|
persons = [decorate(p,i) for i,p in enumerate(persons)]
|
||||||
return {
|
persons.sort()
|
||||||
'dance': data['dance'],
|
persons = [p[4] for p in persons]
|
||||||
'class': data['personClass'],
|
return persons
|
||||||
'place': int(data['place']),
|
|
||||||
'placeTo': int(data['placeTo']),
|
|
||||||
'id': data['id']
|
|
||||||
}
|
|
||||||
except ValueError:
|
|
||||||
self.l.debug('Issue found with data %s.', data)
|
|
||||||
return None
|
|
||||||
|
|
||||||
def __extractAllResults(self, allResults, persons: list[solo_turnier.participant.Person]):
|
def __extractAllResults(self, allResults, persons: list[solo_turnier.participant.Person]):
|
||||||
|
def __extractDanceResult(r):
|
||||||
|
data = self.__extractAllData(r)
|
||||||
|
try:
|
||||||
|
return {
|
||||||
|
'dance': data['dance'],
|
||||||
|
'class': data['personClass'],
|
||||||
|
'place': int(data['place']),
|
||||||
|
'placeTo': int(data['placeTo']),
|
||||||
|
'id': data['id']
|
||||||
|
}
|
||||||
|
except ValueError:
|
||||||
|
self.l.debug('Issue found with data %s.', data)
|
||||||
|
return None
|
||||||
|
|
||||||
ret = {}
|
ret = {}
|
||||||
for row in allResults['data']:
|
for row in allResults['data']:
|
||||||
danceResult = self.__extractDanceResult(row)
|
danceResult = __extractDanceResult(row)
|
||||||
if danceResult is not None:
|
if danceResult is not None:
|
||||||
person = self.__extractPersonData(row)
|
person = self.__extractPersonData(row)
|
||||||
if person not in ret:
|
if person not in ret:
|
||||||
@ -126,6 +141,21 @@ class BatchWorker:
|
|||||||
competitions.sort()
|
competitions.sort()
|
||||||
competitions = [r[2] for r in competitions]
|
competitions = [r[2] for r in competitions]
|
||||||
return competitions
|
return competitions
|
||||||
|
|
||||||
|
|
||||||
|
def __extractGroups(self, allResults):
|
||||||
|
def __extractGroupEntries(r):
|
||||||
|
data = self.__extractAllData(r)
|
||||||
|
return data['personGroup']
|
||||||
|
|
||||||
|
def __decorate(r):
|
||||||
|
return (self.__groupMap[r], r)
|
||||||
|
|
||||||
|
rows = [__extractGroupEntries(r) for r in allResults['data']]
|
||||||
|
groups = [__decorate(r) for r in list(set(rows))]
|
||||||
|
groups.sort()
|
||||||
|
groups = [r[1] for r in groups]
|
||||||
|
return groups
|
||||||
|
|
||||||
def __extarctBasicData(self, allResults):
|
def __extarctBasicData(self, allResults):
|
||||||
def __extractRow(r):
|
def __extractRow(r):
|
||||||
@ -152,12 +182,116 @@ class BatchWorker:
|
|||||||
totalResults = self.__extractAllResults(allResults, persons)
|
totalResults = self.__extractAllResults(allResults, persons)
|
||||||
self.l.debug('Total results: %s', totalResults)
|
self.l.debug('Total results: %s', totalResults)
|
||||||
|
|
||||||
competitions = self.__extractCompetitions(allResults)
|
groups = self.__extractGroups(allResults)
|
||||||
self.l.debug('Competitions: %s', competitions)
|
self.l.debug('Found groups: %s', groups)
|
||||||
|
|
||||||
|
groupRes = {}
|
||||||
|
for group in groups:
|
||||||
|
self.l.info('Processing group %s', group)
|
||||||
|
groupRes[group] = {}
|
||||||
|
|
||||||
|
personsInGroup = [p for p in persons if p.group == group]
|
||||||
|
self.l.debug('Remaining persons: %s', personsInGroup)
|
||||||
|
groupRes[group]['participants'] = personsInGroup
|
||||||
|
|
||||||
|
groupRes[group]['results'] = {}
|
||||||
|
for person in personsInGroup:
|
||||||
|
groupRes[group]['results'][person] = totalResults[person]
|
||||||
|
# resultsInGroup = totalResults[personsInGroup]
|
||||||
|
# self.l.debug('Results in group: %s', resultsInGroup)
|
||||||
|
|
||||||
|
# Do this in a loop
|
||||||
|
finalists = [self.__convertFinalToTuple(r) for r in finals]
|
||||||
|
self.l.debug('Mapped to tuples: %s', finalists)
|
||||||
|
|
||||||
|
self.l.info('Augmenting the list of participants')
|
||||||
|
for finalistList in finalists:
|
||||||
|
self.l.debug('Augmenting competition %s', finalistList)
|
||||||
|
longGroup = finalistList['group']
|
||||||
|
grep = self.__groupFinalMap[longGroup]
|
||||||
|
|
||||||
|
for person in groupRes[group]['results'].keys():
|
||||||
|
self.l.debug('Checking %s for finalist state in competition', person)
|
||||||
|
for competition in groupRes[group]['results'][person]:
|
||||||
|
if competition['dance'] != finalistList['dance']:
|
||||||
|
continue
|
||||||
|
if competition['class'] != finalistList['class']:
|
||||||
|
continue
|
||||||
|
|
||||||
|
competition['finalist'] = (competition['id'] in finalistList['finalists'])
|
||||||
|
self.l.debug('Organized results: %s', groupRes)
|
||||||
|
|
||||||
|
dancesRaw = [competition['dance'] for group in groups for person in groupRes[group]['participants'] for competition in groupRes[group]['results'][person]]
|
||||||
|
dances = list(set(dancesRaw))
|
||||||
|
dances = [(self.__danceMap[d], d) for d in dances]
|
||||||
|
dances.sort()
|
||||||
|
dances = [r[1] for r in dances]
|
||||||
|
self.l.debug('Found dances in competition: %s', dances)
|
||||||
|
|
||||||
|
ret = {}
|
||||||
|
for group in groups:
|
||||||
|
ret[group] = {}
|
||||||
|
|
||||||
|
for person in groupRes[group]['participants']:
|
||||||
|
ret[group][person] = {}
|
||||||
|
# Seed the data structure
|
||||||
|
for dance in dances:
|
||||||
|
ret[group][person][dance] = {
|
||||||
|
'participated': False,
|
||||||
|
'class': '',
|
||||||
|
'finalist': False,
|
||||||
|
'place': '',
|
||||||
|
'id': 0
|
||||||
|
}
|
||||||
|
|
||||||
|
for competition in groupRes[group]['results'][person]:
|
||||||
|
def __getPlace():
|
||||||
|
if competition['place'] == competition['placeTo']:
|
||||||
|
return str(competition['place'])
|
||||||
|
else:
|
||||||
|
return f"{competition['place']}-{competition['placeTo']}"
|
||||||
|
|
||||||
|
dance = competition['dance']
|
||||||
|
ret[group][person][dance]['participated'] = True
|
||||||
|
ret[group][person][dance]['class'] = competition['class']
|
||||||
|
ret[group][person][dance]['finalist'] = competition.get('finalist', False)
|
||||||
|
ret[group][person][dance]['place'] = __getPlace()
|
||||||
|
ret[group][person][dance]['id'] = competition['id']
|
||||||
|
|
||||||
|
self.l.debug('Returned data: %s', pprint.pformat(ret))
|
||||||
|
|
||||||
|
for group in groups:
|
||||||
|
self.l.debug('Outputting table for group %s', group)
|
||||||
|
|
||||||
|
print(f'Ergebnisse der Gruppe {group}')
|
||||||
|
print()
|
||||||
|
|
||||||
|
row = ['Teilnehmer(in)'] + dances
|
||||||
|
table = [row]
|
||||||
|
|
||||||
|
for person in ret[group]:
|
||||||
|
row = [str(person)]
|
||||||
|
for dance in dances:
|
||||||
|
if not ret[group][person][dance]['participated']:
|
||||||
|
row.append('')
|
||||||
|
continue
|
||||||
|
if not ret[group][person][dance]['finalist']:
|
||||||
|
row.append('x')
|
||||||
|
continue
|
||||||
|
row.append(f"{ret[group][person][dance]['place']} ({ret[group][person][dance]['class']}, {ret[group][person][dance]['id']})")
|
||||||
|
table.append(row)
|
||||||
|
|
||||||
|
self.l.debug(table)
|
||||||
|
# print(tabulate.tabulate(table))
|
||||||
|
print(tabulate.tabulate(table, headers='firstrow', tablefmt='fancy_grid'))
|
||||||
|
print()
|
||||||
|
|
||||||
|
|
||||||
|
# self.l.debug('Organized results: %s', pprint.pformat( groupRes['Jun.']))
|
||||||
|
# competitions = self.__extractCompetitions(allResults)
|
||||||
|
# self.l.debug('Competitions: %s', competitions)
|
||||||
|
|
||||||
# basicData = self.__extarctBasicData(allResults)
|
# basicData = self.__extarctBasicData(allResults)
|
||||||
# self.l.debug('Basic extracted data: %s', basicData)
|
# self.l.debug('Basic extracted data: %s', basicData)
|
||||||
|
|
||||||
# finalTuples = [self.__convertFinalToTuple(r) for r in finals]
|
|
||||||
# self.l.debug('Mapped to tuples: %s', finalTuples)
|
|
||||||
|
|
||||||
|
@ -13,6 +13,9 @@ class Person:
|
|||||||
self.group = group
|
self.group = group
|
||||||
|
|
||||||
def __eq__(self, o):
|
def __eq__(self, o):
|
||||||
|
if not isinstance(o, Person):
|
||||||
|
False
|
||||||
|
|
||||||
return (
|
return (
|
||||||
self.firstName == o.firstName and
|
self.firstName == o.firstName and
|
||||||
self.lastName == o.lastName and
|
self.lastName == o.lastName and
|
||||||
|
@ -49,12 +49,15 @@ class ERReader:
|
|||||||
|
|
||||||
if found == -1:
|
if found == -1:
|
||||||
raise Exception(f'Could not find the dance in the result file.')
|
raise Exception(f'Could not find the dance in the result file.')
|
||||||
|
pass
|
||||||
|
|
||||||
# Extract the finalists
|
# Extract the finalists
|
||||||
finalists = []
|
finalists = []
|
||||||
for i in range(found + 1, len(restLines)):
|
for i in range(found + 1, len(restLines)):
|
||||||
if restLines[i].startswith('TopTurnier'):
|
if restLines[i].startswith('TopTurnier'):
|
||||||
break
|
break
|
||||||
|
|
||||||
|
# self.l.debug('Parsing line "%s"', restLines[i].strip())
|
||||||
|
|
||||||
match = re.compile('[0-9]+').match(restLines[i].strip())
|
match = re.compile('[0-9]+').match(restLines[i].strip())
|
||||||
if match is None:
|
if match is None:
|
||||||
|
Loading…
Reference in New Issue
Block a user