forked from AndKenneth/ozf-voting-tools
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnominations.py
128 lines (101 loc) · 3.87 KB
/
nominations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import argparse
import json
def main():
parser = argparse.ArgumentParser()
parser.add_argument('file')
args = parser.parse_args()
nominations_list = read_nominations_file(args.file)
teams = create_team_objects(nominations_list)
divisions = sort_teams(teams)
for name, teams in sorted(divisions.items()):
create_division_report(name, teams)
def read_nominations_file(filename):
with open(filename, 'r') as nominations_file:
nominations_list = nominations_file.readlines()
nominations_list = [line.strip()
for line in nominations_list
if line != '\n' and line != '']
return nominations_list
def create_team_objects(nominations_list):
current_team = ''
teams = {}
for line in nominations_list:
heading, data = line.split(':', 1)
heading = heading.strip()
data = data.strip()
if 'Team Name' in heading:
current_team = data
teams[current_team] = {}
elif 'Division' in heading:
if 'open' in data.lower():
teams[current_team]['division'] = 'open'
if 'intermediate' in data.lower():
teams[current_team]['division'] = 'intermediate'
if 'main' in data.lower():
teams[current_team]['division'] = 'main'
if 'prem' in data.lower():
teams[current_team]['division'] = 'premier'
elif 'Best Pocket Scout' in heading:
teams[current_team]['scoutpocket'] = data
elif 'Best Flank Scout' in heading:
teams[current_team]['scoutflank'] = data
elif 'Best Roaming Soldier' in heading:
teams[current_team]['roamer'] = data
elif 'Best Pocket Soldier' in heading:
teams[current_team]['pocket'] = data
elif 'Best Medic' in heading:
teams[current_team]['medic'] = data
elif 'Best Demoman' in heading:
teams[current_team]['demo'] = data
elif 'Best Utility' in heading:
teams[current_team]['utility'] = data
elif 'Most Improved' in heading:
teams[current_team]['most improved'] = data
return teams
def sort_teams(teams):
divisions = {}
for team_name, data in teams.items():
team_division = data['division']
if team_division not in divisions:
divisions[team_division] = {}
# del data['division']
divisions[team_division][team_name] = data
return divisions
def create_division_report(name, teams):
awards = {
'Best Pocket Scout': 'scoutpocket',
'Best Flank Scout': 'scoutflank',
'Best Utility': 'utility',
'Best Pocket': 'pocket',
'Best Roamer': 'roamer',
'Best Demoman': 'demo',
'Best Medic': 'medic',
'Most Improved Player': 'most improved',
'Most Improved Team': 'team award',
'Friendliest Team': 'team award'
}
mvp = []
for award, designator in awards.items():
if designator == 'team award':
canidate_list = list(teams.keys())
else:
canidate_list = get_award_list(teams, designator)
mvp += canidate_list
awards[award] = canidate_list
awards['Most Valuble Player'] = list(set(mvp))
print(name.capitalize(), 'voting')
print('=' * len(name + ' voting'))
for award, canidate_list in sorted(awards.items()):
print(award + ': ', end='')
print(*sorted(canidate_list), sep=', ', end='\n')
print()
def get_award_list(teams, designator):
class_list = [team[designator]
for team in teams.values() if designator in team]
if type(class_list[0]) is list:
class_list = [
scout for scout_list in class_list for scout in scout_list]
return sorted(class_list)
def prettyprint(obj):
print(json.dumps(obj, indent=4))
main()