From 08c5a42772f65a197e6fcab2614c4cf64d882c69 Mon Sep 17 00:00:00 2001 From: Sergei Date: Tue, 14 Nov 2023 18:42:46 +0500 Subject: [PATCH] Split multi day result formatting, type comments --- languages/ru_RU/LC_MESSAGES/sportorg.po | 3 ++ sportorg/models/memory.py | 42 +++++++++++++------ sportorg/models/result/result_calculation.py | 2 +- ...\202\320\260\321\202\320\276\320\262.html" | 4 -- 4 files changed, 33 insertions(+), 18 deletions(-) diff --git a/languages/ru_RU/LC_MESSAGES/sportorg.po b/languages/ru_RU/LC_MESSAGES/sportorg.po index 56398bad..1d830def 100644 --- a/languages/ru_RU/LC_MESSAGES/sportorg.po +++ b/languages/ru_RU/LC_MESSAGES/sportorg.po @@ -1565,3 +1565,6 @@ msgstr "Файл разблокирован" msgid "Cannot open file, already locked" msgstr "Ошибка открытия файла. Файл уже открыт в другом окне\"" + +msgid "Multi day race" +msgstr "Многодневная гонка" diff --git a/sportorg/models/memory.py b/sportorg/models/memory.py index 8e81d11d..c7e20cee 100644 --- a/sportorg/models/memory.py +++ b/sportorg/models/memory.py @@ -6,6 +6,7 @@ from abc import abstractmethod from datetime import date from enum import Enum, IntEnum +from typing import Dict from typing import Optional import dateutil.parser @@ -431,6 +432,19 @@ def update_data(self, data): self.days = int(data['days']) +def format_result(result, length): + # Format result string, appending with spaces to have specified length + # used in multi day result string filling + # e.g. 12:00:12, 14 -> '12:00:12 ' + ret = '' + if result is not None: + if result.is_status_ok(): + ret = result.get_result_otime_current_day().to_str() + else: + ret = result.status_comment + return (ret + ' ' * length)[0:length] + + class Result: def __init__(self): if type(self) == Result: @@ -565,7 +579,7 @@ def to_dict(self): if self.final_result_time else None, 'order': self.order, - 'multi_day_results': self.get_multi_day_dict(), + 'multi_day_results': self.get_multi_day_result_str(), } def update_data(self, data): @@ -850,27 +864,30 @@ def check_who_can_win(self): self.can_win_count = who_can_win_count self.final_result_time = max_unfinished_start_time + self.get_result_otime() - def get_multi_day_dict(self): + def get_multi_day_result_str(self): + # get + ret = '' + for cur_res in self.get_multi_days(): + ret += format_result(cur_res, 14) + return ret + + def get_multi_days(self): # Type = List[Result] """ Get list of multi day results, None if group type not Multi Day Returns: - str: + List[Result]: """ + ret = [] if ( self.person and self.person.group and self.person.group.get_type() == RaceType.MULTI_DAY_RACE ): - ret = '' person_id = self.person.multi_day_id for day in races(): cur_res: Result = day.find_result_by_person_id(person_id) - text = '' - if cur_res.is_status_ok(): - text = cur_res.get_result_otime_current_day().to_str() - ret += (text + ' ')[0:14] - return ret - return '' + ret.append(cur_res) + return ret class ResultManual(Result): @@ -1393,7 +1410,7 @@ def __init__(self): self.relay_teams = [] # type: List[RelayTeam] self.settings = {} # type: Dict[str, Any] self.controls = [] # type: List[ControlPoint] - self.result_index = None + self.result_index = {} # type: Dict[str, Result] def __repr__(self): return repr(self.data) @@ -1844,8 +1861,7 @@ def get_duplicate_names(self): return ret def find_result_by_person_id(self, person_id) -> Optional[Result]: - if self.result_index is None: - self.result_index = {} + if len(self.result_index) < 1: for res in self.results: if res.person: id = res.person.multi_day_id diff --git a/sportorg/models/result/result_calculation.py b/sportorg/models/result/result_calculation.py index 60425d5a..acc6f961 100644 --- a/sportorg/models/result/result_calculation.py +++ b/sportorg/models/result/result_calculation.py @@ -20,7 +20,7 @@ def __init__(self, r): def process_results(self): logging.debug('Process results') self.race.relay_teams.clear() - self.race.result_index = None + self.race.result_index = {} for person in self.race.persons: person.result_count = 0 if person.start_time and person.group: diff --git "a/templates/reports/1_\320\277\321\200\320\276\321\202\320\276\320\272\320\276\320\273_\321\200\320\265\320\267\321\203\320\273\321\214\321\202\320\260\321\202\320\276\320\262.html" "b/templates/reports/1_\320\277\321\200\320\276\321\202\320\276\320\272\320\276\320\273_\321\200\320\265\320\267\321\203\320\273\321\214\321\202\320\260\321\202\320\276\320\262.html" index c0cb393a..04718e40 100644 --- "a/templates/reports/1_\320\277\321\200\320\276\321\202\320\276\320\272\320\276\320\273_\321\200\320\265\320\267\321\203\320\273\321\214\321\202\320\260\321\202\320\276\320\262.html" +++ "b/templates/reports/1_\320\277\321\200\320\276\321\202\320\276\320\272\320\276\320\273_\321\200\320\265\320\267\321\203\320\273\321\214\321\202\320\260\321\202\320\276\320\262.html" @@ -72,8 +72,6 @@

ПРОТОКОЛ РЕЗУЛЬТАТОВ

r.speed = ''; r.speed_kmh = ''; r.scores = ''; - //r.penalty_time = ''; - //r.penalty_laps = ''; } // SPLITS @@ -243,8 +241,6 @@

ПРОТОКОЛ РЕЗУЛЬТАТОВ

r.speed = ''; r.speed_kmh = ''; r.scores = ''; - //r.penalty_time = ''; - //r.penalty_laps = ''; } // SPLITS