From c4c008d03465495ff305f24af69952692922e8b8 Mon Sep 17 00:00:00 2001 From: ZaneYork Date: Sun, 26 Dec 2021 12:36:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=87=E6=8D=A2=E4=B8=BAmysql=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- douzero/server/battle.py | 12 ++++++------ douzero/server/orm.py | 8 ++------ evaluate_server.py | 12 ++++++++---- requirements-server.txt | 1 + 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/douzero/server/battle.py b/douzero/server/battle.py index 8826f19..a474a3d 100644 --- a/douzero/server/battle.py +++ b/douzero/server/battle.py @@ -64,19 +64,19 @@ def battle_logic(baseline : Baseline, battle : Battle): challenger_baseline['farmer_adp'] = farmer_adp challenger_baseline['create_time'] = datetime.now() Baseline.create(**challenger_baseline) - else: - onnx_path = str(battle.challenger_path) + '.onnx' - if os.path.exists(onnx_path): - os.remove(onnx_path) - os.remove(str(battle.challenger_path)) battle.challenger_wp = landlord_wp if battle.challenger_position == 'landlord' else farmer_wp battle.challenger_adp = landlord_adp if battle.challenger_position == 'landlord' else farmer_adp battle.status = 1 if challenge_success else 2 battle.save() + if not challenge_success: + onnx_path = str(battle.challenger_path) + '.onnx' + if os.path.exists(onnx_path): + os.remove(onnx_path) + os.remove(str(battle.challenger_path)) def tick(): try: - battles = Battle.select().where(Battle.status == 0).order_by(Battle.id.desc()).limit(2) + battles = Battle.select().where(Battle.status == 0).order_by(Battle.id.desc()).limit(10) for battle in battles: battle.status = -1 battle.save() diff --git a/douzero/server/orm.py b/douzero/server/orm.py index 29f8bde..14a411a 100644 --- a/douzero/server/orm.py +++ b/douzero/server/orm.py @@ -1,11 +1,7 @@ # -*- coding:utf8 -*- from peewee import * -db = SqliteDatabase('model.db', pragmas={ - 'journal_mode': 'wal', - 'cache_size': -1 * 64000, # 64MB - 'foreign_keys': 1, - 'ignore_check_constraints': 0, - 'synchronous': 0}) + +db = MySQLDatabase('dou_model', host='192.168.1.88', user='douzero', passwd='VwjT6e0qf2t9iOH0') class BaseModel(Model): class Meta: diff --git a/evaluate_server.py b/evaluate_server.py index c7da9b7..52ea422 100644 --- a/evaluate_server.py +++ b/evaluate_server.py @@ -49,18 +49,22 @@ def metrics(): metrics = {} for i in range(len(baselines)): baseline = baselines[i] - baseline_metric = {} + baseline_metric = { + 'landlord': {}, + 'landlord_up': {}, + 'landlord_front': {}, + 'landlord_down': {} + } models = Model.select(Model.frame, Model.path).where( Model.type == type, Model.create_time >= baseline.create_time, - Model.create_time >= end_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, + baseline_metric[str(battle.challenger_position)][model.frame] = { 'wp': '%.4f' % float(battle.challenger_wp), 'adp': '%.4f' % float(battle.challenger_adp) } diff --git a/requirements-server.txt b/requirements-server.txt index e16acbb..0648acd 100644 --- a/requirements-server.txt +++ b/requirements-server.txt @@ -1,3 +1,4 @@ flask==1.1 flask-cors peewee +pymysql