Add page splits
This commit is contained in:
parent
4d3e087c33
commit
87c5be2a26
|
@ -31,7 +31,7 @@ The definitions of the fields are as follows:
|
||||||
| type | Resource | Parameters | Description |
|
| type | Resource | Parameters | Description |
|
||||||
|------|---------------------------|------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------|
|
|------|---------------------------|------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------|
|
||||||
| GET | tournament/launch | `eval_num`, `name` | Launch tournment on the game. Each pair of models will play `eval_num` times. Results will be saved in database. |
|
| GET | tournament/launch | `eval_num`, `name` | Launch tournment on the game. Each pair of models will play `eval_num` times. Results will be saved in database. |
|
||||||
| GET | tournament/query\_game | `name`, `index`, `agent0`, `agent1`, `win`, `payoff` | Query the games with the given parameters |
|
| GET | tournament/query\_game | `name`, `index`, `agent0`, `agent1`, `win`, `payoff`, `elements_every_page`, `page_index` | Query the games with the given parameters |
|
||||||
| GET | tournament/query\_payoff | `name`, `agent0`, `agent1`, `payoff` | Query the payoffs with the given parameters |
|
| GET | tournament/query\_payoff | `name`, `agent0`, `agent1`, `payoff` | Query the payoffs with the given parameters |
|
||||||
| GET | tournament/replay | `name`, `agent0`, `agent1`, `index` | Return the replay data |
|
| GET | tournament/replay | `name`, `agent0`, `agent1`, `index` | Return the replay data |
|
||||||
| POST | tournament/upload\_agent | `model`(Python file), `name`, `game`, `entry` | Upload a model file. `name` is model ID, `entry` is the class name of the model |
|
| POST | tournament/upload\_agent | `model`(Python file), `name`, `game`, `entry` | Upload a model file. `name` is model ID, `entry` is the class name of the model |
|
||||||
|
@ -42,9 +42,9 @@ The definitions of the fields are as follows:
|
||||||
| API | Description |
|
| API | Description |
|
||||||
|-----------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------|
|
|-----------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------|
|
||||||
| http://127.0.0.1:8000/tournament/launch?eval_num=200&name=leduc-holdem | Evaluate on Leduc Holdem with 200 games for each pair of models |
|
| http://127.0.0.1:8000/tournament/launch?eval_num=200&name=leduc-holdem | Evaluate on Leduc Holdem with 200 games for each pair of models |
|
||||||
| http://127.0.0.1:8000/tournament/replay?name=leduc-holdem&agent0=leduc-holdem-rule-v1&agent1=leduc-holdem-cfr&index=3 | Obtain the replay data between rule model and CFR model. Obtain the data of the 3rd game |
|
| http://127.0.0.1:8000/tournament/replay?name=leduc-holdem&agent0=leduc-holdem-rule-v1&agent1=leduc-holdem-cfr &index=3 | Obtain the replay data between rule model and CFR model. Obtain the data of the 3rd game |
|
||||||
| http://127.0.0.1:8000/tournament/query_game | Get all the game data |
|
| http://127.0.0.1:8000/tournament/query_game&elements_every_page=10&page_index=0 | Get all the game data |
|
||||||
| http://127.0.0.1:8000/tournament/query_game?name=leduc-holdem | Get all the game data of Leduc Holdem |
|
| http://127.0.0.1:8000/tournament/query_game?name=leduc-holdem&elements_every_page=10&page_index=0 | Get all the game data of Leduc Holdem |
|
||||||
| http://127.0.0.1:8000/tournament/query_payoff | Get all the payoffs |
|
| http://127.0.0.1:8000/tournament/query_payoff | Get all the payoffs |
|
||||||
| http://127.0.0.1:8000/tournament/query_payoff?agent0=leduc-holdem-cfr&agent1=leduc-holdem-rule-v1 | Get all the payoffs between rule and CFR models |
|
| http://127.0.0.1:8000/tournament/query_payoff?agent0=leduc-holdem-cfr&agent1=leduc-holdem-rule-v1 | Get all the payoffs between rule and CFR models |
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import importlib.util
|
import importlib.util
|
||||||
|
import math
|
||||||
|
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
|
@ -41,6 +42,17 @@ def _reset_model_ids():
|
||||||
rlcard.models.registration.model_registry.model_specs[name] = ModelSpec()
|
rlcard.models.registration.model_registry.model_specs[name] = ModelSpec()
|
||||||
MODEL_IDS[game].append(name)
|
MODEL_IDS[game].append(name)
|
||||||
|
|
||||||
|
PAGE_FIELDS = ['elements_every_page', 'page_index']
|
||||||
|
|
||||||
|
def _get_page(result, elements_every_page, page_index):
|
||||||
|
elements_every_page = int(elements_every_page)
|
||||||
|
page_index = int(page_index)
|
||||||
|
total_page = math.ceil(len(result) / float(elements_every_page))
|
||||||
|
begin = page_index * elements_every_page
|
||||||
|
end = min((page_index+1) * elements_every_page, total_page)
|
||||||
|
result = result[begin:end]
|
||||||
|
return result, total_page
|
||||||
|
|
||||||
def replay(request):
|
def replay(request):
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
name = request.GET['name']
|
name = request.GET['name']
|
||||||
|
@ -53,10 +65,13 @@ def replay(request):
|
||||||
|
|
||||||
def query_game(request):
|
def query_game(request):
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
filter_dict = {key: request.GET.get(key) for key in dict(request.GET).keys()}
|
if not PAGE_FIELDS[0] in request.GET or not PAGE_FIELDS[1] in request.GET:
|
||||||
result = Game.objects.filter(**filter_dict)
|
return HttpResponse(json.dumps({'value': -1, 'info': 'elements_every_page and page index should be given'}))
|
||||||
|
filter_dict = {key: request.GET.get(key) for key in dict(request.GET).keys() if key not in PAGE_FIELDS}
|
||||||
|
result = Game.objects.filter(**filter_dict).order_by('index')
|
||||||
|
result, total_page = _get_page(result, request.GET['elements_every_page'], request.GET['page_index'])
|
||||||
result = serializers.serialize('json', result, fields=('name', 'index', 'agent0', 'agent1', 'win', 'payoff'))
|
result = serializers.serialize('json', result, fields=('name', 'index', 'agent0', 'agent1', 'win', 'payoff'))
|
||||||
return HttpResponse(result)
|
return HttpResponse(json.dumps({'value': 0, 'data': json.loads(result), 'total_page': total_page}))
|
||||||
|
|
||||||
def query_payoff(request):
|
def query_payoff(request):
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
|
|
Loading…
Reference in New Issue