🐛 Fix standard deviation is not showing correctly in dps line chart

* Fix standard deviation is not showing correctly in dps line chart

* remove console.log

* simpler math
This commit is contained in:
Lei Shi 2023-12-05 03:15:39 +01:00 committed by GitHub
parent 19fb808cf2
commit 043b413285
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 134 additions and 91 deletions

View File

@ -64,33 +64,12 @@ class GCSimResultRenderer:
]
result["extra"]["damage"] = {
"xAxis": [i * 0.5 for i in range(len(result["statistics"]["damage_buckets"]["buckets"]))],
"series": [
{
"data": [bucket["mean"] for bucket in result["statistics"]["damage_buckets"]["buckets"]],
"type": "line",
"stack": "x",
"areaStyle": {},
"name": "平均伤害",
},
{
"data": [bucket["min"] for bucket in result["statistics"]["damage_buckets"]["buckets"]],
"type": "line",
"stack": "x",
"name": "最小伤害",
},
{
"data": [bucket["max"] for bucket in result["statistics"]["damage_buckets"]["buckets"]],
"type": "line",
"stack": "x",
"name": "最大伤害",
},
{
"data": [bucket["sd"] for bucket in result["statistics"]["damage_buckets"]["buckets"]],
"type": "line",
"stack": "x",
"name": "标准差",
},
],
"data": {
"mean": [bucket["mean"] for bucket in result["statistics"]["damage_buckets"]["buckets"]],
"min": [bucket["min"] for bucket in result["statistics"]["damage_buckets"]["buckets"]],
"max": [bucket["max"] for bucket in result["statistics"]["damage_buckets"]["buckets"]],
"sd": [bucket["sd"] for bucket in result["statistics"]["damage_buckets"]["buckets"]],
},
}
return result

View File

@ -10,6 +10,7 @@ from typing import Optional, Dict, List, Union, TYPE_CHECKING, Tuple, Coroutine,
import gcsim_pypi
from pydantic import BaseModel
from gram_core.config import config
from metadata.shortname import idToName
from modules.apihelper.client.components.remote import Remote
from modules.gcsim.cache import GCSimCache
@ -171,8 +172,9 @@ class GCSimRunner:
merged_script = GCSimConverter.merge_character_infos(script, character_infos)
except ValueError:
return GCSimResult(error="无法合并角色信息", user_id=user_id, uid=uid, script_key=script_key)
if file_id := await self.cache.get_cache(uid, hash(str(merged_script))):
return GCSimResult(error=None, user_id=user_id, uid=uid, script_key=script_key, file_id=file_id)
if not config.debug:
if file_id := await self.cache.get_cache(uid, hash(str(merged_script))):
return GCSimResult(error=None, user_id=user_id, uid=uid, script_key=script_key, file_id=file_id)
await self.player_gcsim_scripts.write_script(uid, script_key, str(merged_script))
limit = _get_limit_command()
command = [

View File

@ -1,101 +1,163 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8"/>
<meta charset="utf-8" />
<title>Title</title>
<script src="../../js/tailwindcss-3.1.8.js"></script>
<script src="../../js/echarts.min.js"></script>
<link type="text/css" href="../../styles/public.css" rel="stylesheet"/>
<link type="text/css" href="../../styles/public.css" rel="stylesheet" />
</head>
<body>
<div class="mx-auto flex w-[48rem] flex-col space-y-2 bg-gray-400 px-2 py-2">
<!-- START TEAM/DPS summary row -->
<div class="flex h-auto flex-col items-start justify-center space-y-4 rounded-lg bg-slate-600 py-6">
<!-- START character row -->
{% include "genshin/gcsim/characters.jinja2" %}
<!-- END character row -->
<!-- START summary DPS row -->
{% include "genshin/gcsim/summary.jinja2" %}
<!-- END summary DPS row -->
</div>
<!-- END TEAM/DPS summary row -->
<!-- START DPS distribution row -->
<div class="flex flex-row items-start justify-center space-x-2 rounded-lg">
<div class="flex h-56 w-1/2 items-center justify-center rounded-xl bg-slate-600" id="dps_by_character">
<div class="mx-auto flex w-[48rem] flex-col space-y-2 bg-gray-400 px-2 py-2">
<!-- START TEAM/DPS summary row -->
<div class="flex h-auto flex-col items-start justify-center space-y-4 rounded-lg bg-slate-600 py-6">
<!-- START character row -->
{% include "genshin/gcsim/characters.jinja2" %}
<!-- END character row -->
<!-- START summary DPS row -->
{% include "genshin/gcsim/summary.jinja2" %}
<!-- END summary DPS row -->
</div>
<div class="flex h-56 w-1/2 items-center justify-center rounded-xl bg-slate-600" id="dps_by_element">
<!-- END TEAM/DPS summary row -->
<!-- START DPS distribution row -->
<div class="flex flex-row items-start justify-center space-x-2 rounded-lg">
<div class="flex h-56 w-1/2 items-center justify-center rounded-xl bg-slate-600" id="dps_by_character">
</div>
<div class="flex h-56 w-1/2 items-center justify-center rounded-xl bg-slate-600" id="dps_by_element">
</div>
</div>
<script type="text/javascript">
var data = JSON.parse('{{ extra | tojson }}')
// Initialize the echarts instance based on the prepared dom
var dpsByCharacter = echarts.init(document.getElementById('dps_by_character'));
var dpsByElement = echarts.init(document.getElementById('dps_by_element'));
dpsByCharacter.setOption({
series: [
{
type: 'pie',
data: data["character_dps"],
label: {
color: 'white'
}
}
],
animation: false
});
dpsByElement.setOption({
series: [
{
type: 'pie',
data: data["element_dps"],
label: {
color: 'white'
}
}
],
animation: false
});
</script>
</div>
<!-- END DPS distribution row -->
<!-- START Energy/Heal/Shield row -->
<div class="flex flex-row items-start justify-center space-x-2 rounded-lg">
{% include "genshin/gcsim/other_summary.jinja2" %}
</div>
<!-- END Energy/Heal/Shield row -->
<!-- START DPS line chart row -->
<div class="flex h-80 w-full flex-row items-start justify-center rounded-lg bg-slate-600" id="damage_overtime">
<!-- END DPS distribution row -->
<!-- START Energy/Heal/Shield row -->
<div class="flex flex-row items-start justify-center space-x-2 rounded-lg">
{% include "genshin/gcsim/other_summary.jinja2" %}
</div>
<!-- END Energy/Heal/Shield row -->
<!-- START DPS line chart row -->
<div class="flex h-80 w-full flex-row items-start justify-center rounded-lg bg-slate-600" id="damage_overtime">
</div>
<!-- END DPS line chart row -->
</div>
<script type="text/javascript">
var data = JSON.parse('{{ extra | tojson }}')
// Initialize the echarts instance based on the prepared dom
var dpsByCharacter = echarts.init(document.getElementById('dps_by_character'));
dpsByCharacter.setOption({
series: [
{
type: 'pie',
data: data["character_dps"],
label: {
color: 'white'
}
}
],
animation: false
});
var dpsByElement = echarts.init(document.getElementById('dps_by_element'));
dpsByElement.setOption({
series: [
{
type: 'pie',
data: data["element_dps"],
label: {
color: 'white'
}
}
],
animation: false
});
var damageOvertime = echarts.init(document.getElementById('damage_overtime'));
damageOvertime.setOption({
xAxis: {
data: data["damage"]["xAxis"],
axisLabel: {
color: 'white',
interval: 19
},
axisTick: {
interval: 19
}
},
yAxis: {
axisLabel: {
color: 'white'
color: 'white',
formatter: function (value, index) {
return value / 10000 + "万";
}
}
},
grid: {
left: '3%',
right: '3%',
bottom: '3%',
containLabel: true
},
legend: {
textStyle: {
color: 'white'
}
},
},
series: data["damage"]["series"],
series: [
{
data: data["damage"]["data"]["mean"],
type: "line",
lineStyle: {
},
showSymbol: false,
name: "平均伤害",
},
{
data: data["damage"]["data"]["min"],
type: "line",
lineStyle: {
opacity: 0.5,
},
showSymbol: false,
name: "最小伤害",
},
{
data: data["damage"]["data"]["max"],
type: "line",
lineStyle: {
opacity: 0.5,
},
showSymbol: false,
name: "最大伤害",
},
{
type: "line",
data: data["damage"]["data"]["mean"].map((mean, idx) => mean - data["damage"]["data"]["sd"][idx] < 0 ? mean + data["damage"]["data"]["sd"][idx] : 2 * data["damage"]["data"]["sd"][idx]),
stack: 'confidence-band',
stackStrategy: 'positive',
lineStyle: {
opacity: 0
},
symbol: 'none',
},
{
type: "line",
data: data["damage"]["data"]["mean"].map((mean, idx) => mean - data["damage"]["data"]["sd"][idx] < 0 ? 0 : mean - data["damage"]["data"]["sd"][idx]),
stack: 'confidence-band',
stackStrategy: 'positive',
lineStyle: {
opacity: 0
},
areaStyle: {
opacity: 0.18,
color: '#4c9bd4'
},
symbol: 'none',
},
],
animation: false
});
</script>
<!-- END DPS line chart row -->
</div>
</body>
</html>