fix display campaign NP draw/break in participant table

This commit is contained in:
Maxime Réaux 2026-03-05 11:37:14 +01:00
parent 03f0e048af
commit b1bde76319
3 changed files with 22 additions and 35 deletions

View file

@ -91,28 +91,25 @@ class TieResolver:
campaign_id: str,
objective_id: str,
) -> List[TieContext]:
base_scores = ScoreService.compute_scores(
scores = ScoreService.compute_scores(
war,
ContextType.CAMPAIGN,
campaign_id,
)
scores = TieResolver._build_objective_scores(
base_scores,
objective_id,
)
buckets: DefaultDict[int, List[str]] = defaultdict(list)
for pid, score in scores.items():
buckets[score.victory_points].append(pid)
np_value = score.narrative_points.get(objective_id, 0)
buckets[np_value].append(pid)
ties: List[TieContext] = []
context_id = f"{campaign_id}:{objective_id}"
for score_value, participants in buckets.items():
for np_value, participants in buckets.items():
if len(participants) <= 1:
continue
if TieResolver.is_tie_resolved(
war,
ContextType.OBJECTIVE,
context_id,
score_value,
np_value,
):
continue
if not TieResolver.can_tie_be_resolved(
@ -126,7 +123,7 @@ class TieResolver:
None,
ContextType.OBJECTIVE,
context_id,
score_value,
np_value,
)
)
continue
@ -135,7 +132,7 @@ class TieResolver:
context_type=ContextType.OBJECTIVE,
context_id=context_id,
participants=participants,
score_value=score_value,
score_value=np_value,
)
)
return ties
@ -181,33 +178,33 @@ class TieResolver:
) -> List[TieContext]:
from warchron.model.result_checker import ResultChecker
base_scores = ScoreService.compute_scores(
scores = ScoreService.compute_scores(
war,
ContextType.WAR,
war.id,
)
scores = TieResolver._build_objective_scores(
base_scores,
objective_id,
)
def value_getter(score: ParticipantScore) -> int:
return score.narrative_points.get(objective_id, 0)
ranking = ResultChecker.get_effective_ranking(
war,
ContextType.OBJECTIVE,
f"{war.id}:{objective_id}",
scores,
value_getter=lambda s: s.narrative_points.get(objective_id, 0),
value_getter=value_getter,
)
ties: List[TieContext] = []
for _, group, _ in ranking:
if len(group) <= 1:
continue
score_value = scores[group[0]].victory_points
np_value = value_getter(scores[group[0]])
context_id = f"{war.id}:{objective_id}"
if TieResolver.is_tie_resolved(
war,
ContextType.OBJECTIVE,
context_id,
score_value,
np_value,
):
continue
if not TieResolver.can_tie_be_resolved(
@ -221,7 +218,7 @@ class TieResolver:
None,
ContextType.OBJECTIVE,
context_id,
score_value,
np_value,
)
)
continue
@ -230,24 +227,11 @@ class TieResolver:
context_type=ContextType.OBJECTIVE,
context_id=context_id,
participants=group,
score_value=score_value,
score_value=np_value,
)
)
return ties
@staticmethod
def _build_objective_scores(
base_scores: Dict[str, ParticipantScore],
objective_id: str,
) -> Dict[str, ParticipantScore]:
return {
pid: ParticipantScore(
victory_points=score.narrative_points.get(objective_id, 0),
narrative_points={},
)
for pid, score in base_scores.items()
}
@staticmethod
def apply_bids(
war: War,
@ -269,6 +253,7 @@ class TieResolver:
)
)
# FIXME lost tokens used for narrative tie-break (ContextType.OBJECTIVE)
@staticmethod
def cancel_tie_break(
war: War,