Skip to content

Commit

Permalink
ardf
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Marchenko authored and daxartio committed Jul 6, 2024
1 parent 1398292 commit ec8d804
Show file tree
Hide file tree
Showing 12 changed files with 534 additions and 22 deletions.
52 changes: 52 additions & 0 deletions configs/ranking_ardf.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
1000;160;180;200;;;;140;120
950;158;178;198;;;;138;118
900;156;176;196;;;;136;116
850;154;174;194;;;;134;114
800;152;172;192;;;;132;112
750;150;170;190;210;;;130;110
700;148;168;188;208;;;128;108
650;146;166;186;206;;;126;106
600;144;164;184;204;;;124;104
550;142;162;182;202;;;122;102
500;140;160;180;200;;;120;100
475;138;158;178;198;;;118;
450;136;156;176;196;;;116;
425;134;154;174;194;;;114;
400;132;152;172;192;;;112;
375;130;150;170;190;210;;110;
350;128;148;168;188;208;;108;
325;126;146;166;186;206;;106;
300;124;144;164;184;204;;104;
275;122;142;162;182;202;;102;
250;120;140;160;180;200;;100;
237;118;138;158;178;198;;;
224;116;136;156;176;196;;;
211;114;134;154;174;194;;;
198;112;132;152;172;192;;;
185;110;130;150;170;190;210;;
172;108;128;148;168;188;208;;
159;106;126;146;166;186;206;;
146;104;124;144;164;184;204;;
133;102;122;142;162;182;202;;
120;100;120;140;160;180;200;;
114;;118;138;158;178;198;;
108;;116;136;156;176;196;;
102;;114;134;154;174;194;;
96;;112;132;152;172;192;;
90;;110;130;150;170;190;;
84;;108;128;148;168;188;;
78;;106;126;146;166;186;;
72;;104;124;144;164;184;;
66;;102;122;142;162;182;;
60;;100;120;140;160;180;;
54;;;118;138;158;178;;
48;;;116;136;156;176;;
42;;;114;134;154;174;;
36;;;112;132;152;172;;
30;;;110;130;150;170;;
27;;;108;128;148;168;;
24;;;106;126;146;166;;
21;;;;;144;164;;
18;;;;;142;162;;
15;;;;;;160;;
12;;;;;;158;;
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 @@ -639,6 +639,9 @@ msgstr "по времени"
msgid "by scores"
msgstr "по баллам"

msgid "ardf"
msgstr "ADRF"

msgid "rogain scores"
msgstr "рогейн (45КП = 4балла, 78КП = 7баллов)"

Expand Down
8 changes: 7 additions & 1 deletion sportorg/gui/dialogs/timekeeping_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ def init_ui(self):
self.result_proc_layout = QFormLayout()
self.rp_time_radio = QRadioButton(translate('by time'))
self.result_proc_layout.addRow(self.rp_time_radio)
self.rp_ardf_radio = QRadioButton(translate('ardf'))
self.result_proc_layout.addRow(self.rp_ardf_radio)
self.rp_scores_radio = QRadioButton(translate('by scores'))
self.result_proc_layout.addRow(self.rp_scores_radio)

Expand Down Expand Up @@ -459,6 +461,8 @@ def set_values_from_model(self):

if rp_mode == 'time':
self.rp_time_radio.setChecked(True)
elif rp_mode == 'ardf':
self.rp_ardf_radio.setChecked(True)
else:
self.rp_scores_radio.setChecked(True)

Expand Down Expand Up @@ -615,7 +619,9 @@ def apply_changes_impl(self):

# result processing
rp_mode = 'time'
if self.rp_scores_radio.isChecked():
if self.rp_ardf_radio.isChecked():
rp_mode = 'ardf'
elif self.rp_scores_radio.isChecked():
rp_mode = 'scores'

rp_score_mode = 'rogain'
Expand Down
44 changes: 41 additions & 3 deletions sportorg/models/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ def __init__(self):
self.place = 0
self.scores = 0
self.scores_rogain = 0
self.scores_ardf = 0
self.assigned_rank = Qualification.NOT_QUALIFIED
self.diff: Optional[OTime] = None # readonly
self.diff_scores = 0 # readonly
Expand Down Expand Up @@ -504,6 +505,14 @@ def __eq__(self, other) -> bool:
eq = eq and self.get_finish_time() == other.get_finish_time()
else:
return False
elif race().get_setting('result_processing_mode', 'time') == 'ardf':
eq = eq and self.scores_ardf == other.scores_ardf
if eq and self.get_start_time() and other.get_start_time():
eq = eq and self.get_start_time() == other.get_start_time()
if eq and self.get_finish_time() and other.get_finish_time():
eq = eq and self.get_finish_time() == other.get_finish_time()
else:
return False
else: # process by score (rogain)
eq = eq and self.scores_rogain == other.scores_rogain
if eq and self.get_start_time() and other.get_start_time():
Expand Down Expand Up @@ -533,6 +542,11 @@ def __gt__(self, other) -> bool: # greater is worse
):
return False
return self.get_result_otime() > other.get_result_otime()
elif race().get_setting('result_processing_mode', 'time') == 'ardf':
if self.scores_ardf == other.scores_ardf:
return self.get_result_otime() > other.get_result_otime()
else:
return self.scores_ardf < other.scores_ardf
else: # process by score (rogain)
if self.scores_rogain == other.scores_rogain:
return self.get_result_otime() > other.get_result_otime()
Expand Down Expand Up @@ -568,6 +582,7 @@ def to_dict(self):
'speed': self.speed, # readonly
'scores': self.scores, # readonly
'scores_rogain': self.scores_rogain, # readonly
'scores_ardf': self.scores_ardf, # readonly
'created_at': self.created_at, # readonly
'result': self.get_result(), # readonly
'result_relay': self.get_result_relay(),
Expand All @@ -593,6 +608,8 @@ def update_data(self, data):
self.status = ResultStatus(int(data['status']))
self.penalty_laps = int(data['penalty_laps'])
self.scores = data['scores']
if 'scores_ardf' in data and data['scores_ardf'] is not None:
self.scores_ardf = data['scores_ardf']
if 'scores_rogain' in data and data['scores_rogain'] is not None:
self.scores_rogain = data['scores_rogain']
if str(data['place']).isdigit():
Expand Down Expand Up @@ -645,7 +662,9 @@ def get_result(self) -> str:
return ''

ret = ''
if race().get_setting('result_processing_mode', 'time') == 'scores':
if race().get_setting('result_processing_mode', 'time') == 'ardf':
ret += f"{self.scores_ardf} {translate('points')} "
elif race().get_setting('result_processing_mode', 'time') == 'scores':
ret += f"{self.scores_rogain} {translate('points')} "

time_accuracy = race().get_setting('time_accuracy', 0)
Expand All @@ -662,7 +681,9 @@ def get_result_start_in_comment(self):
return ''

ret = ''
if race().get_setting('result_processing_mode', 'time') == 'scores':
if race().get_setting('result_processing_mode', 'time') == 'ardf':
ret += f"{self.scores_ardf} {translate('points')} "
elif race().get_setting('result_processing_mode', 'time') == 'scores':
ret += f"{self.scores_rogain} {translate('points')} "

# time_accuracy = race().get_setting('time_accuracy', 0)
Expand Down Expand Up @@ -696,7 +717,9 @@ def get_result_relay(self) -> str:
cur_bib -= 1000

ret = ''
if race().get_setting('result_processing_mode', 'time') == 'scores':
if race().get_setting('result_processing_mode', 'time') == 'ardf':
ret += f"{self.scores_ardf} {translate('points')} "
elif race().get_setting('result_processing_mode', 'time') == 'scores':
ret += f"{self.scores_rogain} {translate('points')} "

time_accuracy = race().get_setting('time_accuracy', 0)
Expand Down Expand Up @@ -1047,6 +1070,8 @@ def check(self, course=None):
'ignore_punches_before_start', False
)

optional_controls_taken = set()

for i in range(len(self.splits)):
try:
split = self.splits[i]
Expand Down Expand Up @@ -1118,6 +1143,19 @@ def check(self, course=None):
split.course_index = course_index
course_index += 1

elif template.find('?') > -1:
# optional control '?' or '?(31,32,33)' or '31?'
if cur_code in optional_controls_taken:
continue

if not list_exists or list_contains:
# any control '?' or '?(31,32,33)' or '31?'
split.is_correct = True
split.has_penalty = False
recognized_indexes.append(i)
optional_controls_taken.add(cur_code)
split.course_index = course_index

else:
# simple pre-ordered control '31 989' or '31(31,32,33) 989'
if list_exists:
Expand Down
1 change: 1 addition & 0 deletions sportorg/models/result/result_calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def set_rank(self, group):
if rank > 0:
is_score_processing_mode = (
self.race.get_setting('result_processing_mode', 'time') == 'scores'
or self.race.get_setting('result_processing_mode', 'time') == 'ardf'
)
leader_time = OTime(0)
leader_scores = 0
Expand Down
65 changes: 64 additions & 1 deletion sportorg/models/result/result_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ def check_result(self, result: ResultSportident):
if self.person.group is None:
return True

if race().get_setting('result_processing_mode', 'time') == 'scores':
if race().get_setting('result_processing_mode', 'time') == 'ardf':
result.scores_ardf = self.calculate_scores_ardf(result)
return True
elif race().get_setting('result_processing_mode', 'time') == 'scores':
# process by score (rogain)
result.scores_rogain = self.calculate_scores_rogain(result)
return True
Expand Down Expand Up @@ -73,6 +76,8 @@ def checking(cls, result):
if result.get_result_otime() > result.person.group.max_time:
if race().get_setting('result_processing_mode', 'time') == 'time':
result.status = ResultStatus.OVERTIME
elif race().get_setting('result_processing_mode', 'time') == 'ardf':
result.status = ResultStatus.OVERTIME

result.status_comment = StatusComments().get_status_default_comment(
result.status
Expand Down Expand Up @@ -354,3 +359,61 @@ def calculate_scores_rogain(result):
if ret < 0:
ret = 0
return ret

@staticmethod
def calculate_scores_ardf(result):
user_array = []
ret = 0

course = race().find_course(result)
if not course:
return ret

correct_order = [str(control.code) for control in course.controls]

index_in_order = 0

for cur_split in result.splits:
code = str(cur_split.code)

initial_index = index_in_order

while index_in_order < len(correct_order):
current_cp = correct_order[index_in_order]

if '?' in current_cp:
if '(' in current_cp and ')' in current_cp:
options = current_cp.strip('?()').split(',')
if code in options and code not in user_array:
user_array.append(code)
ret += 1
index_in_order = initial_index + 1
break
else:
if code not in user_array:
user_array.append(code)
ret += 1
index_in_order = initial_index + 1
break

index_in_order += 1
continue

if code == current_cp:
if code not in user_array:
user_array.append(code)
ret += 1
index_in_order += 1
break

index_in_order = initial_index
break

if result.person and result.person.group:
user_time = result.get_result_otime()
max_time = result.person.group.max_time
if OTime() < max_time < user_time:
result.status = ResultStatus.DISQUALIFIED
return 0

return ret
3 changes: 3 additions & 0 deletions sportorg/modules/live/orgeo.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ def _get_person_obj(data, race_data, result=None):
result['result_msec'] / 10
) # 1/100 sec - proprietary format

if race_data['settings']['result_processing_mode'] == 'ardf':
obj['score'] = result['scores_ardf']

obj['result_status'] = (
RESULT_STATUS[int(result['status'])]
if -1 < int(result['status']) < len(RESULT_STATUS)
Expand Down
23 changes: 17 additions & 6 deletions templates/reports/1_протокол_результатов.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ <h2>ПРОТОКОЛ РЕЗУЛЬТАТОВ</h2>
year: result.person.birth_date ? (new Date(result.person.birth_date)).getFullYear() : '',
penalty_time: toHHMMSS(result.penalty_time),
penalty_laps: result.penalty_laps,
scores_ardf: result.scores_ardf,
result: result.result_current,
result_relay: result.result_relay,
result_msec: result.result_msec,
diff: race.settings.result_processing_mode === 'scores' ? result.diff_scores : toHHMMSS(result.diff),
diff: race.settings.result_processing_mode === 'scores' || race.settings.result_processing_mode === 'ardf' ? result.diff_scores : toHHMMSS(result.diff),
place: result.place,
status: result.status,
scores: result.scores,
Expand Down Expand Up @@ -163,7 +164,7 @@ <h2>ПРОТОКОЛ РЕЗУЛЬТАТОВ</h2>
return -1
}
if (a.is_out_of_competition || b.is_out_of_competition) {
if (race.settings.result_processing_mode === 'scores' && a.scores !== b.scores) {
if ((race.settings.result_processing_mode === 'scores' || race.settings.result_processing_mode === 'ardf') && a.scores !== b.scores) {
return a.scores - b.scores;
}
return a.result_msec - b.result_msec;
Expand Down Expand Up @@ -222,9 +223,10 @@ <h2>ПРОТОКОЛ РЕЗУЛЬТАТОВ</h2>
year: result.person.birth_date ? (new Date(result.person.birth_date)).getFullYear() : '',
penalty_time: toHHMMSS(result.penalty_time),
penalty_laps: result.penalty_laps,
scores_ardf: result.scores_ardf,
result: result.result,
result_msec: result.result_msec,
diff: race.settings.result_processing_mode === 'scores' ? result.diff_scores : toHHMMSS(result.diff),
diff: race.settings.result_processing_mode === 'scores' || race.settings.result_processing_mode === 'ardf' ? result.diff_scores : toHHMMSS(result.diff),
place: result.place,
status: result.status,
scores: result.scores,
Expand Down Expand Up @@ -307,7 +309,7 @@ <h2>ПРОТОКОЛ РЕЗУЛЬТАТОВ</h2>
return -1
}
if (a.is_out_of_competition || b.is_out_of_competition) {
if (race.settings.result_processing_mode === 'scores' && a.scores !== b.scores) {
if ((race.settings.result_processing_mode === 'scores' || race.settings.result_processing_mode === 'ardf') && a.scores !== b.scores) {
return a.scores - b.scores;
}
return a.result_msec - b.result_msec;
Expand Down Expand Up @@ -378,7 +380,7 @@ <h2>ПРОТОКОЛ РЕЗУЛЬТАТОВ</h2>
} else {
doubleplace++;
}
elem.diff = race.settings.result_processing_mode === 'scores' ? elem.diff_scores : toHHMMSS(elem.result_msec - best_result_msec);
elem.diff = race.settings.result_processing_mode === 'scores' || race.settings.result_processing_mode === 'ardf' ? elem.diff_scores : toHHMMSS(elem.result_msec - best_result_msec);
elem.place = newplace;
elem.place_show = newplace;
}
Expand Down Expand Up @@ -482,9 +484,10 @@ <h2>ПРОТОКОЛ РЕЗУЛЬТАТОВ</h2>
{key: 'bib', title: 'Номер', size: 6},
{key: 'penalty_time', title: 'Штраф', size: 9, active: false},
{key: 'penalty_laps', title: 'Штраф', size: 9, active: false},
{key: 'scores_ardf', title: 'КП', size: 3, active: race.settings.result_processing_mode === 'ardf'},
{key: 'result', title: 'Результат', size: 17},
{key: 'result_relay', title: 'Ком. рез-т', size: 14},
{key: 'diff', title: 'Отставание', size: 11},
{key: 'diff', title: 'Отставание', size: 11, active: race.settings.result_processing_mode !== 'ardf'},
{key: 'speed', title: 'Темп', size: 8, active: false},
{key: 'speed_kmh', title: 'Скорость', size: 8, active: false},
{key: 'place_show', title: 'Место', size: 6},
Expand Down Expand Up @@ -723,6 +726,14 @@ <h2>ПРОТОКОЛ РЕЗУЛЬТАТОВ</h2>
render()
}
},
{
title: 'КП',
value: Fields.isActive('scores_ardf'),
change: function (checked) {
Fields.active('scores_ardf', checked);
render()
}
},
{
title: 'Отставание',
value: Fields.isActive('diff'),
Expand Down
Loading

0 comments on commit ec8d804

Please sign in to comment.