Skip to content

Commit

Permalink
Split multi day result formatting, type comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeikobelev committed Nov 14, 2023
1 parent 2c61838 commit 08c5a42
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.
3 changes: 3 additions & 0 deletions languages/ru_RU/LC_MESSAGES/sportorg.po
Original file line number Diff line number Diff line change
Expand Up @@ -1565,3 +1565,6 @@ msgstr "Файл разблокирован"

msgid "Cannot open file, already locked"
msgstr "Ошибка открытия файла. Файл уже открыт в другом окне\""

msgid "Multi day race"
msgstr "Многодневная гонка"
42 changes: 29 additions & 13 deletions sportorg/models/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sportorg/models/result/result_calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ <h2>ПРОТОКОЛ РЕЗУЛЬТАТОВ</h2>
r.speed = '';
r.speed_kmh = '';
r.scores = '';
//r.penalty_time = '';
//r.penalty_laps = '';
}

// SPLITS
Expand Down Expand Up @@ -243,8 +241,6 @@ <h2>ПРОТОКОЛ РЕЗУЛЬТАТОВ</h2>
r.speed = '';
r.speed_kmh = '';
r.scores = '';
//r.penalty_time = '';
//r.penalty_laps = '';
}

// SPLITS
Expand Down

0 comments on commit 08c5a42

Please sign in to comment.