修复BUG,添加metrics接口
This commit is contained in:
parent
f7b0f2d7f4
commit
e2879b44a8
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
import traceback
|
||||||
|
|
||||||
from .orm import Baseline, Battle, Model
|
from .orm import Baseline, Battle, Model
|
||||||
from evaluate import evaluate
|
from evaluate import evaluate
|
||||||
|
@ -17,6 +18,7 @@ def battle_logic(baseline : Baseline, battle : Battle):
|
||||||
}
|
}
|
||||||
challenger_baseline[battle.challenger_position + "_path"] = str(battle.challenger_path)
|
challenger_baseline[battle.challenger_position + "_path"] = str(battle.challenger_path)
|
||||||
|
|
||||||
|
print(str(battle.challenger_path))
|
||||||
landlord_wp, farmer_wp, landlord_adp, farmer_adp = \
|
landlord_wp, farmer_wp, landlord_adp, farmer_adp = \
|
||||||
evaluate(challenger_baseline['landlord_path'],
|
evaluate(challenger_baseline['landlord_path'],
|
||||||
challenger_baseline['landlord_up_path'],
|
challenger_baseline['landlord_up_path'],
|
||||||
|
@ -43,16 +45,16 @@ def battle_logic(baseline : Baseline, battle : Battle):
|
||||||
|
|
||||||
challenge_success = False
|
challenge_success = False
|
||||||
if battle.challenger_position == 'landlord':
|
if battle.challenger_position == 'landlord':
|
||||||
if landlord_wp / baseline.landlord_wp > 1.2:
|
if baseline.landlord_wp == 0 or landlord_wp / float(baseline.landlord_wp) > 1.2:
|
||||||
landlord_wp, farmer_wp, landlord_adp, farmer_adp = \
|
landlord_wp, farmer_wp, landlord_adp, farmer_adp = \
|
||||||
_second_eval(landlord_wp, farmer_wp, landlord_adp, farmer_adp)
|
_second_eval(landlord_wp, farmer_wp, landlord_adp, farmer_adp)
|
||||||
if landlord_wp / baseline.landlord_wp > 1.2:
|
if baseline.landlord_wp == 0 or landlord_wp / float(baseline.landlord_wp) > 1.2:
|
||||||
challenge_success = True
|
challenge_success = True
|
||||||
else:
|
else:
|
||||||
if farmer_wp / baseline.farmer_wp > 1.2:
|
if baseline.farmer_wp == 0 or farmer_wp / float(baseline.farmer_wp) > 1.2:
|
||||||
landlord_wp, farmer_wp, landlord_adp, farmer_adp = \
|
landlord_wp, farmer_wp, landlord_adp, farmer_adp = \
|
||||||
_second_eval(landlord_wp, farmer_wp, landlord_adp, farmer_adp)
|
_second_eval(landlord_wp, farmer_wp, landlord_adp, farmer_adp)
|
||||||
if farmer_wp / baseline.farmer_wp > 1.2:
|
if baseline.farmer_wp == 0 or farmer_wp / float(baseline.farmer_wp) > 1.2:
|
||||||
challenge_success = True
|
challenge_success = True
|
||||||
if challenge_success:
|
if challenge_success:
|
||||||
challenger_baseline['rank'] = baseline.rank + 1
|
challenger_baseline['rank'] = baseline.rank + 1
|
||||||
|
@ -73,8 +75,11 @@ def battle_logic(baseline : Baseline, battle : Battle):
|
||||||
battle.save()
|
battle.save()
|
||||||
|
|
||||||
def tick():
|
def tick():
|
||||||
battles = Battle.select().where(Battle.status == 0).order_by(Battle.id.desc())
|
try:
|
||||||
|
battles = Battle.select().where(Battle.status == 0).order_by(Battle.id.desc()).limit(2)
|
||||||
for battle in battles:
|
for battle in battles:
|
||||||
|
battle.status = -1
|
||||||
|
battle.save()
|
||||||
baselines = Baseline.select().order_by(Baseline.rank.desc()).limit(1)
|
baselines = Baseline.select().order_by(Baseline.rank.desc()).limit(1)
|
||||||
if len(baselines) == 0:
|
if len(baselines) == 0:
|
||||||
baseline = {}
|
baseline = {}
|
||||||
|
@ -97,3 +102,5 @@ def tick():
|
||||||
battle.save()
|
battle.save()
|
||||||
else:
|
else:
|
||||||
battle_logic(baselines[0], battle)
|
battle_logic(baselines[0], battle)
|
||||||
|
except:
|
||||||
|
traceback.print_exc()
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
# -*- coding:utf8 -*-
|
# -*- coding:utf8 -*-
|
||||||
from peewee import *
|
from peewee import *
|
||||||
db = SqliteDatabase('model.db')
|
db = SqliteDatabase('model.db', pragmas={
|
||||||
|
'journal_mode': 'wal',
|
||||||
|
'cache_size': -1 * 64000, # 64MB
|
||||||
|
'foreign_keys': 1,
|
||||||
|
'ignore_check_constraints': 0,
|
||||||
|
'synchronous': 0})
|
||||||
|
|
||||||
class BaseModel(Model):
|
class BaseModel(Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
from douzero.evaluation.simulation import evaluate
|
|
||||||
|
|
||||||
from douzero.server.orm import Model, Battle, Baseline
|
from douzero.server.orm import Model, Battle, Baseline
|
||||||
from douzero.server.battle import tick
|
from douzero.server.battle import tick
|
||||||
from flask import Flask, jsonify, request
|
from flask import Flask, jsonify, request
|
||||||
|
@ -38,6 +36,37 @@ def upload():
|
||||||
threadpool.submit(tick)
|
threadpool.submit(tick)
|
||||||
return jsonify({'status': 0, 'message': 'success', 'result': ''})
|
return jsonify({'status': 0, 'message': 'success', 'result': ''})
|
||||||
|
|
||||||
|
@app.route('/battle_tick', methods=['POST'])
|
||||||
|
def battle_tick():
|
||||||
|
tick()
|
||||||
|
return jsonify({'status': 0, 'message': 'success', 'result': ''})
|
||||||
|
|
||||||
|
@app.route('/metrics', methods=['GET'])
|
||||||
|
def metrics():
|
||||||
|
type = request.args.get('type')
|
||||||
|
baselines = Baseline.select().order_by(Baseline.rank.desc()).limit(3)
|
||||||
|
end_time = datetime.now()
|
||||||
|
metrics = {}
|
||||||
|
for i in range(len(baselines)):
|
||||||
|
baseline = baselines[i]
|
||||||
|
baseline_metric = {}
|
||||||
|
models = Model.select(Model.frame, Model.path).where(
|
||||||
|
Model.type == type,
|
||||||
|
Model.create_time >= baseline.create_time,
|
||||||
|
Model.create_time >= end_time
|
||||||
|
).order_by(Model.create_time.asc())
|
||||||
|
end_time = baseline.create_time
|
||||||
|
for model in models:
|
||||||
|
battle = Battle.get_or_none(Battle.challenger_path == model.path, Battle.status > 0, Battle.status != 3)
|
||||||
|
if battle is not None:
|
||||||
|
baseline_metric[model.frame] = {
|
||||||
|
'position': battle.challenger_position,
|
||||||
|
'wp': '%.4f' % float(battle.challenger_wp),
|
||||||
|
'adp': '%.4f' % float(battle.challenger_adp)
|
||||||
|
}
|
||||||
|
metrics[baseline.rank] = baseline_metric
|
||||||
|
return jsonify({'status': 0, 'message': 'success', 'result': metrics})
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import argparse
|
import argparse
|
||||||
parser = argparse.ArgumentParser(description='DouZero evaluation backend')
|
parser = argparse.ArgumentParser(description='DouZero evaluation backend')
|
||||||
|
|
Loading…
Reference in New Issue