Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

预组队相关 #31

Merged
merged 1 commit into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 56 additions & 4 deletions app/lol/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,63 @@ def getTeammates(game, targetPuuid):
return res


def checkTeam(summoners, targetPuuid):
visited = {summoner['name']: False for summoner in summoners}
counter = 1
def assignTeamId(summoners):
"""
分配队伍ID

存储于teamId字段, 自1递增的数字, 若无队伍则为None

---
较此前完善判断逻辑:
1. A单向B, B单向C -> AB都记为 None
2. A双向B, B双向C -> ABC记为同一 teamId
3. A双向B且单向C -> AB记为同一 teamId, C记为None
---

@param summoners: 召唤师信息
[{
"summonerId": 123456,
"teammatesMarker": [{'summonerId': 333333, 'cnt': 3, 'name': "召唤师1"}]
}, ... ]

@return: 变更直接作用于入参 :summoners: 同时会return; 两者为同一实例;

"""
team_id = 1
summoner_to_team = {}

# 123456: [333333]
# key=summonerId
# value=teammates
summoner_to_teammates = {
summoner["summonerId"]: [teammate["summonerId"] for teammate in summoner["teammatesMarker"]] for summoner in
summoners}

for summoner_id, teammates in summoner_to_teammates.items():
for teammate_id in teammates:
# 检查双向队友
if summoner_id in summoner_to_teammates[teammate_id]:
# 检查teamId
if summoner_id not in summoner_to_team and teammate_id not in summoner_to_team:
summoner_to_team[summoner_id] = team_id
summoner_to_team[teammate_id] = team_id
team_id += 1
# summoner已有teamId, 但队友没有时, 为队友分配相同的teamId
elif summoner_id in summoner_to_team and teammate_id not in summoner_to_team:
summoner_to_team[teammate_id] = summoner_to_team[summoner_id]
# 队友已有teamId, 但summoner没有时, 为summoner分配相同的teamId
elif teammate_id in summoner_to_team and summoner_id not in summoner_to_team:
summoner_to_team[summoner_id] = summoner_to_team[teammate_id]

# 将teamId添加到原始数据中
for summoner in summoners:
if summoner["summonerId"] in summoner_to_team:
summoner["teamId"] = summoner_to_team[summoner["summonerId"]]
else:
# 无队伍以及单向的标记为 None
summoner["teamId"] = None

# TODO!
return summoners


def getRecentChampions(games):
Expand Down
37 changes: 1 addition & 36 deletions app/view/game_info_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,41 +194,6 @@ def __initLayout(self):
def updateSummoners(self, summoners):
self.clear()

# 取出所有summonerId的映射
"""
{
1234: {6666},
6666: {1234},
9999: set(),
}
"""
teams = {item["summonerId"]: set([member["summonerId"] for member in item["teammatesMarker"]]) for item in summoners}

team_ids = {}

def dfs(node, team_id):
"""
深度搜索 dfs 分配 team id
"""
if node in team_ids: # 已经有队伍ID
return

# 深度搜索成员, 分配队伍ID
team_ids[node] = team_id
for member in teams[node]:
dfs(member, team_id)

current_team_id = 1
for summoner in teams:
if teams[summoner] and summoner not in team_ids: # 有队伍, 且未分配id
dfs(summoner, current_team_id)
current_team_id += 1

# 整理结果, 放回summoners;
# teamId为从1开始的值, 若未预组队则为None
for item in summoners:
item["teamId"] = team_ids.get(item["summonerId"], None)

for summoner in summoners:
summonerView = SummonerInfoView(summoner)
self.vBoxLayout.addWidget(summonerView)
Expand Down Expand Up @@ -259,7 +224,7 @@ def __init__(self, info: dict, parent=None):
sep=20)

self.teammateIcon = None
if info["teammatesMarker"]:
if info["teammatesMarker"] and info["teamId"]:
self.teammateIcon = QLabel()
self.teammateIcon.setPixmap(
QPixmap(Icon.TEAM.path()).scaled(
Expand Down
6 changes: 5 additions & 1 deletion app/view/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
getLolProcessPid)
from ..lol.connector import connector
from ..lol.tools import (processGameData, translateTier, getRecentChampions,
processRankInfo, getTeammates)
processRankInfo, getTeammates, assignTeamId)

import threading
from concurrent.futures import ThreadPoolExecutor, as_completed
Expand Down Expand Up @@ -743,6 +743,8 @@ def process_item(item):
if result is not None:
summoners.append(result)

assignTeamId(summoners)

self.gameInfoInterface.allySummonersInfoReady.emit(
{'summoners': summoners})

Expand Down Expand Up @@ -864,6 +866,8 @@ def process_item(item):
if result is not None:
summoners.append(result)

assignTeamId(summoners)

self.gameInfoInterface.enemySummonerInfoReady.emit(
{'summoners': summoners, 'queueId': queueId})

Expand Down
Loading