display objective awards in participant tables
This commit is contained in:
parent
53b1fc916c
commit
f55106c260
8 changed files with 160 additions and 24 deletions
|
|
@ -1,5 +1,5 @@
|
|||
from __future__ import annotations
|
||||
from typing import List, Tuple, Dict, TYPE_CHECKING
|
||||
from typing import List, Tuple, Dict, TYPE_CHECKING, Callable
|
||||
from collections import defaultdict
|
||||
|
||||
from warchron.constants import ContextType
|
||||
|
|
@ -36,15 +36,16 @@ class ResultChecker:
|
|||
context_type: ContextType,
|
||||
context_id: str,
|
||||
scores: Dict[str, ParticipantScore],
|
||||
value_getter: Callable[[ParticipantScore], int],
|
||||
) -> List[Tuple[int, List[str], Dict[str, int]]]:
|
||||
vp_buckets: Dict[int, List[str]] = defaultdict(list)
|
||||
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)
|
||||
buckets[value_getter(score)].append(pid)
|
||||
sorted_vps = sorted(buckets.keys(), reverse=True)
|
||||
ranking: List[Tuple[int, List[str], Dict[str, int]]] = []
|
||||
current_rank = 1
|
||||
for vp in sorted_vps:
|
||||
participants = vp_buckets[vp]
|
||||
for value in sorted_vps:
|
||||
participants = buckets[value]
|
||||
if context_type == ContextType.WAR and len(participants) > 1:
|
||||
subgroups = ResultChecker._secondary_sorting_war(war, participants)
|
||||
for subgroup in subgroups:
|
||||
|
|
@ -57,7 +58,7 @@ class ResultChecker:
|
|||
continue
|
||||
# normal tie-break if tie persists
|
||||
if not TieResolver.is_tie_resolved(
|
||||
war, context_type, context_id, vp
|
||||
war, context_type, context_id, value
|
||||
):
|
||||
ranking.append(
|
||||
(current_rank, subgroup, {pid: 0 for pid in subgroup})
|
||||
|
|
@ -80,7 +81,7 @@ class ResultChecker:
|
|||
continue
|
||||
# no tie
|
||||
if len(participants) == 1 or not TieResolver.is_tie_resolved(
|
||||
war, context_type, context_id, vp
|
||||
war, context_type, context_id, value
|
||||
):
|
||||
ranking.append(
|
||||
(current_rank, participants, {pid: 0 for pid in participants})
|
||||
|
|
@ -118,7 +119,11 @@ class ResultChecker:
|
|||
war, ContextType.CAMPAIGN, campaign.id
|
||||
)
|
||||
ranking = ResultChecker.get_effective_ranking(
|
||||
war, ContextType.CAMPAIGN, campaign.id, scores
|
||||
war,
|
||||
ContextType.CAMPAIGN,
|
||||
campaign.id,
|
||||
scores,
|
||||
lambda s: s.victory_points,
|
||||
)
|
||||
for rank, group, _ in ranking:
|
||||
if pid in group:
|
||||
|
|
|
|||
|
|
@ -146,7 +146,11 @@ class TieResolver:
|
|||
|
||||
scores = ScoreService.compute_scores(war, ContextType.WAR, war.id)
|
||||
ranking = ResultChecker.get_effective_ranking(
|
||||
war, ContextType.WAR, war.id, scores
|
||||
war,
|
||||
ContextType.WAR,
|
||||
war.id,
|
||||
scores,
|
||||
value_getter=lambda s: s.victory_points,
|
||||
)
|
||||
ties: List[TieContext] = []
|
||||
for _, group, _ in ranking:
|
||||
|
|
@ -191,6 +195,7 @@ class TieResolver:
|
|||
ContextType.OBJECTIVE,
|
||||
f"{war.id}:{objective_id}",
|
||||
scores,
|
||||
value_getter=lambda s: s.narrative_points.get(objective_id, 0),
|
||||
)
|
||||
ties: List[TieContext] = []
|
||||
for _, group, _ in ranking:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue