Skip to content

Commit 8345e7d

Browse files
committed
get final results
1 parent 07b9e03 commit 8345e7d

File tree

4 files changed

+89
-24
lines changed

4 files changed

+89
-24
lines changed

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
**/__pycache__
22
.pytest_cache
3-
teams.json
4-
in/*.csv
53
.coverage
64
htmlcov
5+
6+
in/*.csv
7+
teams.json
8+
teams-calculated.json

src/__init__.py

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ def download():
3636
print("Download complete")
3737

3838

39+
def printTeamTable(teams):
40+
titleString = f"│ N │{"Nátev týmu":32}{"ID":^5}│Kat.│Body│Poř. glob.|Poř. v kat.|"
41+
print("—"*len(titleString))
42+
print(titleString)
43+
print("—"*len(titleString))
44+
for i in range(len(teams)):
45+
team = teams[i]
46+
print(
47+
f"│{i+1:>3}{team.name:<32}{team.teamId:>5}{team.category:^4}{team.pointsSum:>4}{team.rankTotal:>10}{team.rankCategory:>11}│"
48+
)
49+
print("—"*len(titleString))
50+
51+
3952
def process():
4053
# load teams
4154
if not os.path.exists(TEAM_JSON):
@@ -53,7 +66,6 @@ def process():
5366
sys.exit()
5467

5568
inputFiles = glob.glob(IN_DIR + "/*.csv")
56-
print(inputFiles)
5769

5870
if (len(inputFiles) == 0):
5971
print("No input file found")
@@ -62,7 +74,6 @@ def process():
6274
teamTasks = {}
6375
for inputFile in inputFiles:
6476
parseFile(inputFile, teamTasks)
65-
print(teamTasks)
6677

6778
teamPoints = getTeamPoints(teamTasks)
6879

@@ -72,13 +83,71 @@ def process():
7283
teamsJsonData[str(teamId)]['members'])
7384
teams.append(Team(
7485
teamId,
86+
teamsJsonData[str(teamId)]['name'],
7587
teamPoints[teamId],
7688
coeffAvg,
7789
teamsJsonData[str(teamId)]['category']
7890
))
7991

92+
# rank teams
93+
teamsA = sorted([team for team in teams.copy() if team.category == 'A'])
94+
teamsB = sorted([team for team in teams.copy() if team.category == 'B'])
95+
teamsC = sorted([team for team in teams.copy() if team.category == 'C'])
8096
teams.sort()
81-
print(teams)
97+
98+
# save team ranks
99+
for i in range(len(teams)):
100+
teams[i].rankTotal = i+1
101+
for group in [teamsA, teamsB, teamsC]:
102+
for i in range(len(group)):
103+
group[i].rankCategory = i+1
104+
105+
# update original JSON data
106+
for team in teams:
107+
teamsJsonData[str(team.teamId)]['rankTotal'] = team.rankTotal
108+
teamsJsonData[str(team.teamId)]['rankCategory'] = team.rankCategory
109+
teamsJsonData[str(team.teamId)]['points'] = team.pointsSum
110+
teamsJsonData[str(team.teamId)]['state'] = 'participated'
111+
112+
with open('teams-calculated.json', 'w') as file:
113+
json.dump(teamsJsonData, file)
114+
115+
# print results
116+
print("\nTýmy seřazeny dle pořadí\n")
117+
print("Globální pořadí")
118+
printTeamTable(teams)
119+
print()
120+
print("Kategorie A")
121+
printTeamTable(teamsA)
122+
print()
123+
print("Kategorie B")
124+
printTeamTable(teamsB)
125+
print()
126+
print("Kategorie C")
127+
printTeamTable(teamsC)
128+
129+
# print sorted by team name
130+
teamsByName = teams.copy()
131+
teamsByNameA = teamsA.copy()
132+
teamsByNameB = teamsB.copy()
133+
teamsByNameC = teamsC.copy()
134+
sorted(teamsByName, key=lambda team: team.name)
135+
sorted(teamsByNameA, key=lambda team: team.name)
136+
sorted(teamsByNameB, key=lambda team: team.name)
137+
sorted(teamsByNameC, key=lambda team: team.name)
138+
139+
print("\nTýmy seřazeny dle názvu\n")
140+
print("Všechny týmy")
141+
printTeamTable(teams)
142+
print()
143+
print("Kategorie A")
144+
printTeamTable(teamsA)
145+
print()
146+
print("Kategorie B")
147+
printTeamTable(teamsB)
148+
print()
149+
print("Kategorie C")
150+
printTeamTable(teamsC)
82151

83152

84153
def main():

src/teams.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ def __init__(self, studyYear) -> None:
2121

2222

2323
class Team:
24-
def __init__(self, teamId, points, coefficientAverage, category) -> None:
24+
def __init__(self, teamId, name, points, coefficientAverage, category) -> None:
2525
self.teamId = teamId
26+
self.name = name
2627
self.pointsSum = points['sum']
2728
self.pointsCounts = points['counts']
2829
self.coefficientAverage = coefficientAverage
2930
self.category = category
31+
self.rankCategory = 0
32+
self.rankTotal = 0
3033

3134
def __repr__(self) -> str:
3235
return f"<{self.teamId}, {self.category}>"

src/teams_test.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ def test_points_sum():
112112

113113
def get_test_teams():
114114
return [
115-
Team(8, {'sum': 15, 'counts': {5: 3}}, 4, 'A'),
116-
Team(2, {'sum': 8, 'counts': {5: 1, 3: 1}}, 4, 'B'),
117-
Team(1, {'sum': 8, 'counts': {5: 1, 2: 1, 1: 1}}, 4, 'A'),
118-
Team(4, {'sum': 8, 'counts': {3: 2, 2: 1}}, 4, 'B'),
119-
Team(3, {'sum': 4, 'counts': {3: 1, 1: 1}}, 4, 'A'),
120-
Team(7, {'sum': 4, 'counts': {2: 2}}, 1, 'A'),
121-
Team(5, {'sum': 4, 'counts': {2: 2}}, 4, 'B'),
122-
Team(6, {'sum': 4, 'counts': {2: 2}}, 4, 'A')
115+
Team(8, 'A', {'sum': 15, 'counts': {5: 3}}, 4, 'A'),
116+
Team(2, 'A', {'sum': 8, 'counts': {5: 1, 3: 1}}, 4, 'B'),
117+
Team(1, 'A', {'sum': 8, 'counts': {5: 1, 2: 1, 1: 1}}, 4, 'A'),
118+
Team(4, 'A', {'sum': 8, 'counts': {3: 2, 2: 1}}, 4, 'B'),
119+
Team(3, 'A', {'sum': 4, 'counts': {3: 1, 1: 1}}, 4, 'A'),
120+
Team(7, 'A', {'sum': 4, 'counts': {2: 2}}, 1, 'A'),
121+
Team(5, 'A', {'sum': 4, 'counts': {2: 2}}, 4, 'B'),
122+
Team(6, 'A', {'sum': 4, 'counts': {2: 2}}, 4, 'A')
123123
]
124124

125125

@@ -140,16 +140,7 @@ def test_team_compare_gt():
140140

141141

142142
def test_team_sort():
143-
teams = [
144-
Team(8, {'sum': 15, 'counts': {5: 3}}, 4, 'A'),
145-
Team(2, {'sum': 8, 'counts': {5: 1, 3: 1}}, 4, 'B'),
146-
Team(1, {'sum': 8, 'counts': {5: 1, 2: 1, 1: 1}}, 4, 'A'),
147-
Team(4, {'sum': 8, 'counts': {3: 2, 2: 1}}, 4, 'B'),
148-
Team(3, {'sum': 4, 'counts': {3: 1, 1: 1}}, 4, 'A'),
149-
Team(7, {'sum': 4, 'counts': {2: 2}}, 1, 'A'),
150-
Team(5, {'sum': 4, 'counts': {2: 2}}, 4, 'B'),
151-
Team(6, {'sum': 4, 'counts': {2: 2}}, 4, 'A')
152-
]
143+
teams = get_test_teams()
153144
sorted(teams, key=lambda team: team.teamId)
154145
print(teams)
155146
assert teams[0].teamId == 8

0 commit comments

Comments
 (0)