Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiday protocols #420

Merged
merged 7 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sportorg/gui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ def create_file(self, *args, update_data=True, is_new=False):
self.set_title()
self.init_model()
except Exception as e:
logging.error(str(e))
logging.exception(e)
QMessageBox.warning(
self,
translate('Error'),
Expand Down
2 changes: 1 addition & 1 deletion sportorg/gui/tabs/memory_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def get_values_from_object(self, result):
rented_card,
time_to_hhmmss(i.get_result_otime_current_day())
if i.is_status_ok()
else '',
else i.get_result(),
]
return ret

Expand Down
56 changes: 43 additions & 13 deletions sportorg/models/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,8 @@ def to_dict(self):
'created_at': self.created_at, # readonly
'result': self.get_result(), # readonly
'result_relay': self.get_result_relay(),
'result_current': self.get_result_otime_current_day().to_str(),
'result_current': self.get_result_otime_current_day().to_str() if self.is_status_ok()
else self.get_result(),
'start_msec': self.get_start_time().to_msec(), # readonly
'finish_msec': self.get_finish_time().to_msec(), # readonly
'result_msec': self.get_result_otime().to_msec(), # readonly
Expand All @@ -563,6 +564,7 @@ def to_dict(self):
if self.final_result_time
else None,
'order': self.order,
'multi_day_results': self.get_multi_day_dict()
}

def update_data(self, data):
Expand Down Expand Up @@ -717,18 +719,14 @@ def get_result_otime_multi_day(self):
person_id = self.person.multi_day_id
sum_result = OTime()
for day in races():
result_found = False
for result in day.results:
assert isinstance(result, Result)
if result.person and result.person.multi_day_id == person_id:
if result.is_status_ok():
sum_result += result.get_result_otime_current_day()
result_found = True
continue
else:
self.status = ResultStatus.DISQUALIFIED
return OTime() # DSQ/DNS
if not result_found:
result_tmp = day.find_result_by_person_id(person_id)
if result_tmp:
if result_tmp.is_status_ok():
sum_result += result_tmp.get_result_otime_current_day()
else:
self.status = ResultStatus.DISQUALIFIED
return OTime() # DSQ/DNS
else:
self.status = ResultStatus.DISQUALIFIED
return OTime() # result not found in that day
return sum_result
Expand Down Expand Up @@ -851,6 +849,24 @@ 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):
daxartio marked this conversation as resolved.
Show resolved Hide resolved
"""
Get list of multi day results, None if group type not Multi Day
Returns:
str:
"""
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 ''


class ResultManual(Result):
system_type = SystemType.MANUAL
Expand Down Expand Up @@ -1372,6 +1388,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
daxartio marked this conversation as resolved.
Show resolved Hide resolved

def __repr__(self):
return repr(self.data)
Expand Down Expand Up @@ -1821,6 +1838,19 @@ def get_duplicate_names(self):
current_name = person.full_name
return ret

def find_result_by_person_id(self, person_id) -> Result:
if self.result_index is None:
self.result_index = {}
for res in self.results:
if res.person:
id = res.person.multi_day_id
self.result_index[id] = res

if person_id in self.result_index:
return self.result_index[person_id]
else:
return None


class Qualification(IntEnum):
NOT_QUALIFIED = 0
Expand Down
3 changes: 3 additions & 0 deletions sportorg/models/result/result_calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def __init__(self, r):
def process_results(self):
logging.debug('Process results')
self.race.relay_teams.clear()
self.race.result_index = None
for person in self.race.persons:
person.result_count = 0
if person.start_time and person.group:
Expand Down Expand Up @@ -93,6 +94,8 @@ def set_places(array):

res.place = last_place
current_place += 1
else:
res.current_result = res.get_result()

def process_relay_results(self, group):
if group and isinstance(group, Group):
Expand Down
15 changes: 8 additions & 7 deletions templates/reports/1_протокол_результатов.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ <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,
result: result.result,
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),
Expand All @@ -72,8 +72,8 @@ <h2>ПРОТОКОЛ РЕЗУЛЬТАТОВ</h2>
r.speed = '';
r.speed_kmh = '';
r.scores = '';
r.penalty_time = '';
r.penalty_laps = '';
//r.penalty_time = '';
daxartio marked this conversation as resolved.
Show resolved Hide resolved
//r.penalty_laps = '';
}

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

// SPLITS
Expand Down Expand Up @@ -534,7 +534,7 @@ <h2>ПРОТОКОЛ РЕЗУЛЬТАТОВ</h2>
this.getField('all_splits').active = location.href.indexOf('all_splits=1') > -1;
this.getField('scores').active = location.href.indexOf('scores=1') > -1;
this.getField('penalty_time').active = location.href.indexOf('penalty_time=1') > -1;

this.getField('penalty_laps').active = location.href.indexOf('penalty_laps=1') > -1;
this.getField('result_relay').active = isRelay
} catch (e){}
return this;
Expand Down Expand Up @@ -620,7 +620,8 @@ <h2>ПРОТОКОЛ РЕЗУЛЬТАТОВ</h2>
by_course: store.showProtocolByCourse ? 1 : 0,
all_splits: Fields.isActive('all_splits') ? 1 : 0,
scores: Fields.isActive('scores') ? 1 : 0,
penalty_time: Fields.isActive('penalty_time') ? 1 : 0
penalty_time: Fields.isActive('penalty_time') ? 1 : 0,
penalty_laps: Fields.isActive('penalty_laps') ? 1 : 0
};
var queryString = '?';
Object.keys(query).forEach(function (key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ <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,
result: result.result,
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),
Expand All @@ -72,8 +72,8 @@ <h2>ПРОТОКОЛ РЕЗУЛЬТАТОВ</h2>
r.speed = '';
r.speed_kmh = '';
r.scores = '';
r.penalty_time = '';
r.penalty_laps = '';
//r.penalty_time = '';
//r.penalty_laps = '';
}

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

// SPLITS
Expand Down Expand Up @@ -534,7 +534,7 @@ <h2>ПРОТОКОЛ РЕЗУЛЬТАТОВ</h2>
this.getField('all_splits').active = location.href.indexOf('all_splits=1') > -1;
this.getField('scores').active = location.href.indexOf('scores=1') > -1;
this.getField('penalty_time').active = location.href.indexOf('penalty_time=1') > -1;

this.getField('penalty_laps').active = location.href.indexOf('penalty_laps=1') > -1;
this.getField('result_relay').active = isRelay
} catch (e){}
return this;
Expand Down Expand Up @@ -625,7 +625,8 @@ <h2>ПРОТОКОЛ РЕЗУЛЬТАТОВ</h2>
by_course: store.showProtocolByCourse ? 1 : 0,
all_splits: Fields.isActive('all_splits') ? 1 : 0,
scores: Fields.isActive('scores') ? 1 : 0,
penalty_time: Fields.isActive('penalty_time') ? 1 : 0
penalty_time: Fields.isActive('penalty_time') ? 1 : 0,
penalty_laps: Fields.isActive('penalty_laps') ? 1 : 0
};
var queryString = '?';
Object.keys(query).forEach(function (key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ <h2>ПРОТОКОЛ РЕЗУЛЬТАТОВ (СУММА ВРЕМЕНИ)</h2>
};
var results = this.race.results.filter(function (result) {
if (result.person && result.person.group && result.person.organization && equal(result.person.organization)) {
return !_this.selected.groups.length || _this.selected.groups.some(function (elem) {
return !_this.selected.groups || !_this.selected.groups.length || _this.selected.groups.some(function (elem) {
return elem.id === result.person.group.id;
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ <h2>ПРОТОКОЛ РЕЗУЛЬТАТОВ</h2>
};
var results = this.race.results.filter(function (result) {
if (result.status === 1 && result.person && !result.person.is_out_of_competition && result.person.group && result.person.organization && equal(result.person.organization, result.person.group)) {
return !_this.selected.groups.length || _this.selected.groups.some(function (elem) {
return !_this.selected.groups || !_this.selected.groups.length || _this.selected.groups.some(function (elem) {
return elem.id === result.person.group.id;
})
}
Expand Down Expand Up @@ -193,9 +193,16 @@ <h2>ПРОТОКОЛ РЕЗУЛЬТАТОВ</h2>
title: 'n: ',
value: [
{text: 'все участники', value: 0},
{text: '1', value: 1},
{text: '2', value: 2},
{text: '3', value: 3},
{text: '4', value: 4},
{text: '5', value: 5},
{text: '6', value: 6},
{text: '7', value: 7},
{text: '8', value: 8},
{text: '9', value: 9},
{text: '10', value: 10},
{text: '101', value: 101}
],
change: function (arr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ <h2>ПРОТОКОЛ РЕЗУЛЬТАТОВ</h2>
};
var results = this.race.results.filter(function (result) {
if (result.status === 1 && result.person && !result.person.is_out_of_competition && result.person.group && result.person.organization && equal(result.person.organization, result.person.group)) {
return !_this.selected.groups.length || _this.selected.groups.some(function (elem) {
return !_this.selected.groups || !_this.selected.groups.length || _this.selected.groups.some(function (elem) {
return elem.id === result.person.group.id;
})
}
Expand Down Expand Up @@ -193,9 +193,13 @@ <h2>ПРОТОКОЛ РЕЗУЛЬТАТОВ</h2>
title: 'n: ',
value: [
{text: 'все участники', value: 0},
{text: '1', value: 1},
{text: '2', value: 2},
{text: '3', value: 3},
{text: '4', value: 4},
{text: '5', value: 5},
{text: '6', value: 6},
{text: '7', value: 7},
{text: '8', value: 8},
{text: '9', value: 9},
{text: '10', value: 10},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ <h2>ПРОТОКОЛ РЕЗУЛЬТАТОВ</h2>
};
var results = this.race.results.filter(function (result) {
if (result.status === 1 && result.person && !result.person.is_out_of_competition && result.person.group && result.person.organization && equal(result.person.organization, result.person.group)) {
return !_this.selected.groups.length || _this.selected.groups.some(function (elem) {
return !_this.selected.groups || !_this.selected.groups.length || _this.selected.groups.some(function (elem) {
return elem.id === result.person.group.id;
})
}
Expand Down Expand Up @@ -188,9 +188,13 @@ <h2>ПРОТОКОЛ РЕЗУЛЬТАТОВ</h2>
title: 'n: ',
value: [
{text: 'все участники', value: 0},
{text: '1', value: 1},
{text: '2', value: 2},
{text: '3', value: 3},
{text: '4', value: 4},
{text: '5', value: 5},
{text: '6', value: 6},
{text: '7', value: 7},
{text: '8', value: 8},
{text: '9', value: 9},
{text: '10', value: 10},
Expand Down
Loading
Loading