Spaces:
Sleeping
Sleeping
ping98k
commited on
Commit
·
f69a8f9
1
Parent(s):
a01815f
Fix pairwise progress to track overall rounds
Browse files
main.py
CHANGED
|
@@ -189,25 +189,25 @@ def run_tournament(
|
|
| 189 |
winner_label = _clean_json(text).get("winner", "A")
|
| 190 |
return a if winner_label == "A" else b
|
| 191 |
|
| 192 |
-
def tournament_round(pairs, executor):
|
| 193 |
futures = {executor.submit(play, a, b): (a, b) for a, b in pairs}
|
| 194 |
results = []
|
| 195 |
-
prog = SimpleProgress(len(futures), "Pairwise round")
|
| 196 |
for fut in as_completed(futures):
|
| 197 |
a, b = futures[fut]
|
| 198 |
winner = fut.result()
|
| 199 |
loser = b if winner == a else a
|
| 200 |
results.append((winner, loser))
|
| 201 |
-
yield from log(
|
| 202 |
return results
|
| 203 |
|
| 204 |
def tournament(players, executor):
|
| 205 |
lost_to = {}
|
| 206 |
current = players[:]
|
|
|
|
| 207 |
while len(current) > 1:
|
| 208 |
leftover = current[-1] if len(current) % 2 == 1 else None
|
| 209 |
pairs = [(current[i], current[i + 1]) for i in range(0, len(current) - 1, 2)]
|
| 210 |
-
round_results = yield from tournament_round(pairs, executor)
|
| 211 |
for w, l in round_results:
|
| 212 |
lost_to[l] = w
|
| 213 |
current = [w for w, _ in round_results]
|
|
|
|
| 189 |
winner_label = _clean_json(text).get("winner", "A")
|
| 190 |
return a if winner_label == "A" else b
|
| 191 |
|
| 192 |
+
def tournament_round(pairs, executor, progress):
|
| 193 |
futures = {executor.submit(play, a, b): (a, b) for a, b in pairs}
|
| 194 |
results = []
|
|
|
|
| 195 |
for fut in as_completed(futures):
|
| 196 |
a, b = futures[fut]
|
| 197 |
winner = fut.result()
|
| 198 |
loser = b if winner == a else a
|
| 199 |
results.append((winner, loser))
|
| 200 |
+
yield from log(progress.step())
|
| 201 |
return results
|
| 202 |
|
| 203 |
def tournament(players, executor):
|
| 204 |
lost_to = {}
|
| 205 |
current = players[:]
|
| 206 |
+
progress = SimpleProgress(len(players) - 1, "Pairwise round")
|
| 207 |
while len(current) > 1:
|
| 208 |
leftover = current[-1] if len(current) % 2 == 1 else None
|
| 209 |
pairs = [(current[i], current[i + 1]) for i in range(0, len(current) - 1, 2)]
|
| 210 |
+
round_results = yield from tournament_round(pairs, executor, progress)
|
| 211 |
for w, l in round_results:
|
| 212 |
lost_to[l] = w
|
| 213 |
current = [w for w, _ in round_results]
|