Damage Analysis

This commit is contained in:
omg-xtao 2024-03-15 20:46:16 +08:00 committed by GitHub
parent d3f64bfd74
commit aef9906f73
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 838 additions and 652 deletions

View File

@ -22,6 +22,21 @@ from plugins.tools.genshin import PlayerNotFoundError
from utils.log import logger
from utils.uid import mask_number
try:
from starrail_damage_cal.mihomo.models import Avatar as DamageAvatar
from starrail_damage_cal.to_data import get_data as get_damage_data
from starrail_damage_cal.cal_damage import cal_info as cal_damage_info
from msgspec import convert as msgspec_convert
STARRAIL_ARTIFACT_FUNCTION_AVAILABLE = True
except ImportError:
DamageAvatar = None
get_damage_data = None
cal_damage_info = None
msgspec_convert = None
STARRAIL_ARTIFACT_FUNCTION_AVAILABLE = False
if TYPE_CHECKING:
from telegram.ext import ContextTypes
from telegram import Update
@ -154,7 +169,9 @@ class PlayerCards(Plugin):
if idToRole(characters.avatarId) == ch_name:
break
else:
await message.reply_text(f"角色展柜中未找到 {ch_name} ,请检查角色是否存在于角色展柜中,或者等待角色数据更新后重试\n\n{DEP_MSG}")
await message.reply_text(
f"角色展柜中未找到 {ch_name} ,请检查角色是否存在于角色展柜中,或者等待角色数据更新后重试\n\n{DEP_MSG}"
)
return
await message.reply_chat_action(ChatAction.UPLOAD_PHOTO)
render_result = await RenderTemplate(
@ -203,7 +220,10 @@ class PlayerCards(Plugin):
return
if data.avatarList is None:
await message.delete()
await callback_query.answer("请先将角色加入到角色展柜并允许查看角色详情后再使用此功能,如果已经添加了角色,请等待角色数据更新后重试", show_alert=True)
await callback_query.answer(
"请先将角色加入到角色展柜并允许查看角色详情后再使用此功能,如果已经添加了角色,请等待角色数据更新后重试",
show_alert=True,
)
return
buttons = self.gen_button(data, user.id, uid, update_button=False)
render_data = await self.parse_holder_data(data)
@ -268,7 +288,10 @@ class PlayerCards(Plugin):
return
if data.avatarList is None:
await message.delete()
await callback_query.answer("请先将角色加入到角色展柜并允许查看角色详情后再使用此功能,如果已经添加了角色,请等待角色数据更新后重试", show_alert=True)
await callback_query.answer(
"请先将角色加入到角色展柜并允许查看角色详情后再使用此功能,如果已经添加了角色,请等待角色数据更新后重试",
show_alert=True,
)
return
if page:
buttons = self.gen_button(data, user.id, uid, page, await self.cache.ttl(uid) <= 0)
@ -280,7 +303,10 @@ class PlayerCards(Plugin):
break
else:
await message.delete()
await callback_query.answer(f"角色展柜中未找到 {result} ,请检查角色是否存在于角色展柜中,或者等待角色数据更新后重试", show_alert=True)
await callback_query.answer(
f"角色展柜中未找到 {result} ,请检查角色是否存在于角色展柜中,或者等待角色数据更新后重试",
show_alert=True,
)
return
await callback_query.answer(text="正在渲染图片中 请稍等 请不要重复点击按钮", show_alert=False)
await message.reply_chat_action(ChatAction.UPLOAD_PHOTO)
@ -493,6 +519,7 @@ class RenderTemplate:
"artifacts": artifacts,
"skills": skills,
"images": images,
**(await self.cal_avatar_damage()),
}
return await self.template_service.render(
@ -553,3 +580,25 @@ class RenderTemplate:
for e in relic_list
if self.client.get_affix_by_id(e.tid) is not None
]
async def cal_avatar_damage(self) -> Dict:
if not STARRAIL_ARTIFACT_FUNCTION_AVAILABLE:
return {
"damage_function_available": False,
}
try:
data = self.character.dict()
if "property" in data:
del data["property"]
avatar = msgspec_convert(data, type=DamageAvatar)
damage_data = await get_damage_data(avatar, "", str(self.uid))
damage_info = await cal_damage_info(damage_data[0])
return {
"damage_function_available": True,
"damage_info": damage_info,
}
except Exception:
logger.warning("计算角色伤害时出现错误 uid[%s] avatar[%s]", self.uid, self.character.avatarId)
return {
"damage_function_available": False,
}

1282
poetry.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -12,7 +12,7 @@ httpx = "^0.25.0"
ujson = "^5.9.0"
Jinja2 = "^3.1.2"
python-telegram-bot = { version = "^20.7", extras = ["ext", "rate-limiter"] }
sqlmodel = "^0.0.14"
sqlmodel = "^0.0.16"
colorlog = "^6.8.0"
fakeredis = "^2.19.0"
redis = "^5.0.1"
@ -21,28 +21,29 @@ asyncmy = "^0.2.9"
aiofiles = "^23.2.1"
python-dotenv = "^1.0.0"
alembic = "^1.13.0"
black = "^23.9.1"
black = "^24.1.1"
rich = "^13.6.0"
TgCrypto = { version = "^1.2.5", optional = true }
Pyrogram = { version = "^2.0.102", optional = true }
pytest = { version = "^7.3.0", optional = true }
pytest-asyncio = { version = "^0.23.2", optional = true }
flaky = { version = "^3.7.0", optional = true }
lxml = "^4.9.2"
lxml = "^5.0.0"
arko-wrapper = "^0.2.8"
fastapi = "<0.106.0"
uvicorn = { extras = ["standard"], version = "^0.25.0" }
fastapi = "^0.110.0"
uvicorn = { extras = ["standard"], version = "^0.28.0" }
sentry-sdk = "^1.31.0"
GitPython = "^3.1.30"
openpyxl = "^3.1.1"
async-lru = "^2.0.4"
thefuzz = "^0.20.0"
cryptography = "^41.0.4"
thefuzz = "^0.22.1"
cryptography = "^42.0.2"
pillow = "^10.0.1"
playwright = "1.39.0"
aiosqlite = { extras = ["sqlite"], version = "^0.19.0" }
aiosqlite = { extras = ["sqlite"], version = "^0.20.0" }
simnet = { git = "https://github.com/PaiGramTeam/SIMNet" }
psutil = "^5.9.6"
starrail-damage-cal = "^1.4.2"
[tool.poetry.extras]
pyro = ["Pyrogram", "TgCrypto"]

View File

@ -1,82 +1,93 @@
aiofiles==23.2.1 ; python_version >= "3.8" and python_version < "4.0"
aiolimiter==1.1.0 ; python_version >= "3.8" and python_version < "4.0"
aiosqlite[sqlite]==0.19.0 ; python_version >= "3.8" and python_version < "4.0"
aiosqlite[sqlite]==0.20.0 ; python_version >= "3.8" and python_version < "4.0"
alembic==1.13.1 ; python_version >= "3.8" and python_version < "4.0"
anyio==3.7.1 ; python_version >= "3.8" and python_version < "4.0"
anyio==4.3.0 ; python_version >= "3.8" and python_version < "4.0"
apscheduler==3.10.4 ; python_version >= "3.8" and python_version < "4.0"
arko-wrapper==0.2.8 ; python_version >= "3.8" and python_version < "4.0"
async-lru==2.0.4 ; python_version >= "3.8" and python_version < "4.0"
async-timeout==4.0.3 ; python_version >= "3.8" and python_full_version <= "3.11.2"
async-timeout==4.0.3 ; python_version >= "3.8" and python_full_version < "3.11.3"
asyncmy==0.2.9 ; python_version >= "3.8" and python_version < "4.0"
backports-zoneinfo==0.2.1 ; python_version >= "3.8" and python_version < "3.9"
beautifulsoup4==4.12.2 ; python_version >= "3.8" and python_version < "4.0"
black==23.12.1 ; python_version >= "3.8" and python_version < "4.0"
cachetools==5.3.2 ; python_version >= "3.8" and python_version < "4.0"
certifi==2023.11.17 ; python_version >= "3.8" and python_version < "4.0"
cffi==1.16.0 ; python_version >= "3.8" and python_version < "4.0"
beautifulsoup4==4.12.3 ; python_version >= "3.8" and python_version < "4.0"
black==24.2.0 ; python_version >= "3.8" and python_version < "4.0"
cachetools==5.3.3 ; python_version >= "3.8" and python_version < "4.0"
certifi==2024.2.2 ; python_version >= "3.8" and python_version < "4.0"
cffi==1.16.0 ; python_version >= "3.8" and python_version < "4.0" and platform_python_implementation != "PyPy"
click==8.1.7 ; python_version >= "3.8" and python_version < "4.0"
colorama==0.4.6 ; python_version >= "3.8" and python_version < "4.0" and (sys_platform == "win32" or platform_system == "Windows")
colorlog==6.8.0 ; python_version >= "3.8" and python_version < "4.0"
cryptography==41.0.7 ; python_version >= "3.8" and python_version < "4.0"
colorlog==6.8.2 ; python_version >= "3.8" and python_version < "4.0"
cryptography==42.0.5 ; python_version >= "3.8" and python_version < "4.0"
et-xmlfile==1.1.0 ; python_version >= "3.8" and python_version < "4.0"
exceptiongroup==1.2.0 ; python_version >= "3.8" and python_version < "3.11"
fakeredis==2.20.1 ; python_version >= "3.8" and python_version < "4.0"
fastapi==0.105.0 ; python_version >= "3.8" and python_version < "4.0"
fakeredis==2.21.3 ; python_version >= "3.8" and python_version < "4.0"
fastapi==0.110.0 ; python_version >= "3.8" and python_version < "4.0"
flaky==3.8.1 ; python_version >= "3.8" and python_version < "4.0"
gitdb==4.0.11 ; python_version >= "3.8" and python_version < "4.0"
gitpython==3.1.40 ; python_version >= "3.8" and python_version < "4.0"
gitpython==3.1.42 ; python_version >= "3.8" and python_version < "4.0"
greenlet==3.0.0 ; python_version >= "3.8" and python_version < "4.0"
h11==0.14.0 ; python_version >= "3.8" and python_version < "4.0"
httpcore==1.0.2 ; python_version >= "3.8" and python_version < "4.0"
httpcore==1.0.4 ; python_version >= "3.8" and python_version < "4.0"
httptools==0.6.1 ; python_version >= "3.8" and python_version < "4.0"
httpx==0.25.2 ; python_version >= "3.8" and python_version < "4.0"
idna==3.6 ; python_version >= "3.8" and python_version < "4.0"
importlib-metadata==7.0.1 ; python_version >= "3.8" and python_version < "3.9"
importlib-resources==6.1.1 ; python_version >= "3.8" and python_version < "3.9"
jinja2==3.1.2 ; python_version >= "3.8" and python_version < "4.0"
lxml==4.9.4 ; python_version >= "3.8" and python_version < "4.0"
mako==1.3.0 ; python_version >= "3.8" and python_version < "4.0"
importlib-metadata==7.0.2 ; python_version >= "3.8" and python_version < "3.9"
importlib-resources==6.3.0 ; python_version >= "3.8" and python_version < "3.9"
iniconfig==2.0.0 ; python_version >= "3.8" and python_version < "4.0"
jinja2==3.1.3 ; python_version >= "3.8" and python_version < "4.0"
lxml==5.1.0 ; python_version >= "3.8" and python_version < "4.0"
mako==1.3.2 ; python_version >= "3.8" and python_version < "4.0"
markdown-it-py==3.0.0 ; python_version >= "3.8" and python_version < "4.0"
markupsafe==2.1.3 ; python_version >= "3.8" and python_version < "4.0"
markupsafe==2.1.5 ; python_version >= "3.8" and python_version < "4.0"
mdurl==0.1.2 ; python_version >= "3.8" and python_version < "4.0"
msgspec==0.18.6 ; python_version >= "3.8" and python_version < "4.0"
mypy-extensions==1.0.0 ; python_version >= "3.8" and python_version < "4.0"
openpyxl==3.1.2 ; python_version >= "3.8" and python_version < "4.0"
packaging==23.2 ; python_version >= "3.8" and python_version < "4.0"
packaging==24.0 ; python_version >= "3.8" and python_version < "4.0"
pathspec==0.12.1 ; python_version >= "3.8" and python_version < "4.0"
pillow==10.1.0 ; python_version >= "3.8" and python_version < "4.0"
platformdirs==4.1.0 ; python_version >= "3.8" and python_version < "4.0"
pillow==10.2.0 ; python_version >= "3.8" and python_version < "4.0"
platformdirs==4.2.0 ; python_version >= "3.8" and python_version < "4.0"
playwright==1.39.0 ; python_version >= "3.8" and python_version < "4.0"
psutil==5.9.7 ; python_version >= "3.8" and python_version < "4.0"
pycparser==2.21 ; python_version >= "3.8" and python_version < "4.0"
pydantic==1.10.13 ; python_version >= "3.8" and python_version < "4.0"
pluggy==1.4.0 ; python_version >= "3.8" and python_version < "4.0"
psutil==5.9.8 ; python_version >= "3.8" and python_version < "4.0"
pyaes==1.6.1 ; python_version >= "3.8" and python_version < "4.0"
pycparser==2.21 ; python_version >= "3.8" and python_version < "4.0" and platform_python_implementation != "PyPy"
pydantic==1.10.14 ; python_version >= "3.8" and python_version < "4.0"
pyee==11.0.1 ; python_version >= "3.8" and python_version < "4.0"
pygments==2.17.2 ; python_version >= "3.8" and python_version < "4.0"
python-dotenv==1.0.0 ; python_version >= "3.8" and python_version < "4.0"
pyrogram==2.0.106 ; python_version >= "3.8" and python_version < "4.0"
pysocks==1.7.1 ; python_version >= "3.8" and python_version < "4.0"
pytest-asyncio==0.23.5.post1 ; python_version >= "3.8" and python_version < "4.0"
pytest==7.4.4 ; python_version >= "3.8" and python_version < "4.0"
python-dotenv==1.0.1 ; python_version >= "3.8" and python_version < "4.0"
python-telegram-bot[ext,rate-limiter]==20.7 ; python_version >= "3.8" and python_version < "4.0"
pytz==2023.3.post1 ; python_version >= "3.8" and python_version < "4.0"
pytz==2024.1 ; python_version >= "3.8" and python_version < "4.0"
pyyaml==6.0.1 ; python_version >= "3.8" and python_version < "4.0"
rapidfuzz==3.6.0 ; python_version >= "3.8" and python_version < "4.0"
redis==5.0.1 ; python_version >= "3.8" and python_version < "4.0"
rich==13.7.0 ; python_version >= "3.8" and python_version < "4.0"
sentry-sdk==1.39.1 ; python_version >= "3.8" and python_version < "4.0"
rapidfuzz==3.6.2 ; python_version >= "3.8" and python_version < "4.0"
redis==5.0.3 ; python_version >= "3.8" and python_version < "4.0"
rich==13.7.1 ; python_version >= "3.8" and python_version < "4.0"
sentry-sdk==1.42.0 ; python_version >= "3.8" and python_version < "4.0"
simnet @ git+https://github.com/PaiGramTeam/SIMNet@main ; python_version >= "3.8" and python_version < "4.0"
six==1.16.0 ; python_version >= "3.8" and python_version < "4.0"
smmap==5.0.1 ; python_version >= "3.8" and python_version < "4.0"
sniffio==1.3.0 ; python_version >= "3.8" and python_version < "4.0"
sniffio==1.3.1 ; python_version >= "3.8" and python_version < "4.0"
sortedcontainers==2.4.0 ; python_version >= "3.8" and python_version < "4.0"
soupsieve==2.5 ; python_version >= "3.8" and python_version < "4.0"
sqlalchemy==2.0.23 ; python_version >= "3.8" and python_version < "4.0"
sqlmodel==0.0.14 ; python_version >= "3.8" and python_version < "4.0"
starlette==0.27.0 ; python_version >= "3.8" and python_version < "4.0"
thefuzz==0.20.0 ; python_version >= "3.8" and python_version < "4.0"
sqlalchemy==2.0.28 ; python_version >= "3.8" and python_version < "4.0"
sqlmodel==0.0.16 ; python_version >= "3.8" and python_version < "4.0"
starlette==0.36.3 ; python_version >= "3.8" and python_version < "4.0"
starrail-damage-cal==1.4.2 ; python_version >= "3.8" and python_version < "4.0"
tgcrypto==1.2.5 ; python_version >= "3.8" and python_version < "4.0"
thefuzz==0.22.1 ; python_version >= "3.8" and python_version < "4.0"
tomli==2.0.1 ; python_version >= "3.8" and python_version < "3.11"
tornado==6.3.3 ; python_version >= "3.8" and python_version < "4.0"
typing-extensions==4.9.0 ; python_version >= "3.8" and python_version < "4.0"
tzdata==2023.3 ; python_version >= "3.8" and python_version < "4.0" and platform_system == "Windows"
typing-extensions==4.10.0 ; python_version >= "3.8" and python_version < "4.0"
tzdata==2024.1 ; python_version >= "3.8" and python_version < "4.0" and platform_system == "Windows"
tzlocal==5.2 ; python_version >= "3.8" and python_version < "4.0"
ujson==5.9.0 ; python_version >= "3.8" and python_version < "4.0"
urllib3==2.1.0 ; python_version >= "3.8" and python_version < "4.0"
uvicorn[standard]==0.25.0 ; python_version >= "3.8" and python_version < "4.0"
urllib3==2.2.1 ; python_version >= "3.8" and python_version < "4.0"
uvicorn[standard]==0.28.0 ; python_version >= "3.8" and python_version < "4.0"
uvloop==0.19.0 ; (sys_platform != "win32" and sys_platform != "cygwin") and platform_python_implementation != "PyPy" and python_version >= "3.8" and python_version < "4.0"
watchfiles==0.21.0 ; python_version >= "3.8" and python_version < "4.0"
websockets==12.0 ; python_version >= "3.8" and python_version < "4.0"
zipp==3.17.0 ; python_version >= "3.8" and python_version < "3.9"
zipp==3.18.1 ; python_version >= "3.8" and python_version < "3.9"

View File

@ -0,0 +1,24 @@
<table class="table-auto border-collapse w-full bg-black bg-opacity-20 rounded-lg">
<thead>
<tr class="bg-black bg-opacity-20">
<th class="px-4 py-2">技能</th>
<th class="px-4 py-2">暴击伤害</th>
<th class="px-4 py-2">期望伤害</th>
<th class="px-4 py-2">满配辅助末日兽</th>
</tr>
</thead>
<tbody>
{% for item in damage_info %}
<tr class="text-center odd:bg-white odd:bg-opacity-10">
<td class="border px-4 py-2">{{ item.name }}</td>
{% if item.damagelist|length == 1 %}
<td class="border px-4 py-2 " colspan="3">{{ item.damagelist[0]|round|int }}</td>
{% else %}
{% for damage in item.damagelist %}
<td class="border px-4 py-2">{{ damage|round|int }}</td>
{% endfor %}
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>

View File

@ -49,6 +49,10 @@
font-family: shicon;
font-size: 1.25em;
}
body {
width: 1050px;
}
</style>
</head>
<body class="text-xl text-neutral-200">
@ -91,16 +95,23 @@
</div>
<!-- Info -->
<div class="px-5 relative">
<div class="px-5 relative mb-4">
<div class="grid grid-cols-3 gap-4">
{% include 'starrail/player_card/artifacts.html' %}
</div>
</div>
<!-- damage -->
{%- if damage_function_available == True -%}
<div class="px-5 relative">
{% include "starrail/player_card/damage.html" %}
</div>
{%- endif -%}
<!-- Logo -->
<div class="mt-4 relative">
<div class="text-gray-300 text-center opacity-70 text-lg">
Inspired by Miao-Plugin & Data by MiHoMo.Me
Data from MiHoMo.Me × Inspired by Miao-Plugin × Damage Cal by StarRailUID
</div>
</div>
</div>