mirror of
https://github.com/A-Minos/nonebot-plugin-tetris-stats.git
synced 2026-03-05 05:36:54 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 144c223fe9 | |||
|
|
52a6d95434 | ||
| d8255756ca | |||
|
|
13c6d53b6a |
@@ -0,0 +1,52 @@
|
|||||||
|
"""modify field length
|
||||||
|
|
||||||
|
迁移 ID: 3588702dd3a4
|
||||||
|
父迁移: bc6abd57928f
|
||||||
|
创建时间: 2025-07-19 17:21:17.927162
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from alembic import op
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Sequence
|
||||||
|
|
||||||
|
revision: str = '3588702dd3a4'
|
||||||
|
down_revision: str | Sequence[str] | None = 'bc6abd57928f'
|
||||||
|
branch_labels: str | Sequence[str] | None = None
|
||||||
|
depends_on: str | Sequence[str] | None = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade(name: str = '') -> None:
|
||||||
|
if name:
|
||||||
|
return
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
with op.batch_alter_table('nb_t_tos_hist_data', schema=None) as batch_op:
|
||||||
|
batch_op.alter_column(
|
||||||
|
'user_unique_identifier',
|
||||||
|
existing_type=sa.VARCHAR(length=24),
|
||||||
|
type_=sa.String(length=256),
|
||||||
|
existing_nullable=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade(name: str = '') -> None:
|
||||||
|
if name:
|
||||||
|
return
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
with op.batch_alter_table('nb_t_tos_hist_data', schema=None) as batch_op:
|
||||||
|
batch_op.alter_column(
|
||||||
|
'user_unique_identifier',
|
||||||
|
existing_type=sa.String(length=256),
|
||||||
|
type_=sa.VARCHAR(length=24),
|
||||||
|
existing_nullable=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
# ### end Alembic commands ###
|
||||||
@@ -5,7 +5,7 @@ from nonebot_plugin_alconna import Option, Subcommand, UniMessage
|
|||||||
from nonebot_plugin_orm import get_session
|
from nonebot_plugin_orm import get_session
|
||||||
from nonebot_plugin_uninfo import Uninfo
|
from nonebot_plugin_uninfo import Uninfo
|
||||||
from nonebot_plugin_uninfo.orm import get_session_persist_id
|
from nonebot_plugin_uninfo.orm import get_session_persist_id
|
||||||
from sqlalchemy import func, select
|
from sqlalchemy import select
|
||||||
from sqlalchemy.orm import selectinload
|
from sqlalchemy.orm import selectinload
|
||||||
|
|
||||||
from ....db import trigger
|
from ....db import trigger
|
||||||
@@ -41,6 +41,7 @@ async def _(event_session: Uninfo, template: Template | None = None):
|
|||||||
command_args=['--all'] + ([f'--template {template}'] if template is not None else []),
|
command_args=['--all'] + ([f'--template {template}'] if template is not None else []),
|
||||||
):
|
):
|
||||||
async with get_session() as session:
|
async with get_session() as session:
|
||||||
|
# 获取最新记录
|
||||||
latest_data = (
|
latest_data = (
|
||||||
await session.scalars(
|
await session.scalars(
|
||||||
select(TETRIOLeagueStats)
|
select(TETRIOLeagueStats)
|
||||||
@@ -49,19 +50,42 @@ async def _(event_session: Uninfo, template: Template | None = None):
|
|||||||
.options(selectinload(TETRIOLeagueStats.fields))
|
.options(selectinload(TETRIOLeagueStats.fields))
|
||||||
)
|
)
|
||||||
).one()
|
).one()
|
||||||
compare_data = (
|
|
||||||
await session.scalars(
|
# 计算目标时间点 (24小时前)
|
||||||
|
target_time = latest_data.update_time - timedelta(hours=24)
|
||||||
|
|
||||||
|
# 查询目标时间点之前的最近记录
|
||||||
|
before = (
|
||||||
|
await session.scalar(
|
||||||
select(TETRIOLeagueStats)
|
select(TETRIOLeagueStats)
|
||||||
.order_by(
|
.where(TETRIOLeagueStats.update_time <= target_time)
|
||||||
func.abs(
|
.order_by(TETRIOLeagueStats.update_time.desc())
|
||||||
func.julianday(TETRIOLeagueStats.update_time)
|
|
||||||
- func.julianday(latest_data.update_time - timedelta(hours=24))
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.limit(1)
|
.limit(1)
|
||||||
.options(selectinload(TETRIOLeagueStats.fields))
|
.options(selectinload(TETRIOLeagueStats.fields))
|
||||||
)
|
)
|
||||||
).one()
|
or latest_data
|
||||||
|
)
|
||||||
|
|
||||||
|
# 查询目标时间点之后的最近记录
|
||||||
|
after = (
|
||||||
|
await session.scalar(
|
||||||
|
select(TETRIOLeagueStats)
|
||||||
|
.where(TETRIOLeagueStats.update_time >= target_time) # 使用 >= 避免间隙
|
||||||
|
.order_by(TETRIOLeagueStats.update_time.asc())
|
||||||
|
.limit(1)
|
||||||
|
.options(selectinload(TETRIOLeagueStats.fields))
|
||||||
|
)
|
||||||
|
or latest_data
|
||||||
|
)
|
||||||
|
|
||||||
|
# 确定最接近的记录
|
||||||
|
compare_data = (
|
||||||
|
before
|
||||||
|
if abs((target_time - before.update_time).total_seconds())
|
||||||
|
< abs((target_time - after.update_time).total_seconds())
|
||||||
|
else after
|
||||||
|
)
|
||||||
|
|
||||||
match template:
|
match template:
|
||||||
case 'v1' | None:
|
case 'v1' | None:
|
||||||
await UniMessage.image(raw=await make_image_v1(latest_data, compare_data)).finish()
|
await UniMessage.image(raw=await make_image_v1(latest_data, compare_data)).finish()
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from nonebot_plugin_alconna import Option, UniMessage
|
|||||||
from nonebot_plugin_orm import get_session
|
from nonebot_plugin_orm import get_session
|
||||||
from nonebot_plugin_uninfo import Uninfo
|
from nonebot_plugin_uninfo import Uninfo
|
||||||
from nonebot_plugin_uninfo.orm import get_session_persist_id
|
from nonebot_plugin_uninfo.orm import get_session_persist_id
|
||||||
from sqlalchemy import func, select
|
from sqlalchemy import select
|
||||||
from sqlalchemy.orm import selectinload
|
from sqlalchemy.orm import selectinload
|
||||||
|
|
||||||
from ....db import trigger
|
from ....db import trigger
|
||||||
@@ -39,6 +39,7 @@ async def _(rank: ValidRank, event_session: Uninfo):
|
|||||||
command_args=[f'--detail {rank}'],
|
command_args=[f'--detail {rank}'],
|
||||||
):
|
):
|
||||||
async with get_session() as session:
|
async with get_session() as session:
|
||||||
|
# 获取最新记录
|
||||||
latest_data = (
|
latest_data = (
|
||||||
await session.scalars(
|
await session.scalars(
|
||||||
select(TETRIOLeagueStats)
|
select(TETRIOLeagueStats)
|
||||||
@@ -47,19 +48,41 @@ async def _(rank: ValidRank, event_session: Uninfo):
|
|||||||
.options(selectinload(TETRIOLeagueStats.fields))
|
.options(selectinload(TETRIOLeagueStats.fields))
|
||||||
)
|
)
|
||||||
).one()
|
).one()
|
||||||
compare_data = (
|
|
||||||
await session.scalars(
|
# 计算目标时间点 (24小时前)
|
||||||
|
target_time = latest_data.update_time - timedelta(hours=24)
|
||||||
|
|
||||||
|
# 查询目标时间点之前的最近记录
|
||||||
|
before = (
|
||||||
|
await session.scalar(
|
||||||
select(TETRIOLeagueStats)
|
select(TETRIOLeagueStats)
|
||||||
.order_by(
|
.where(TETRIOLeagueStats.update_time <= target_time)
|
||||||
func.abs(
|
.order_by(TETRIOLeagueStats.update_time.desc())
|
||||||
func.julianday(TETRIOLeagueStats.update_time)
|
|
||||||
- func.julianday(latest_data.update_time - timedelta(hours=24))
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.limit(1)
|
.limit(1)
|
||||||
.options(selectinload(TETRIOLeagueStats.fields))
|
.options(selectinload(TETRIOLeagueStats.fields))
|
||||||
)
|
)
|
||||||
).one()
|
or latest_data # 回退到最新记录
|
||||||
|
)
|
||||||
|
|
||||||
|
# 查询目标时间点之后的最近记录
|
||||||
|
after = (
|
||||||
|
await session.scalar(
|
||||||
|
select(TETRIOLeagueStats)
|
||||||
|
.where(TETRIOLeagueStats.update_time >= target_time)
|
||||||
|
.order_by(TETRIOLeagueStats.update_time.asc())
|
||||||
|
.limit(1)
|
||||||
|
.options(selectinload(TETRIOLeagueStats.fields))
|
||||||
|
)
|
||||||
|
or latest_data # 回退到最新记录
|
||||||
|
)
|
||||||
|
|
||||||
|
# 确定最接近的记录
|
||||||
|
compare_data = (
|
||||||
|
before
|
||||||
|
if abs((target_time - before.update_time).total_seconds())
|
||||||
|
< abs((target_time - after.update_time).total_seconds())
|
||||||
|
else after
|
||||||
|
)
|
||||||
await UniMessage.image(
|
await UniMessage.image(
|
||||||
raw=await make_image(
|
raw=await make_image(
|
||||||
rank,
|
rank,
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class TOSHistoricalData(MappedAsDataclass, Model):
|
|||||||
__tablename__ = 'nb_t_tos_hist_data'
|
__tablename__ = 'nb_t_tos_hist_data'
|
||||||
|
|
||||||
id: Mapped[int] = mapped_column(init=False, primary_key=True)
|
id: Mapped[int] = mapped_column(init=False, primary_key=True)
|
||||||
user_unique_identifier: Mapped[str] = mapped_column(String(24), index=True)
|
user_unique_identifier: Mapped[str] = mapped_column(String(256), index=True)
|
||||||
api_type: Mapped[Literal['User Info', 'User Profile']] = mapped_column(String(16), index=True)
|
api_type: Mapped[Literal['User Info', 'User Profile']] = mapped_column(String(16), index=True)
|
||||||
data: Mapped[UserInfoSuccess | UserProfile] = mapped_column(
|
data: Mapped[UserInfoSuccess | UserProfile] = mapped_column(
|
||||||
PydanticType(get_model=[], models={UserInfoSuccess, UserProfile})
|
PydanticType(get_model=[], models={UserInfoSuccess, UserProfile})
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "nonebot-plugin-tetris-stats"
|
name = "nonebot-plugin-tetris-stats"
|
||||||
version = "1.10.0"
|
version = "1.10.2"
|
||||||
description = "一款基于 NoneBot2 的用于查询 Tetris 相关游戏数据的插件"
|
description = "一款基于 NoneBot2 的用于查询 Tetris 相关游戏数据的插件"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
authors = [{ name = "shoucandanghehe", email = "wallfjjd@gmail.com" }]
|
authors = [{ name = "shoucandanghehe", email = "wallfjjd@gmail.com" }]
|
||||||
@@ -162,7 +162,7 @@ defineConstant = { PYDANTIC_V2 = true }
|
|||||||
typeCheckingMode = "standard"
|
typeCheckingMode = "standard"
|
||||||
|
|
||||||
[tool.bumpversion]
|
[tool.bumpversion]
|
||||||
current_version = "1.10.0"
|
current_version = "1.10.2"
|
||||||
tag = true
|
tag = true
|
||||||
sign_tags = true
|
sign_tags = true
|
||||||
tag_name = "{new_version}"
|
tag_name = "{new_version}"
|
||||||
|
|||||||
Reference in New Issue
Block a user