fix icon mapping in campaign ranking
This commit is contained in:
parent
0bfe27e0d3
commit
d766befd31
5 changed files with 113 additions and 58 deletions
|
|
@ -37,24 +37,23 @@ class ResultChecker:
|
|||
context_type: ContextType,
|
||||
context_id: str,
|
||||
scores: Dict[str, ParticipantScore],
|
||||
) -> List[Tuple[int, List[str]]]:
|
||||
) -> List[Tuple[int, List[str], Dict[str, int]]]:
|
||||
vp_buckets: Dict[int, List[str]] = defaultdict(list)
|
||||
for pid, score in scores.items():
|
||||
vp_buckets[score.victory_points].append(pid)
|
||||
sorted_vps = sorted(vp_buckets.keys(), reverse=True)
|
||||
ranking: List[Tuple[int, List[str]]] = []
|
||||
ranking: List[Tuple[int, List[str], Dict[str, int]]] = []
|
||||
current_rank = 1
|
||||
for vp in sorted_vps:
|
||||
participants = vp_buckets[vp]
|
||||
# no tie
|
||||
if len(participants) == 1:
|
||||
ranking.append((current_rank, participants))
|
||||
current_rank += 1
|
||||
continue
|
||||
tie_id = f"{context_id}:score:{vp}"
|
||||
# tie unresolved → shared rank (theoretically impossible)
|
||||
if not TieResolver.is_tie_resolved(war, context_type, tie_id):
|
||||
ranking.append((current_rank, participants))
|
||||
# no tie
|
||||
if len(participants) == 1 or not TieResolver.is_tie_resolved(
|
||||
war, context_type, tie_id
|
||||
):
|
||||
ranking.append(
|
||||
(current_rank, participants, {pid: 0 for pid in participants})
|
||||
)
|
||||
current_rank += 1
|
||||
continue
|
||||
# apply token ranking
|
||||
|
|
@ -64,7 +63,11 @@ class ResultChecker:
|
|||
tie_id,
|
||||
participants,
|
||||
)
|
||||
tokens_spent = TieResolver.tokens_spent_map(
|
||||
war, context_type, tie_id, participants
|
||||
)
|
||||
for group in groups:
|
||||
ranking.append((current_rank, group))
|
||||
group_tokens = {pid: tokens_spent[pid] for pid in group}
|
||||
ranking.append((current_rank, group, group_tokens))
|
||||
current_rank += 1
|
||||
return ranking
|
||||
|
|
|
|||
|
|
@ -131,6 +131,24 @@ class TieResolver:
|
|||
groups[-1].append(pid)
|
||||
return groups
|
||||
|
||||
@staticmethod
|
||||
def tokens_spent_map(
|
||||
war: War,
|
||||
context_type: ContextType,
|
||||
context_id: str,
|
||||
participants: List[str],
|
||||
) -> Dict[str, int]:
|
||||
spent = {pid: 0 for pid in participants}
|
||||
for ev in war.events:
|
||||
if (
|
||||
isinstance(ev, InfluenceSpent)
|
||||
and ev.context_type == context_type
|
||||
and ev.context_id == context_id
|
||||
and ev.participant_id in spent
|
||||
):
|
||||
spent[ev.participant_id] += ev.amount
|
||||
return spent
|
||||
|
||||
@staticmethod
|
||||
def get_active_participants(
|
||||
war: War,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue