-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBracketLable.command
executable file
·187 lines (152 loc) · 5.55 KB
/
BracketLable.command
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/env python
import gdata.spreadsheet.service
import time
import sys
import psycopg2
import _pages
import _gdrive
EShiftDown = 1265854068
ECommandDown = 1264807268
EOptionDown = 1265594484
EControlDown = 1264809068
kVK_LeftArrow = 0x7B
kVK_RightArrow = 0x7C
kVK_DownArrow = 0x7D
kVK_UpArrow = 0x7E
home = '/Users/isaac/Documents/'
conn = psycopg2.connect( database ='djangostack',
host='dev.dartoo.com',
port='5432',
user='postgres',
password='tnvkfdl2')
#@unused
class Team():
def __init__(__, id, team_name ):
__.id = id
__.team_name = team_name
__.players = []
def append(__, player_name, ranking ):
__.players.append( Player( player_name ) )
class Match():
def __init__(__, id, round, ranking, winners_go, losers_go ):
__.id = id
__.round = round
__.ranking = ranking
__.winner = None
__.loser = None
__.winners_go = winners_go
__.losers_go = losers_go
__.teams = []
__.status = ''
def assign(__, id ):
__.teams.append( id )
class Division():
def __init__(__, name, format, teams, pages ):
__.format = format
__.name = name
__.teams = teams
__.pages = pages
__.match = [None] * 129
__.seed = [None] * 65
__.team_numbers = len( teams )
__.byes = 64 - __.team_numbers
__.bye = __.team_numbers + 1
__.label = _gdrive.Sheet('22K', 'Label')
if __.byes:
__.teams[ str(__.team_numbers + 1) ] = 'bye'
sheet = _gdrive.Sheet( '22K', 'Bracket' )
rows = sheet.listfeed.entry
for row in rows:
id = int( row.custom['id'].text )
__.match[id] = Match( id=id,
round= int( row.custom['round'].text ),
ranking= row.custom['ranking'].text,
winners_go= int( row.custom['winners-go'].text or 0 ),
losers_go= int( row.custom['losers-go'].text or 0 ) )
seed1 = int( row.custom['seed1'].text or 0 )
if seed1: __.seed[ seed1 ] = id
seed2 = int( row.custom['seed2'].text or 0 )
if seed2: __.seed[ seed2 ] = id
print __.seed
__.seeding( teams )
__.put_byes()
def seeding(__, teams):
for position in teams:
team_name = teams[ position ]
position = int( position )
if position <= 32:
id = __.seed[ position ]
__.match[ id ].assign( position )
elif team_name != 'bye':
id = __.seed[ position + __.byes ]
__.match[ id ].assign( position )
def put_byes(__):
for row in range(1,33):
if len( __.match[ row ].teams ) < 2:
__.match[ row ].teams.append( __.bye )
def round(__):
for row in __.match:
if ( row and row.winners_go and row.status != 'completed' and len( row.teams ) == 2 ):
# who is winner
__.match[ row.id ].teams.sort()
winner_id = __.match[ row.id ].teams[0]
__.report_match( row.id, winner_id )
def report_match(__, match_id, winner_id ):
__.match[ match_id ].status = 'completed'
teams = __.match[ match_id ].teams[:]
teams.remove( winner_id )
loser_id = teams.pop()
print match_id, ':', winner_id, loser_id
winners_go = __.match[ match_id ].winners_go
__.match[ winners_go ].assign( winner_id )
losers_go = __.match[ match_id ].losers_go
if losers_go:
__.match[ losers_go ].assign( loser_id )
#release console
def write_single(__):
for row in __.match:
if row and row.teams:
print row.id, ':', row.round, row.teams, row.ranking
__.label.delete_all()
__.pages.key_code( kVK_UpArrow, ECommandDown )
for i in range(1, 33):
for j in range(0, 2):
position = __.match[i].teams[j]
number = '%03d%02d%03d' % ( i, 1, position )
__.pages.type_out( number )
__.pages.key_code( kVK_DownArrow )
team = __.teams[ str(position) ]
__.pages.type_out( team )
__.pages.key_code( kVK_DownArrow )
__.label.insert({ 'number': number, 'team': team })
def write_double(__):
key_code( kVK_UpArrow, ECommandDown )
for i in range(1, 33):
for j in range(0, 2):
position = __.match[i].teams[j]
__.pages.type_out( '%03d%02d%03d' % ( i, 1, position ) )
__.pages.key_code( kVK_DownArrow )
__.pages.type_out( __.teams[ str(position) ] )
__.pages.key_code( kVK_DownArrow )
#class Event():
# def __init__(__, players ):
# int(row.teams[1]) - int(row.teams[0])
def main():
sheet = _gdrive.Sheet('22K', 'Gold')
rows = sheet.listfeed.entry
teams = {}
for row in rows:
teams[ row.custom['id'].text ] = row.custom['team'].text
sheet = _gdrive.Sheet('22K', 'Home')
rows = sheet.listfeed.entry
lines = 1
for row in rows:
if row.custom['key'].text == 'lines':
lines = int( row.custom['value'].text )
elif row.custom['key'].text == 'url':
url = row.custom['value'].text
pages = _pages.Label( url, lines )
division = Division( 'Gold', 'Singles', teams, pages )
division.write_single()
division.round()
main()