Skip to content

Instantly share code, notes, and snippets.

@timxyz
Last active February 23, 2021 11:32
Show Gist options
  • Save timxyz/68b4ab6713df56a6cf25637d2a0d9543 to your computer and use it in GitHub Desktop.
Save timxyz/68b4ab6713df56a6cf25637d2a0d9543 to your computer and use it in GitHub Desktop.
AI Abacus simulator request
import json
import pandas as pd
import requests
AI_ABACUS_SIMULATOR_URL = ''
AI_ABACUS_API_KEY = ''
def make_simulator_request(ply_ids, tme_id, style_id):
"""
Sychronously queries the AI Abacus Simulator API for the specified players and team
Parameters
----------
ply_ids : array of str
Array of Wyscout IDs for players to query
tme_id : str
Wyscout team ID to simulate a transfer to
style_id : str
Wyscout team ID to use for the stylistic comparison used to compute Suitability
Returns
-------
DataFrame
DataFrame with WyScout player ID as index and "Chemistry" and "Suitability" as columns
"""
request_body = {
'explain': 'none',
'simulate': ['chemistry', 'suitability'],
'transfers': [{ 'playerId': str(ply_id), 'teamId': str(tme_id), 'styleId': str(style_id) } for ply_id in ply_ids]
}
request_body_str = json.dumps(request_body)
response = requests.post(
AI_ABACUS_SIMULATOR_URL,
headers={
'x-api-key': AI_ABACUS_API_KEY,
'Content-Type': 'application/json'
},
data=request_body_str
)
response_body = response.json()
ply_ids_out = []
chemistry = []
suitability = []
if 'transfers' in response_body:
ply_ids_out = [item['playerId'] for item in response_body['transfers']]
chemistry = [item['chemistry']['value'] for item in response_body['transfers']]
suitability = [item['suitability']['value'] for item in response_body['transfers']]
return pd.DataFrame({
'PLY ID': ply_ids_out,
'Chemistry': chemistry,
'Suitability': suitability
}).set_index('PLY ID')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment