From 40c8ebad039d073a8e6c2fc8525c981f1787b04f Mon Sep 17 00:00:00 2001
From: Martin Mares <mj@ucw.cz>
Date: Mon, 1 Mar 2021 12:27:52 +0100
Subject: [PATCH] =?UTF-8?q?mo.score:=20Ne=C3=BAsp=C4=9B=C5=A1n=C3=AD=20?=
 =?UTF-8?q?=C5=99e=C5=A1itel=C3=A9=20nepot=C5=99ebuj=C3=AD=20jednozna?=
 =?UTF-8?q?=C4=8Dn=C3=A9=20po=C5=99ad=C3=AD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

U neúspěšných řešitelů třídíme primárně podle bodů, sekundárně podle
jména, a jmenovce pak případně podle ročníku.

Také jsem do class Score přidal flagy, zda jsou definovaní vítězové
a úspěšní řešitelé.
---
 mo/score.py | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/mo/score.py b/mo/score.py
index 99f4cb4a..50ec9beb 100644
--- a/mo/score.py
+++ b/mo/score.py
@@ -83,6 +83,8 @@ class Score:
     round: db.Round
     contest: Optional[db.Contest]
     part_states: List[db.PartState]
+    want_successful: bool
+    want_winners: bool
 
     # Řádky výsledkovky
     _results: Dict[int, ScoreResult]
@@ -104,6 +106,8 @@ class Score:
         self.round = round
         self.contest = contest
         self.part_states = part_states
+        self.want_successful = round.score_successful_limit is not None
+        self.want_winners = round.score_winner_limit is not None
 
         # Příprava subquery na účastníky (contest_subq obsahuje master_contest_id)
         sess = db.get_session()
@@ -186,14 +190,8 @@ class Score:
     def _mark_winners(self):
         for result in self._results.values():
             total_points = result.get_total_points()
-            result.winner = (
-                self.round.score_winner_limit is not None
-                and total_points >= self.round.score_winner_limit
-            )
-            result.successful = (
-                self.round.score_successful_limit is not None
-                and total_points >= self.round.score_successful_limit
-            )
+            result.winner = self.want_winners and total_points >= self.round.score_winner_limit
+            result.successful = self.want_successful and total_points >= self.round.score_successful_limit
 
     def _load_prev_round(self, step: int) -> bool:
         """Načtení úloh a řešení předchozího kola, pokud takové existuje."""
@@ -337,8 +335,12 @@ class Score:
                 points_from_max = list(sorted(sol_points.values()))
                 points_from_difficult = [sol_points[task_id] for task_id in tasks_by_difficulty]
 
-                # Primárně podle počtu získaných bodů, sekundárně podle bodů od maxima, terciárně podle bodů od nejobtížnější
-                result._order_key.extend((total_points, points_from_max, points_from_difficult))
+                if result.successful or not self.want_successful:
+                    # Primárně podle počtu získaných bodů, sekundárně podle bodů od maxima, terciárně podle bodů od nejobtížnější
+                    result._order_key.extend((total_points, points_from_max, points_from_difficult))
+                else:
+                    # Neúspěšné řešitele třídíme podle počtu získaných bodů, sekundárně podle jména
+                    result._order_key.extend((total_points, result.user.name_sort_key()))
 
             # Otestujeme, jestli teď existují sdílená místa
             if not self._exists_same_order_key():
-- 
GitLab