-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #427 from battlecode/tour-runner
Add single elimination tournament runner in beta
- Loading branch information
Showing
13 changed files
with
553 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...d/siarnaq/api/compete/migrations/0004_match_challonge_id_matchparticipant_challonge_id.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Generated by Django 4.1.2 on 2023-01-17 06:57 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("compete", "0003_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="match", | ||
name="challonge_id", | ||
field=models.IntegerField(blank=True, null=True, unique=True), | ||
), | ||
migrations.AddField( | ||
model_name="matchparticipant", | ||
name="challonge_id", | ||
field=models.CharField(blank=True, max_length=64, null=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# An API-esque module for our usage. | ||
# Commands here are not very generic (like a good API), | ||
# and are instead tailored to Battlecode's specific usage, | ||
# to improve dev efficiency | ||
|
||
import requests | ||
from django.conf import settings | ||
|
||
_headers = { | ||
"Accept": "application/json", | ||
"Authorization-Type": "v1", | ||
"Authorization": settings.CHALLONGE_API_KEY, | ||
"Content-Type": "application/vnd.api+json", | ||
# requests' default user agent causes Challonge's API to crash. | ||
"User-Agent": "", | ||
} | ||
|
||
AUTH_TYPE = "v1" | ||
URL_BASE = "https://api.challonge.com/v2/" | ||
|
||
|
||
def set_api_key(api_key): | ||
"""Set the challonge.com api credentials to use.""" | ||
_headers["Authorization"] = api_key | ||
|
||
|
||
def create_tournament( | ||
tournament_url, tournament_name, is_private=True, is_single_elim=True | ||
): | ||
tournament_type = "single elimination" if is_single_elim else "double elimination" | ||
|
||
url = f"{URL_BASE}tournaments.json" | ||
|
||
payload = { | ||
"data": { | ||
"type": "tournaments", | ||
"attributes": { | ||
"name": tournament_name, | ||
"tournament_type": tournament_type, | ||
"private": is_private, | ||
"url": tournament_url, | ||
}, | ||
} | ||
} | ||
|
||
r = requests.post(url, headers=_headers, json=payload) | ||
r.raise_for_status() | ||
|
||
|
||
def bulk_add_participants(tournament_url, participants): | ||
""" | ||
Adds participants in bulk. | ||
Expects `participants` to be formatted in the format Challonge expects. | ||
Note especially that seeds must be 1-indexed. | ||
""" | ||
url = f"{URL_BASE}tournaments/{tournament_url}/participants/bulk_add.json" | ||
|
||
payload = { | ||
"data": { | ||
"type": "Participant", | ||
"attributes": { | ||
"participants": participants, | ||
}, | ||
} | ||
} | ||
|
||
r = requests.post(url, headers=_headers, json=payload) | ||
r.raise_for_status() | ||
|
||
|
||
def start_tournament(tournament_url): | ||
url = f"{URL_BASE}tournaments/{tournament_url}/change_state.json" | ||
|
||
payload = {"data": {"type": "TournamentState", "attributes": {"state": "start"}}} | ||
|
||
r = requests.put(url, headers=_headers, json=payload) | ||
r.raise_for_status() | ||
|
||
|
||
def get_tournament(tournament_url): | ||
url = f"{URL_BASE}tournaments/{tournament_url}.json" | ||
|
||
r = requests.get(url, headers=_headers) | ||
r.raise_for_status() | ||
return r.json() | ||
|
||
|
||
def update_match(tournament_url, match_id, match): | ||
url = f"{URL_BASE}tournaments/{tournament_url}/matches/{match_id}.json" | ||
|
||
payload = { | ||
"data": { | ||
"type": "Match", | ||
"attributes": { | ||
"match": match, | ||
}, | ||
} | ||
} | ||
|
||
r = requests.put(url, headers=_headers, json=payload) | ||
r.raise_for_status() |
43 changes: 43 additions & 0 deletions
43
backend/siarnaq/api/episodes/migrations/0003_remove_tournament_challonge_private_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Generated by Django 4.1.2 on 2023-01-17 06:57 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
( | ||
"episodes", | ||
"0002_rename_release_version_episode_release_version_public_and_more", | ||
), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name="tournament", | ||
name="challonge_private", | ||
), | ||
migrations.RemoveField( | ||
model_name="tournament", | ||
name="challonge_public", | ||
), | ||
migrations.RemoveField( | ||
model_name="tournament", | ||
name="in_progress", | ||
), | ||
migrations.AddField( | ||
model_name="tournament", | ||
name="challonge_id_private", | ||
field=models.SlugField(blank=True, null=True), | ||
), | ||
migrations.AddField( | ||
model_name="tournament", | ||
name="challonge_id_public", | ||
field=models.SlugField(blank=True, null=True), | ||
), | ||
migrations.AddField( | ||
model_name="tournamentround", | ||
name="in_progress", | ||
field=models.BooleanField(default=False), | ||
), | ||
] |
Oops, something went wrong.