Skip to content

Commit

Permalink
test: result checking
Browse files Browse the repository at this point in the history
  • Loading branch information
sembruk committed Dec 5, 2024
1 parent 60fedf4 commit 1e0dbfa
Show file tree
Hide file tree
Showing 3 changed files with 674 additions and 29 deletions.
15 changes: 9 additions & 6 deletions sportorg/models/result/result_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ def check_result(self, result):

if race().get_setting('result_processing_mode', 'time') == 'scores':
result.check(course)
result.scores, result.penalty_points = self.calculate_scores_rogaining(result)
scores = self.calculate_rogaine_scores(result)
result.penalty_points = self.calculate_rogaine_penalty(result, result.scores)
result.scores = scores - result.penalty_points
return True

if race().get_setting('marked_route_dont_dsq', False):
Expand Down Expand Up @@ -230,7 +232,7 @@ def get_control_score(code):
return int(code)//10 # score = code / 10

@staticmethod
def calculate_scores_rogaining(result):
def calculate_rogaine_scores(result):
user_array = []
points = 0
for cur_split in result.splits:
Expand All @@ -239,6 +241,10 @@ def calculate_scores_rogaining(result):
if code not in user_array:
user_array.append(code)
points += ResultChecker.get_control_score(code)
return points

@staticmethod
def calculate_rogaine_penalty(result, score):
penalty_points = 0
if result.person and result.person.group:
user_time = result.get_result_otime()
Expand All @@ -249,9 +255,6 @@ def calculate_scores_rogaining(result):
minutes_diff = (seconds_diff + 59) // 60 # note, 1:01 = 2 minutes
penalty_step = race().get_setting('result_processing_scores_minute_penalty', 1.0)
penalty_points = minutes_diff*penalty_step
points -= penalty_points
if points < 0:
points = 0
return points, penalty_points
return min(penalty_points, score)


24 changes: 1 addition & 23 deletions tests/test_penalty_checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,6 @@ def test_basic_syntax():
assert ok(course=[31, '41', '51(51,52)'], splits=[31, 41, 52], penalty=1)
assert dsq(course=[31, '41', '51(51,52)'], splits=[31, 41, 59], penalty=0)

race().set_setting('marked_route_mode', 'off')
race().set_setting('result_processing_mode', 'scores')
race().set_setting('marked_route_dont_dsq', True)
race().set_setting('result_processing_score_mode', 'fixed')
assert ok(course=[31, '*', '*', '*'], splits=[31, 41, 51], penalty=0, scores=3)
race().set_setting('result_processing_score_mode', 'rogain')
assert ok(course=['*[]'], splits=[31, 41, 51], penalty=0, scores=12)
assert ok(course=[31, '*[]'], splits=[32, 31, 51], penalty=0, scores=8)


def test_marked_route_yes_no():
"""Тест маркированной трассы по варианту ДА/НЕТ.
Expand Down Expand Up @@ -313,7 +304,6 @@ def check(
splits: List[int],
result_status: ResultStatus = ResultStatus.OK,
penalty: int = 0,
scores: int = 0,
) -> Tuple[bool, bool]:
"""Проверка отметки с начислением штрафа. Параметры проверки задаются
заранее и хранятся в объекте race().get_settings().
Expand Down Expand Up @@ -342,7 +332,7 @@ def check(
ResultChecker.checking(result)
result_penalty = get_penalty(result)

check_result = result.status == result_status, result_penalty == penalty, result.scores == scores
check_result = result.status == result_status, result_penalty == penalty

if not all(check_result):
message = exception_message(
Expand All @@ -352,8 +342,6 @@ def check(
result_status_received=result.status,
penalty_expected=penalty,
penalty_received=result_penalty,
scores_expected=scores,
scores_received=result.scores,
)
raise ValueError(message)

Expand Down Expand Up @@ -412,8 +400,6 @@ def exception_message(
result_status_received: ResultStatus,
penalty_expected: int,
penalty_received: int,
scores_expected = int,
scores_received = int,
) -> str:
"""Формирование отладочного сообщения при создании исключения. Отладочное
сообщение содержит сравнение дистанции и отметок и причину несоответствия.
Expand All @@ -432,10 +418,6 @@ def exception_message(
Ожидаемое количество штрафа.
penalty_received : int
Полученное количество штрафа.
scores_expected : int
Ожидаемое количество баллов.
scores_received : int
Полученное количество баллов.
Returns
-------
Expand All @@ -452,10 +434,6 @@ def exception_message(
message += '\n' + f'Penalty failed!'
message += '\n' + f'Expected: {penalty_expected}'
message += '\n' + f'Received: {penalty_received}'
if scores_expected != scores_received:
message += '\n' + f'Scores failed!'
message += '\n' + f'Expected: {scores_expected}'
message += '\n' + f'Received: {scores_received}'
return message


Expand Down
Loading

0 comments on commit 1e0dbfa

Please sign in to comment.