Skip to content

Commit

Permalink
feat: new features for a marked track with penalty loops (sportorg#421)
Browse files Browse the repository at this point in the history
Co-authored-by: Aleksandr Karpov <[email protected]>
  • Loading branch information
alex-karpov and Aleksandr Karpov committed Dec 27, 2023
1 parent 8c1e1f8 commit 050b6bd
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 31 deletions.
32 changes: 16 additions & 16 deletions languages/ru_RU/LC_MESSAGES/sportorg.po
Original file line number Diff line number Diff line change
Expand Up @@ -669,26 +669,26 @@ msgstr "Режим начисления штрафа: штрафные круг
msgid "counting lap"
msgstr "оценочный круг"

msgid "Operating mode: evaluation point"
msgstr "Режим работы: оценочный круг"

msgid "Print number of penalty laps instead of splits"
msgstr "При считывании печатается распечатка"

msgid "when competitor reads out his card"
msgstr "с количеством штрафных кругов"
msgid ""
"Operating mode: evaluation point\n"
"Print the number of penalty laps instead of splits\n"
"when a competitor reads out his card"
msgstr ""
"Режим работы: оценочный круг\n"
"При считывании печатать распечатку\n"
"с количеством штрафных кругов"

msgid "lap station"
msgstr "станция на штрафном круге"

msgid "Station number on the penalty lap"
msgstr "Номер станции на штрафном круге"

msgid "Competitor must punch at station"
msgstr "Спортсмен должен отметиться на станции"

msgid "every time he/she passes a penalty lap"
msgstr "при каждом прохождении штрафного круга"
msgid ""
"Station number on the penalty lap\n"
"A competitor must punch at the station\n"
"each time they pass the penalty lap"
msgstr ""
"Номер станции на штрафном круге\n"
"Спортсмен должен отметиться на станции\n"
"при каждом прохождении штрафного круга"

msgid "scores off"
msgstr "очки не рассчитываются"
Expand Down
20 changes: 18 additions & 2 deletions sportorg/gui/dialogs/timekeeping_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,24 @@ def init_ui(self):
self.mr_laps_radio.toggled.connect(self.penalty_calculation_mode)
self.mr_layout.addRow(self.mr_laps_radio)
self.mr_counting_lap_check = QCheckBox(translate('counting lap'))
self.mr_counting_lap_check.setToolTip(
translate(
'Operating mode: evaluation point\n'
'Print the number of penalty laps instead of splits\n'
'when a competitor reads out his card'
)
)
self.mr_counting_lap_check.stateChanged.connect(self.penalty_calculation_mode)
self.mr_layout.addRow(self.mr_counting_lap_check)
self.mr_lap_station_check = QCheckBox(translate('lap station'))
self.mr_lap_station_check.setToolTip(
translate(
'Station number on the penalty lap\n'
'A competitor must punch at the station\n'
'each time they pass the penalty lap'
)
)
self.mr_lap_station_check.stateChanged.connect(self.penalty_calculation_mode)
self.mr_lap_station_edit = AdvSpinBox(max_width=50)
self.mr_layout.addRow(self.mr_lap_station_check, self.mr_lap_station_edit)
self.mr_dont_dqs_check = QCheckBox(translate("Don't disqualify"))
Expand Down Expand Up @@ -457,7 +473,7 @@ def set_values_from_model(self):
)
mr_if_counting_lap = obj.get_setting('marked_route_if_counting_lap', False)
mr_if_station_check = obj.get_setting('marked_route_if_station_check', False)
mr_station_code = obj.get_setting('marked_route_station_code', 80)
mr_station_code = obj.get_setting('marked_route_penalty_lap_station_code', 80)
mr_if_dont_dsq_check = obj.get_setting('marked_route_dont_dsq', False)
mr_if_max_penalty_by_cp = obj.get_setting(
'marked_route_max_penalty_by_cp', False
Expand Down Expand Up @@ -634,7 +650,7 @@ def apply_changes_impl(self):
obj.set_setting('marked_route_penalty_time', mr_penalty_time)
obj.set_setting('marked_route_if_counting_lap', mr_if_counting_lap)
obj.set_setting('marked_route_if_station_check', mr_if_station_check)
obj.set_setting('marked_route_station_code', mr_station_code)
obj.set_setting('marked_route_penalty_lap_station_code', mr_station_code)
obj.set_setting('marked_route_dont_dsq', mr_if_dont_dsq)
obj.set_setting('marked_route_max_penalty_by_cp', mr_if_max_penalty_by_cp)

Expand Down
1 change: 1 addition & 0 deletions sportorg/gui/menu/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ def execute(self):
logging.debug('Penalty calculation start')
for result in race().results:
if result.person:
ResultChecker.checking(result)
ResultChecker.calculate_penalty(result)
ResultChecker.checking(result)
logging.debug('Penalty calculation finish')
Expand Down
17 changes: 7 additions & 10 deletions sportorg/models/result/result_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ def calculate_penalty(result: Result):
controls = course.controls
splits = result.splits

if mode == 'laps' and race().get_setting(
'marked_route_if_penalty_lap_station_check'
):
if mode == 'laps' and race().get_setting('marked_route_if_station_check'):
lap_station = race().get_setting('marked_route_penalty_lap_station_code')
splits, _ = ResultChecker.detach_penalty_laps2(splits, lap_station)

Expand Down Expand Up @@ -176,8 +174,7 @@ def penalty_calculation(splits, controls, check_existence=False):
```
"""

# Walkaround: if i.code != '199' убирает станцию штрафного круга
user_array = [i.code for i in splits if i.code != '199']
user_array = [i.code for i in splits]
origin_array = [i.get_number_code() for i in controls]
res = 0

Expand Down Expand Up @@ -275,9 +272,9 @@ def detach_penalty_laps(splits, lap_station):

@staticmethod
def detach_penalty_laps2(splits, lap_station):
"""Walkaround: извлекает отметки на штрафной станции.
Наивный метод, надо учитывать, что штрафные КП должны относиться
к пункту оценки, а не появляться из неочищенного чипа"""
'''Detaches penalty laps from the given list of splits
based on the provided lap station code.
'''
if not splits:
return [], []
regular = [punch for punch in splits if int(punch.code) != lap_station]
Expand All @@ -289,7 +286,7 @@ def check_penalty_laps(result):
assert isinstance(result, Result)

mode = race().get_setting('marked_route_mode', 'off')
check_laps = race().get_setting('marked_route_if_penalty_lap_station_check')
check_laps = race().get_setting('marked_route_if_station_check')

if mode == 'laps' and check_laps:
lap_station = race().get_setting('marked_route_penalty_lap_station_code')
Expand Down Expand Up @@ -352,7 +349,7 @@ def marked_route_check_penalty_laps(result: Result):

mr_if_counting_lap = obj.get_setting('marked_route_if_counting_lap', False)
mr_if_station_check = obj.get_setting('marked_route_if_station_check', False)
mr_station_code = obj.get_setting('marked_route_station_code', 0)
mr_station_code = obj.get_setting('marked_route_penalty_lap_station_code', 0)

if mr_if_station_check and int(mr_station_code) > 0:
count_laps = 0
Expand Down
2 changes: 1 addition & 1 deletion templates/split/1_split_printout.html
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ <h2>{{ person.surname }} {{ person.name }} - {{ group.name }}</h2>
</table>
<br> Финиш: {{result.finish_msec|tohhmmss}} {{result.speed}}
{% if race['settings'].get('marked_route_mode', 'off') == 'laps' %}
<br> Штраф: {{result.penalty_laps}} круг{{result.penalty_laps|plural}}
<br> Штрафных кругов: {{result.penalty_laps}}
{% elif race['settings'].get('marked_route_mode', 'off') == 'time' %}
<br> Штраф: {{result.penalty_time|tohhmmss}}
{% endif %}
Expand Down
4 changes: 2 additions & 2 deletions tests/test_penalty_checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
# default value: marked_route_if_counting_lap = True
# marked_route_if_station_check [bool] - режим проверки количества пройденных штрафных кругов
# default value: marked_route_if_station_check = False
# marked_route_station_code [int] - номер станции на штрафном круге
# default value: marked_route_station_code = 80
# marked_route_penalty_lap_station_code [int] - номер станции на штрафном круге
# default value: marked_route_penalty_lap_station_code = 80
# marked_route_dont_dsq [bool] - дисквалифицировать ли спортсмена за пропущенные КП
# True - проверяет функцией penalty_calculation_free_order()
# False - проверяет функцией penalty_calculation(<...>, check_existence=True)
Expand Down

0 comments on commit 050b6bd

Please sign in to comment.