切换为mysql数据库

This commit is contained in:
ZaneYork 2021-12-26 12:36:43 +08:00
parent e2879b44a8
commit c4c008d034
4 changed files with 17 additions and 16 deletions

View File

@ -64,19 +64,19 @@ def battle_logic(baseline : Baseline, battle : Battle):
challenger_baseline['farmer_adp'] = farmer_adp challenger_baseline['farmer_adp'] = farmer_adp
challenger_baseline['create_time'] = datetime.now() challenger_baseline['create_time'] = datetime.now()
Baseline.create(**challenger_baseline) 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_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.challenger_adp = landlord_adp if battle.challenger_position == 'landlord' else farmer_adp
battle.status = 1 if challenge_success else 2 battle.status = 1 if challenge_success else 2
battle.save() 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(): def tick():
try: 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: for battle in battles:
battle.status = -1 battle.status = -1
battle.save() battle.save()

View File

@ -1,11 +1,7 @@
# -*- coding:utf8 -*- # -*- coding:utf8 -*-
from peewee import * from peewee import *
db = SqliteDatabase('model.db', pragmas={
'journal_mode': 'wal', db = MySQLDatabase('dou_model', host='192.168.1.88', user='douzero', passwd='VwjT6e0qf2t9iOH0')
'cache_size': -1 * 64000, # 64MB
'foreign_keys': 1,
'ignore_check_constraints': 0,
'synchronous': 0})
class BaseModel(Model): class BaseModel(Model):
class Meta: class Meta:

View File

@ -49,18 +49,22 @@ def metrics():
metrics = {} metrics = {}
for i in range(len(baselines)): for i in range(len(baselines)):
baseline = baselines[i] baseline = baselines[i]
baseline_metric = {} baseline_metric = {
'landlord': {},
'landlord_up': {},
'landlord_front': {},
'landlord_down': {}
}
models = Model.select(Model.frame, Model.path).where( models = Model.select(Model.frame, Model.path).where(
Model.type == type, Model.type == type,
Model.create_time >= baseline.create_time, Model.create_time >= baseline.create_time,
Model.create_time >= end_time Model.create_time <= end_time
).order_by(Model.create_time.asc()) ).order_by(Model.create_time.asc())
end_time = baseline.create_time end_time = baseline.create_time
for model in models: for model in models:
battle = Battle.get_or_none(Battle.challenger_path == model.path, Battle.status > 0, Battle.status != 3) battle = Battle.get_or_none(Battle.challenger_path == model.path, Battle.status > 0, Battle.status != 3)
if battle is not None: if battle is not None:
baseline_metric[model.frame] = { baseline_metric[str(battle.challenger_position)][model.frame] = {
'position': battle.challenger_position,
'wp': '%.4f' % float(battle.challenger_wp), 'wp': '%.4f' % float(battle.challenger_wp),
'adp': '%.4f' % float(battle.challenger_adp) 'adp': '%.4f' % float(battle.challenger_adp)
} }

View File

@ -1,3 +1,4 @@
flask==1.1 flask==1.1
flask-cors flask-cors
peewee peewee
pymysql