随机获取深渊推荐队伍

This commit is contained in:
SiHuaN 2022-10-08 11:16:52 +08:00 committed by GitHub
parent 1b5d7fdf9c
commit 95b1381975
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 7 deletions

View File

@ -1,3 +1,4 @@
import secrets
import time import time
from typing import List, Optional, Any from typing import List, Optional, Any
@ -25,6 +26,7 @@ class FullTeamRate(BaseModel):
up: TeamRate up: TeamRate
down: TeamRate down: TeamRate
owner_num: Optional[int] owner_num: Optional[int]
nice: Optional[float]
@property @property
def rate(self) -> float: def rate(self) -> float:
@ -48,7 +50,18 @@ class TeamRateResult(BaseModel):
def sort(self, characters: List[str]): def sort(self, characters: List[str]):
for team in self.rate_list_full: for team in self.rate_list_full:
team.owner_num = sum(member.name in characters for member in team.up.formation + team.down.formation) 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: class AbyssTeamData:

View File

@ -60,12 +60,12 @@ class AbyssTeam(Plugin, BasePlugin):
team_data = await self.team_data.get_data() team_data = await self.team_data.get_data()
# 尝试获取用户已绑定的原神账号信息 # 尝试获取用户已绑定的原神账号信息
user_data = await self._get_data_from_user(user) 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 = { abyss_team_data = {
"up": [], "up": [],
"down": [] "down": []
} }
for i in team_data.rate_list_full[0].up.formation: for i in random_team.up.formation:
temp = { temp = {
"icon": (await self.assets_service.avatar(roleToId(i.name)).icon()).as_uri(), "icon": (await self.assets_service.avatar(roleToId(i.name)).icon()).as_uri(),
"name": i.name, "name": i.name,
@ -73,7 +73,7 @@ class AbyssTeam(Plugin, BasePlugin):
"hava": (i.name in user_data) if user_data else True, "hava": (i.name in user_data) if user_data else True,
} }
abyss_team_data["up"].append(temp) 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 = { temp = {
"icon": (await self.assets_service.avatar(roleToId(i.name)).icon()).as_uri(), "icon": (await self.assets_service.avatar(roleToId(i.name)).icon()).as_uri(),
"name": i.name, "name": i.name,

View File

@ -30,9 +30,11 @@ async def test_abyss_team_data(abyss_team_data: AbyssTeamData):
team_data.sort(["迪奥娜", "芭芭拉", "凯亚", ""]) team_data.sort(["迪奥娜", "芭芭拉", "凯亚", ""])
assert isinstance(team_data.rate_list_full[0], FullTeamRate) assert isinstance(team_data.rate_list_full[0], FullTeamRate)
assert isinstance(team_data.rate_list_full[-1], FullTeamRate) assert isinstance(team_data.rate_list_full[-1], FullTeamRate)
memberUp = {i.name for i in team_data.rate_list_full[0].up.formation} random_team = team_data.random_team(["迪奥娜", "芭芭拉", "凯亚", ""])
memberDown = {i.name for i in team_data.rate_list_full[0].down.formation} assert isinstance(random_team, FullTeamRate)
assert not memberUp & memberDown 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: for i in team_data.rate_list_full[0].down.formation:
LOGGER.info("rate down info:name %s star %s", i.name, i.star) LOGGER.info("rate down info:name %s star %s", i.name, i.star)
for i in team_data.rate_list_full[0].up.formation: for i in team_data.rate_list_full[0].up.formation: