mirror of
https://github.com/PaiGramTeam/PaiGram.git
synced 2024-11-24 17:19:40 +00:00
✨ 随机获取深渊推荐队伍
This commit is contained in:
parent
1b5d7fdf9c
commit
95b1381975
@ -1,3 +1,4 @@
|
||||
import secrets
|
||||
import time
|
||||
from typing import List, Optional, Any
|
||||
|
||||
@ -25,6 +26,7 @@ class FullTeamRate(BaseModel):
|
||||
up: TeamRate
|
||||
down: TeamRate
|
||||
owner_num: Optional[int]
|
||||
nice: Optional[float]
|
||||
|
||||
@property
|
||||
def rate(self) -> float:
|
||||
@ -48,7 +50,18 @@ class TeamRateResult(BaseModel):
|
||||
def sort(self, characters: List[str]):
|
||||
for team in self.rate_list_full:
|
||||
team.owner_num = sum(member.name in characters for member in team.up.formation + team.down.formation)
|
||||
self.rate_list_full.sort(key=lambda x: (x.owner_num / 8 * x.rate), reverse=True)
|
||||
team.nice = team.owner_num / 8 * team.rate
|
||||
self.rate_list_full.sort(key=lambda x: x.nice, reverse=True)
|
||||
|
||||
def random_team(self, characters: List[str]) -> FullTeamRate:
|
||||
self.sort(characters)
|
||||
max_nice = self.rate_list_full[0].nice
|
||||
nice_teams: List[FullTeamRate] = []
|
||||
for team in self.rate_list_full:
|
||||
if team.nice < max_nice:
|
||||
break
|
||||
nice_teams.append(team)
|
||||
return secrets.choice(nice_teams)
|
||||
|
||||
|
||||
class AbyssTeamData:
|
||||
|
@ -60,12 +60,12 @@ class AbyssTeam(Plugin, BasePlugin):
|
||||
team_data = await self.team_data.get_data()
|
||||
# 尝试获取用户已绑定的原神账号信息
|
||||
user_data = await self._get_data_from_user(user)
|
||||
team_data.sort(user_data)
|
||||
random_team = team_data.random_team(user_data)
|
||||
abyss_team_data = {
|
||||
"up": [],
|
||||
"down": []
|
||||
}
|
||||
for i in team_data.rate_list_full[0].up.formation:
|
||||
for i in random_team.up.formation:
|
||||
temp = {
|
||||
"icon": (await self.assets_service.avatar(roleToId(i.name)).icon()).as_uri(),
|
||||
"name": i.name,
|
||||
@ -73,7 +73,7 @@ class AbyssTeam(Plugin, BasePlugin):
|
||||
"hava": (i.name in user_data) if user_data else True,
|
||||
}
|
||||
abyss_team_data["up"].append(temp)
|
||||
for i in team_data.rate_list_full[0].down.formation:
|
||||
for i in random_team.down.formation:
|
||||
temp = {
|
||||
"icon": (await self.assets_service.avatar(roleToId(i.name)).icon()).as_uri(),
|
||||
"name": i.name,
|
||||
|
@ -30,9 +30,11 @@ async def test_abyss_team_data(abyss_team_data: AbyssTeamData):
|
||||
team_data.sort(["迪奥娜", "芭芭拉", "凯亚", "琴"])
|
||||
assert isinstance(team_data.rate_list_full[0], FullTeamRate)
|
||||
assert isinstance(team_data.rate_list_full[-1], FullTeamRate)
|
||||
memberUp = {i.name for i in team_data.rate_list_full[0].up.formation}
|
||||
memberDown = {i.name for i in team_data.rate_list_full[0].down.formation}
|
||||
assert not memberUp & memberDown
|
||||
random_team = team_data.random_team(["迪奥娜", "芭芭拉", "凯亚", "琴"])
|
||||
assert isinstance(random_team, FullTeamRate)
|
||||
member_up = {i.name for i in random_team.up.formation}
|
||||
member_down = {i.name for i in random_team.down.formation}
|
||||
assert not member_up & member_down
|
||||
for i in team_data.rate_list_full[0].down.formation:
|
||||
LOGGER.info("rate down info:name %s star %s", i.name, i.star)
|
||||
for i in team_data.rate_list_full[0].up.formation:
|
||||
|
Loading…
Reference in New Issue
Block a user