优化SQL及UI

This commit is contained in:
zhiyang7 2021-12-27 11:22:49 +08:00
parent 89daced3ad
commit e75f8fc4bb
3 changed files with 37 additions and 17 deletions

View File

@ -19,9 +19,9 @@ class Model(BaseModel):
class Battle(BaseModel):
id = PrimaryKeyField()
challenger_path = CharField(null = False)
challenger_path = CharField(null = False, index = True)
challenger_position = CharField(null = False)
status = IntegerField(null = False)
status = IntegerField(null = False, index = True)
challenger_wp = DecimalField(null=True)
challenger_adp = DecimalField(null=True)
class Meta:
@ -34,7 +34,7 @@ class Baseline(BaseModel):
landlord_up_path = ForeignKeyField(Model, to_field='path',related_name = "model")
landlord_front_path = ForeignKeyField(Model, to_field='path',related_name = "model")
landlord_down_path = ForeignKeyField(Model, to_field='path',related_name = "model")
rank = IntegerField(null = False)
rank = IntegerField(null = False, index = True)
landlord_wp = DecimalField(null=False)
farmer_wp = DecimalField(null=False)
landlord_adp = DecimalField(null=False)

View File

@ -1,4 +1,7 @@
import itertools
import os
from peewee import JOIN
from douzero.server.orm import Model, Battle, Baseline
from douzero.server.battle import tick
@ -83,6 +86,10 @@ def metrics():
baseline = baselines[i]
baseline_metric = {
'baseline': {
'landlord_path': os.path.basename(str(baseline.landlord_path)).split('.')[0],
'landlord_up_path': os.path.basename(str(baseline.landlord_up_path)).split('.')[0].replace('landlord_', ''),
'landlord_down_path': os.path.basename(str(baseline.landlord_down_path)).split('.')[0].replace('landlord_', ''),
'landlord_front_path': os.path.basename(str(baseline.landlord_front_path)).split('.')[0].replace('landlord_', ''),
'landlord_wp': '%.4f' % float(baseline.landlord_wp),
'landlord_adp': '%.4f' % float(baseline.landlord_adp),
'farmer_wp': '%.4f' % float(baseline.farmer_wp),
@ -94,19 +101,28 @@ def metrics():
'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
).order_by(Model.create_time.asc())
results = (
Model
.select(Model.frame, Model.path, Battle.challenger_position, Battle.challenger_wp, Battle.challenger_adp)
.where(
Model.type == type,
Model.create_time >= baseline.create_time,
Model.create_time <= end_time
)
.join(Battle, JOIN.INNER, on=(
(Battle.challenger_path == Model.path) &
(Battle.status > 0) &
(Battle.status != 3))
)
.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[str(battle.challenger_position)][model.frame] = {
'wp': '%.4f' % float(battle.challenger_wp),
'adp': '%.4f' % float(battle.challenger_adp)
}
for result in results:
battle = result.battle
baseline_metric[str(battle.challenger_position)][result.frame] = {
'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})

View File

@ -22,10 +22,14 @@
}
var json = {
title: {
text: rank
text: 'Baseline: ' + rank
},
subtitle: {
text: ''
text: 'WP: ' + result[rank]['baseline'].landlord_wp + '\t/\t' + result[rank]['baseline'].farmer_wp + '<br/>' +
result[rank]['baseline'].landlord_path + '\t/\t' +
result[rank]['baseline'].landlord_down_path + '\t/\t' +
result[rank]['baseline'].landlord_front_path + '\t/\t' +
result[rank]['baseline'].landlord_up_path
},
}
categories = new Set()