Skip to content

Commit

Permalink
script to submit tournament matches into elo submissions
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennanB committed Sep 12, 2024
1 parent dbf2c2a commit c35f285
Show file tree
Hide file tree
Showing 2 changed files with 229 additions and 29 deletions.
127 changes: 127 additions & 0 deletions matches.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
Player1,Player2,Player3,Player4,Player5,Player6,Score1,Score2
XanB,Migitino,SupergoobeJR,joelemonade,Charlemagne,p4l20,126,168
JOOT49,Takanori,piraba,axn7627,eeman7199,Adam,122,137
Evan8738,Darre2655,Liam,C4678,CGorms081,TayLew,145,174
tactualelf,gingerrrr,technoton1,cryoforce,Gabriel,stel,108,137
Charlemagne,JOOT49,eeman7199,Migitino,Takanori,joelemonade,145,131
Darre2655,XanB,C4678,TayLew,axn7627,Liam,108,112
tactualelf,p4l20,Adam,stel,technoton1,Evan8738,100,173
gingerrrr,piraba,Gabriel,CGorms081,SupergoobeJR,cryoforce,137,110
Liam,JOOT49,C4678,XanB,Charlemagne,Takanori,119,147
technoton1,TayLew,p4l20,eeman7199,tactualelf,Evan8738,127,123
SupergoobeJR,joelemonade,Gabriel,piraba,stel,Darre2655,126,153
axn7627,CGorms081,Migitino,Adam,gingerrrr,cryoforce,120,138
C4678,p4l20,eeman7199,JOOT49,tactualelf,XanB,165,84
Takanori,Liam,stel,SupergoobeJR,piraba,technoton1,151,136
Gabriel,Darre2655,axn7627,Migitino,Evan8738,gingerrrr,147,124
cryoforce,TayLew,Charlemagne,Adam,joelemonade,CGorms081,147,112
stel,SupergoobeJR,JOOT49,piraba,C4678,tactualelf,113,135
Evan8738,Gabriel,Takanori,p4l20,Liam,Migitino,122,139
technoton1,cryoforce,axn7627,Darre2655,Adam,Charlemagne,94,162
TayLew,XanB,joelemonade,gingerrrr,eeman7199,CGorms081,133,184
Takanori,C4678,SupergoobeJR,Gabriel,Migitino,tactualelf,151,115
Liam,Adam,piraba,p4l20,cryoforce,Darre2655,153,152
Charlemagne,axn7627,gingerrrr,eeman7199,stel,TayLew,126,183
CGorms081,Evan8738,XanB,joelemonade,technoton1,JOOT49,151,118
TayLew,Adam,technoton1,C4678,Gabriel,Migitino,146,149
Charlemagne,Darre2655,Takanori,piraba,Evan8738,SupergoobeJR,188,135
p4l20,CGorms081,XanB,Liam,cryoforce,joelemonade,152,137
piraba,Evan8738,SupergoobeJR,Liam,cryoforce,joelemonade,124,139
eeman7199,stel,gingerrrr,C4678,Gabriel,Migitino,174,175
Charlemagne,Darre2655,Takanori,p4l20,CGorms081,XanB,170,131
eeman7199,stel,gingerrrr,Liam,cryoforce,joelemonade,143,129
p4l20,CGorms081,XanB,TayLew,Adam,technoton1,138,161
C4678,Gabriel,Migitino,Charlemagne,Darre2655,Takanori,133,158
TayLew,Adam,technoton1,eeman7199,stel,gingerrrr,147,130
C4678,Gabriel,Migitino,TayLew,Adam,technoton1,131,133
Charlemagne,Darre2655,Takanori,TayLew,Adam,technoton1,149,125
Charlemagne,Darre2655,Takanori,TayLew,Adam,technoton1,144,119
Logan,Brennan,Charlemagne,Jimit,Liam,Darre,205,156
Tsd2,Eitan,Matthew,BingBong,Wrathofroma,Stel,111,138
Aris,Piraba,Tsd2,Takanori,Crayfish,Logan,116,153
Liam,Aris,BingBong,Charlemagne,Matthew,Piraba,133,166
Crayfish,Jimit,Takanori,Wrathofroma,Stel,Eitan*,153,163
Jimit,Brennan,Matthew,Tsd2,Darre,Takanori,202,148
Wrathofroma,Piraba,Stel,Charlemagne,Darre,Aris,145,155
Crayfish,Liam,Brennan,Eitan,Logan,BingBong,130,165
Eitan,Liam*,Darre,Aris,Tsd2,Jimit,162,95
Takanori,Charlemagne,Piraba,Matthew,BingBong,Brennan,137,164
Liam,Wrathofroma,Logan,Stel,Crayfish,Darre,132,147
Piraba,Logan,Wrathofroma,Tsd2,Charlemagne,Jimit,142,84
Takanori,Aris,Matthew,Crayfish,Eitan,Brennan,167,180
Stel,Tsd2,Crayfish,BingBong,Darre,Charlemagne,139,165
Logan,BingBong,Takanori,Aris,Matthew,Wrathofroma,142,169
Piraba,Eitan,Jimit,Brennan,Stel,Liam,145,170
BingBong,Takanori,Eitan,Darre,Logan,Piraba,173,153
Crayfish,Charlemagne,Wrathofroma,Liam,Matthew,Stel,163,178
Tsd2,Jimit,BingBong,Brennan,Aris,Crayfish,75,167
Matthew,Eitan,Darre,Piraba,Brennan,Tsd2,196,114
Charlemagne,Aris,Liam,Takanori,Wrathofroma,Jimit,154,112
Stel,Jimit,Charlemagne,Matthew,Logan,Eitan,134,182
Darre,Wrathofroma,Brennan,Piraba,Crayfish,BingBong,181,121
Logan,Stel,Aris,Liam,Takanori,Tsd2,238,71
Matthew,Stel,Crayfish,Jimit,Piraba,Liam,178,91
Darre,BingBong,Logan,Eitan,Charlemagne,Aris,140,184
Brennan,Takanori,Liam,Wrathofroma,Tsd2,Eitan,176,99
Brennan,Matthew,Piraba,Eitan,Crayfish,Aris,181,162
Stel,Charlemagne,Takanori,Darre,Logan,Wrathofroma,136,151
Eitan,Charlemagne,Takanori,Stel,Charlemagne,Takanori,148,131
Brennan,Matthew,Piraba,Darre,Logan,Wrathofroma,170,124
Darre,Logan,Wrathofroma,Eitan,Crayfish,Aris,138,131
Brennan,Matthew,Piraba,Darre,Logan,Wrathofroma,158,90
Brennan,Matthew,Piraba,Darre,Logan,Wrathofroma,150,134
Brennan4476,Tamy,Zac-10101,noahplwg,lekerbal,Liam,111,119
Matthew422,mariofan9,LittleCorgi,Eitan,Sbeahm21,minigameking,165,88
popedeclan,waxton,xanathar_the_great,maximumvoltage7784,Abyss1792,captaincolonelcorn,140,100
brendan7,Parin,itzcrayfish784,EvanBoi,CGorms081,tactualelf,141,103
harel4590,joaquinrog9280,stel,C4678,kaiju_jones,roma,110,149
Evan8738,Logan4476,Darre2655,Cosinus_Maximus,Trevor1102,ambrose8156,213,113
Jeff2718,Anthony3357,lekerbal,eback0-9005,Adam,Eitan,150,159
CGorms081,Matthew422,brendan7,Liam,captaincolonelcorn,waxton,176,98
itzcrayfish784,roma,EvanBoi,Abyss1792,kaiju_jones,popedeclan,136,101
Darre2655,xanathar_the_great,minigameking,Evan8738,noahplwg,C4678,148,180
Anthony3357,mariofan9,Parin,Tamy,harel4590,Logan4476,118,110
Adam,tactualelf,Cosinus_Maximus,ambrose8156,Brennan4476,eback0-9005,95,154
Sbeahm21,maximumvoltage7784,joaquinrog9280,Trevor1102,Jeff2718,stel,63,167
Zac-10101,EvanBoi,kaiju_jones,LittleCorgi,captaincolonelcorn,xanathar_the_great,147,98
waxton,Evan8738,Anthony3357,Parin,lekerbal,C4678,119,143
roma,Abyss1792,Liam,Adam,Darre2655,mariofan9,89,174
Trevor1102,harel4590,popedeclan,stel,Eitan,tactualelf,115,199
Logan4476,Brennan4476,Sbeahm21,brendan7,Zac-10101,eback0-9005,166,114
LittleCorgi,noahplwg,Cosinus_Maximus,itzcrayfish784,Matthew422,Jeff2718,114,172
Tamy,ambrose8156,joaquinrog9280,CGorms081,minigameking,maximumvoltage7784,191,121
Liam,tactualelf,Evan8738,Abyss1792,stel,Anthony3357,144,168
xanathar_the_great,eback0-9005,lekerbal,Parin,popedeclan,roma,100,162
Jeff2718,Zac-10101,Eitan,C4678,Darre2655,brendan7,101,167
captaincolonelcorn,Trevor1102,Brennan4476,minigameking,itzcrayfish784,Tamy,130,129
kaiju_jones,LittleCorgi,maximumvoltage7784,noahplwg,Adam,Logan4476,96,164
EvanBoi,joaquinrog9280,mariofan9,waxton,ambrose8156,Matthew422,131,177
harel4590,Liam,CGorms081,Sbeahm21,Cosinus_Maximus,Abyss1792,106,110
captaincolonelcorn,Evan8738,Zac-10101,tactualelf,Jeff2718,Parin,141,169
maximumvoltage7784,brendan7,Trevor1102,roma,Anthony3357,LittleCorgi,126,85
Eitan,Logan4476,ambrose8156,joaquinrog9280,xanathar_the_great,itzcrayfish784,192,124
stel,EvanBoi,noahplwg,mariofan9,eback0-9005,CGorms081,172,89
lekerbal,minigameking,waxton,kaiju_jones,Cosinus_Maximus,harel4590,162,119
popedeclan,C4678,Sbeahm21,Matthew422,Tamy,Adam,96,166
Darre2655,Parin,Abyss1792,joaquinrog9280,LittleCorgi,Brennan4476,181,141
ambrose8156,roma,captaincolonelcorn,Anthony3357,Eitan,noahplwg,120,169
eback0-9005,waxton,harel4590,Zac-10101,itzcrayfish784,Trevor1102,110,158
minigameking,C4678,Jeff2718,Logan4476,Liam,EvanBoi,117,141
tactualelf,Sbeahm21,Matthew422,lekerbal,maximumvoltage7784,Darre2655,146,106
Brennan4476,CGorms081,kaiju_jones,mariofan9,popedeclan,Evan8738,185,106
xanathar_the_great,stel,Adam,Cosinus_Maximus,brendan7,Tamy,128,97
Matthew422,Darre2655,C4678,ambrose8156,waxton,joaquinrog9280,120,98
stel,Liam,roma,noahplwg,CGorms081,Anthony3357,193,132
Parin,Logan4476,Jeff2718,brendan7,EvanBoi,Trevor1102,159,123
Adam,Eitan,itzcrayfish784,Brennan4476,Evan8738,kaiju_jones,146,143
ambrose8156,waxton,joaquinrog9280,noahplwg,CGorms081,Anthony3357,126,87
brendan7,EvanBoi,Trevor1102,Brennan4476,Evan8738,kaiju_jones,122,130
Matthew422,Darre2655,C4678,stel,Liam,roma,178,135
Parin,Logan4476,Jeff2718,Adam,Eitan,itzcrayfish784,130,149
stel,Liam,roma,Brennan4476,Evan8738,kaiju_jones,131,137
Parin,Logan4476,Jeff2718,ambrose8156,waxton,joaquinrog9280,172,125
Matthew422,Darre2655,C4678,Adam,Eitan,itzcrayfish784,193,178
Parin,Logan4476,Jeff2718,Brennan4476,Evan8738,kaiju_jones,112,136
Adam,Eitan,itzcrayfish784,Brennan4476,Evan8738,kaiju_jones,156,123
Matthew422,Darre2655,C4678,Adam,Eitan,itzcrayfish784,160,144
Matthew422,Darre2655,C4678,Adam,Eitan,itzcrayfish784,189,157
131 changes: 102 additions & 29 deletions submit_matches.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,136 @@
import requests
import os
from dotenv import load_dotenv
from fuzzywuzzy import fuzz
from prompt_toolkit import prompt
from prompt_toolkit.validation import Validator, ValidationError

# Load environment variables
load_dotenv()

API_KEY = os.getenv('SRC_API_TOKEN')
print(API_KEY)
API_BASE_URL = 'https://secondrobotics.org'

def submit_match(red_alliance, blue_alliance, red_score, blue_score):
url = f"{API_BASE_URL}/ranked/api/CR3v3/match"
headers = {
'Content-Type': 'application/json',
'X-API-KEY': API_KEY
}
payload = {
"red_alliance": red_alliance,
"blue_alliance": blue_alliance,
"red_score": red_score,
"blue_score": blue_score
}
def get_valid_players(game_mode_code):
url = f"{API_BASE_URL}/api/ranked/{game_mode_code}/players/"
headers = {'X-API-KEY': API_KEY}

response = requests.post(url, json=payload, headers=headers)
return response.json()
response = requests.get(url, headers=headers)
if response.status_code == 200:
return response.json()
else:
print(f"Failed to fetch valid players: {response.status_code}")
return None

def find_closest_match(name, valid_players):
best_match = None
best_ratio = 0
for player in valid_players:
ratio_display = fuzz.ratio(name.lower(), player['display_name'].lower())
ratio_username = fuzz.ratio(name.lower(), player['username'].lower())
max_ratio = max(ratio_display, ratio_username)
if max_ratio > best_ratio:
best_ratio = max_ratio
best_match = player
return best_match, best_ratio

def validate_player_id(text):
if text.isdigit() and len(text) == 18:
return True
return False

class PlayerIdValidator(Validator):
def validate(self, document):
text = document.text
if not validate_player_id(text):
raise ValidationError(message='Please enter a valid 18-digit Discord ID')

def process_csv(file_path, valid_players):
player_mappings = {}
matches = []

def process_csv(file_path):
with open(file_path, 'r') as csvfile:
reader = csv.reader(csvfile)
next(reader) # Skip header row if present

for row in reader:
red_alliance = [int(player.strip()) for player in row[:3]]
blue_alliance = [int(player.strip()) for player in row[3:6]]
red_score = int(row[6])
blue_score = int(row[7])
match = []
for player in row[:6]: # Process all 6 players
player = player.strip()
if player in player_mappings:
match.append(player_mappings[player])
elif validate_player_id(player):
match.append(int(player))
player_mappings[player] = int(player)
else:
closest_match, ratio = find_closest_match(player, valid_players)
if ratio == 100:
match.append(int(closest_match['id']))
player_mappings[player] = int(closest_match['id'])
else:
print(f"\nNo exact match found for '{player}'.")
print(f"Closest match: {closest_match['display_name']} (ID: {closest_match['id']})")
confirmation = prompt(f"Accept this match? (y/n): ").lower()
if confirmation == 'y':
match.append(int(closest_match['id']))
player_mappings[player] = int(closest_match['id'])
else:
manual_id = prompt("Enter the correct Discord ID: ", validator=PlayerIdValidator())
match.append(int(manual_id))
player_mappings[player] = int(manual_id)

result = submit_match(red_alliance, blue_alliance, red_score, blue_score)
print(f"Match submitted: {result}")
match.extend([int(row[6]), int(row[7])]) # Add scores
matches.append(match)

return matches

def get_valid_players(game_mode_code):
url = f"{API_BASE_URL}/ranked/api/{game_mode_code}/players/"
def submit_match(red_alliance, blue_alliance, red_score, blue_score, game_mode_code):
url = f"{API_BASE_URL}/api/ranked/{game_mode_code}/match/"
headers = {
'Content-Type': 'application/json',
'X-API-KEY': API_KEY
}
payload = {
"red_alliance": red_alliance,
"blue_alliance": blue_alliance,
"red_score": red_score,
"blue_score": blue_score
}

response = requests.get(url, headers=headers)
response = requests.post(url, json=payload, headers=headers)
if response.status_code == 200:
return response.json()
else:
print(f"Failed to fetch valid players: {response.status_code}")
print(f"Error submitting match: Status code {response.status_code}")
print(f"Response content: {response.text}")
return None

if __name__ == "__main__":
csv_file_path = "matches.csv" # Replace with your CSV file path
game_mode_code = "CR3v3" # Replace with the appropriate game mode code

valid_players = get_valid_players(game_mode_code)
if valid_players:
print(f"Fetched {len(valid_players)} valid players")
# You can use valid_players for validation or other purposes
if not valid_players:
print("Failed to fetch valid players. Exiting.")
exit(1)

process_csv(csv_file_path)
print(f"Fetched {len(valid_players)} valid players")

matches = process_csv(csv_file_path, valid_players)

print("\nAll players processed. Ready to submit matches.")
confirmation = prompt("Do you want to submit these matches? (y/n): ").lower()

if confirmation == 'y':
for match in matches:
red_alliance = match[:3]
blue_alliance = match[3:6]
red_score, blue_score = match[6:]
result = submit_match(red_alliance, blue_alliance, red_score, blue_score, game_mode_code)
if result:
print(f"Match submitted successfully: {result}")
else:
print("Failed to submit match. Please check the error message above.")
else:
print("Match submission cancelled.")

0 comments on commit c35f285

Please sign in to comment.