def show_person_info(self): bib_or_name = self.item_bib_or_name.text() # type: str self.label_person_info.setText('') person = None if bib_or_name: if bib_or_name.isdigit(): person = memory.find(memory.race().persons, bib=int(bib_or_name)) else: for p in memory.race().persons: if bib_or_name.lower() in p.full_name.lower(): person = p break if person: info = person.full_name if person.group: info = '{}\n{}: {}'.format(info, _('Group'), person.group.name) if person.card_number: info = '{}\n{}: {}'.format(info, _('Card'), person.card_number) self.label_person_info.setText(info) else: self.label_person_info.setText(_('not found')) self.tmp_person = person
def apply_changes_impl(self): status_comment = StatusComments().remove_hint( self.item_status_comment.currentText()) text = self.item_numbers.toPlainText() numbers = [] for item in text.split('\n'): if not len(item): continue for n_item in item.split(): if n_item.isdigit(): numbers.append(int(n_item)) old_numbers = [] obj = race() for number in numbers: if number not in old_numbers: person = find(obj.persons, bib=number) if person: result = race().new_result(ResultManual) result.person = person result.status = ResultStatus.DID_NOT_START result.status_comment = status_comment Teamwork().send(result.to_dict()) obj.add_new_result(result) else: logging.info('{} not found'.format(number)) old_numbers.append(number)
def check_name(self): name = self.item_name.text() self.button_ok.setDisabled(False) if name and name != self.current_object.name: group = find(race().groups, name=name) if group: self.button_ok.setDisabled(True)
def check_name(self): name = self.item_name.text() self.button_ok.setDisabled(False) if name and name != self.current_object.name: org = find(race().organizations, name=name) if org: self.button_ok.setDisabled(True)
def test_import_txt_v8(self): ocad.import_txt_v8('test/CoursesV8.txt') course = find(race().courses, name='999') self.assertIsInstance(course, Course, 'Not course') self.assertEqual(course.length, 4400) self.assertEqual(course.climb, 0) self.assertEqual(len(course.controls), 14) self.assertEqual(course.controls[3].code, '34') self.assertEqual(course.controls[3].length, 316)
def get_control_score(code): obj = race() control = find(obj.controls, code=str(code)) if control and control.score: return control.score if obj.get_setting('result_processing_score_mode', 'fixed') == 'fixed': return obj.get_setting('result_processing_fixed_score_value', 1.0) # fixed score per control else: return int(code) // 10 # score = code / 10
def show_person_info(self): bib = self.item_bib.value() self.label_person_info.setText('') if bib: person = find(race().persons, bib=bib) if person: info = person.full_name if person.group: info = '{}\n{}: {}'.format(info, _('Group'), person.group.name) if person.card_number: info = '{}\n{}: {}'.format(info, _('Card'), person.card_number) self.label_person_info.setText(info) else: self.label_person_info.setText(_('not found'))
def test_import_csv(self): winorient.import_csv('test/5979_csv_wo.csv') person = find(race().persons, name='Сергей', surname='Добрынин') self.assertIsInstance(person, Person, 'Not person') self.assertIsInstance(person.group, Group, 'Not group') self.assertEqual(person.group.name, 'МУЖЧИНЫ', 'Group name error') self.assertIsInstance(person.organization, Organization, 'Not organization') self.assertEqual(person.organization.name, 'УралГУФК, Челябинск', 'Organization name error') self.assertEqual(person.get_year(), 1995, 'Year error') self.assertEqual(person.card_number, 1005404, 'Card number error') self.assertEqual(person.comment, 'C:123', 'Comment error') self.assertEqual(person.qual, Qualification.MS, 'Qualification error')
def _merge_punches(self): card_number = self._result.card_number existing_res = find(race().results, card_number=card_number) if not existing_res: self._add_result() return True else: if existing_res.merge_with(self._result): # existing result changed, recalculate group results and printout self._result = existing_res ResultChecker.calculate_penalty(self._result) ResultChecker.checking(self._result) return True
def get_group_leader_time(self, group): if self.race.get_type(group) == RaceType.RELAY: team_result = find(self.race.relay_teams, group=group, place=1) if isinstance(team_result, RelayTeam): leader_time = team_result.get_time() else: return OTime() else: results = self.get_group_finishes(group) if len(results) > 0: leader_result = results[0] leader_time = leader_result.get_result_otime() else: return OTime() return leader_time
def get_group_rank_relay(self, group): """ Rank calculation, takes sums or scores from qualification of best 10 athletes, who have OK result and not o/c :param group: :return: rank of group, -1 if we have < 10 successfull results """ teams = find(self.race.relay_teams, group=group, return_all=True) success_teams = [] started_teams = 0 if teams: for cur_team in teams: assert isinstance(cur_team, RelayTeam) if cur_team.get_is_out_of_competition(): continue if not cur_team.get_is_all_legs_finished(): continue started_teams += 1 if cur_team.get_is_status_ok(): success_teams.append(cur_team) if started_teams < 6: # less than 6 teams started in relay return -1 if len(success_teams) < 4: # less than 4 teams successfully finished in relay return -1 scores = [] for cur_team in success_teams: for cur_leg in cur_team.legs: res = cur_leg.get_result() person = res.person qual = person.qual scores.append(qual.get_scores()) if len(scores) <= 10: # get rank sum of 10 best finished return sum(scores) scores = sorted(scores) return sum(scores[-10:])
def import_from_course_data(courses): obj = race() for course in courses: if find(obj.courses, name=course['name']) is None: c = create(Course, name=course['name'], length=course['length'], climb=course['climb']) controls = [] i = 1 for control in course['controls']: if control['type'] == 'Control': controls.append( create(CourseControl, code=control['control'], order=i, length=control['leg_length'])) i += 1 c.controls = controls obj.courses.append(c)
def _relay_find_leg(self): if self._find_person_by_result(): bib = self._person.bib % 1000 while True: bib += 1000 next_leg = find(race().persons, bib=bib) if next_leg: next_leg_res = race().find_person_result(next_leg) if not next_leg_res: self._person = next_leg self._result.person = next_leg logging.info('Relay: Card {} assigned to bib {}'.format(self._result.card_number, bib)) break else: # All legs of relay team finished break if not self._person: self.assign_chip_reading = 'off' self.card_read_repeated = False
def check_bib(self): bib = self.item_bib.value() self.label_bib_info.setText('') if bib: person = find(race().persons, bib=bib) if person: if person.bib == self.current_object.bib: self.button_ok.setEnabled(True) return self.button_ok.setDisabled(True) self.is_ok['bib'] = False info = '{}\n{}'.format(_('Number already exists'), person.full_name) if person.group: info = '{}\n{}: {}'.format(info, _('Group'), person.group.name) self.label_bib_info.setText(info) else: self.label_bib_info.setText(_('Number is unique')) self.is_ok['bib'] = True if self.items_ok(): self.button_ok.setEnabled(True) else: self.button_ok.setEnabled(True)
def apply_changes_impl(self): import_race = self.races[self.item_races.currentIndex()] unique_id = 'id' if self.unique_id_item_name.isChecked(): unique_id = 'name' action = 'add' if self.import_action_item_overwrite.isChecked(): action = 'overwrite' obj = race() if unique_id == 'id' and action == 'overwrite': import_race.id = obj.id obj.update_data(import_race.to_dict()) return if unique_id == 'id' and action == 'add': organizations = [] for org in import_race.organizations: old_org = find(obj.organizations, id=org.id) old_org_by_name = find(obj.organizations, name=org.name) if old_org is None: if old_org_by_name is not None: org.name = '_' + org.name organizations.append(org) obj.organizations.extend(organizations) courses = [] for course in import_race.courses: old_course = find(obj.courses, id=course.id) old_course_by_name = find(obj.courses, name=course.name) if old_course is None: if old_course_by_name is not None: course.name = '_' + course.name courses.append(course) obj.courses.extend(courses) groups = [] for group in import_race.groups: old_group = find(obj.groups, id=group.id) old_group_by_name = find(obj.groups, name=group.name) if old_group is None: if old_group_by_name is not None: group.name = '_' + group.name if group.course: group.course = find(obj.courses, id=group.course.id) groups.append(group) obj.groups.extend(groups) persons = [] for person in import_race.persons: if find(obj.persons, id=person.id) is None: if person.group: person.group = find(obj.groups, id=person.group.id) if person.organization: person.organization = find(obj.organizations, id=person.organization.id) persons.append(person) obj.persons.extend(persons) results = [] for result in import_race.results: if find(obj.results, id=result.id) is None: if result.person: result.person = find(obj.persons, id=result.person.id) results.append(result) obj.results.extend(results) return
def apply_changes_impl(self): group = self.current_object assert (isinstance(group, Group)) if self.is_new: race().groups.insert(0, group) if group.name != self.item_name.text(): group.name = self.item_name.text() if group.long_name != self.item_full_name.text(): group.long_name = self.item_full_name.text() if (group.course is not None and group.course.name != self.item_course.currentText()) \ or (group.course is None and len(self.item_course.currentText()) > 0): group.course = find(race().courses, name=self.item_course.currentText()) if group.sex.get_title() != self.item_sex.currentText(): group.sex = Sex(self.item_sex.currentIndex()) if group.min_age != self.item_age_min.value(): group.min_age = self.item_age_min.value() if group.max_age != self.item_age_max.value(): group.max_age = self.item_age_max.value() if group.min_year != self.item_year_min.value(): group.min_year = self.item_year_min.value() if group.max_year != self.item_year_max.value(): group.max_year = self.item_year_max.value() if group.start_corridor != self.item_corridor.value(): group.start_corridor = self.item_corridor.value() if group.order_in_corridor != self.item_corridor_order.value(): group.order_in_corridor = self.item_corridor_order.value() if group.price != self.item_price.value(): group.price = self.item_price.value() time = time_to_otime(self.item_start_interval.time()) if group.start_interval != time: group.start_interval = time time = time_to_otime(self.item_max_time.time()) if group.max_time != time: group.max_time = time if group.ranking.is_active != self.rank_checkbox.isChecked(): group.ranking.is_active = self.rank_checkbox.isChecked() t = RaceType.get_by_name(self.type_combo.currentText()) selected_type = t if t is not None else group.get_type() if group.get_type() != selected_type: group.set_type(selected_type) group.is_any_course = self.item_is_any_course.isChecked() ResultCalculation(race()).set_rank(group) Teamwork().send(group.to_dict())
def get_group_rank_relay(self, group): """ Rank calculation, takes sums or scores from qualification of best X (default=10) athletes, who have OK result and are not out of competition :param group: :return: rank of group, -1 if we have < X (default=4) successfull teams """ teams = find(self.race.relay_teams, group=group, return_all=True) success_teams = [] start_limit = Config().ranking.get('start_limit_relay', 6) finish_limit = Config().ranking.get('finish_limit_relay', 4) sum_count = Config().ranking.get('sum_count_relay', 10) relay_ranking_method = Config().ranking.get('relay_ranking_method', 'personal') started_teams = 0 if teams: for cur_team in teams: assert isinstance(cur_team, RelayTeam) if cur_team.get_is_out_of_competition(): continue if not cur_team.get_is_all_legs_finished(): continue started_teams += 1 if cur_team.get_is_status_ok(): success_teams.append(cur_team) if started_teams < start_limit: # less than X (default=6) teams started in relay return -1 if len(success_teams) < finish_limit: # less than X (default=4) teams successfully finished in relay return -1 if relay_ranking_method == 'personal': scores = [] for cur_team in success_teams: for cur_leg in cur_team.legs: res = cur_leg.get_result() person = res.person qual = person.qual scores.append(qual.get_score()) if len(scores) <= sum_count: # get rank sum of X (default=10) best finished return sum(scores) scores = sorted(scores) return sum(scores[-sum_count:]) else: # calculate average team score and get sum of first X teams average_sum = 0 for cur_team in success_teams[:sum_count]: team_sum = 0 for cur_leg in cur_team.legs: res = cur_leg.get_result() person = res.person qual = person.qual team_sum += qual.get_score() average_sum += team_sum / len(cur_team.legs) return average_sum
def execute(self): for result in race().results: if result.person is None and result.bib: result.person = find(race().persons, bib=result.bib) self.app.refresh()
def apply_changes_impl(self): result = self.current_object if self.is_new: race().results.insert(0, result) if result.is_punch(): if result.card_number != self.item_card_number.value(): result.card_number = self.item_card_number.value() new_splits = self.splits.splits() if len(result.splits) == len(new_splits): for i, split in enumerate(result.splits): if split != new_splits[i]: break result.splits = new_splits time_ = time_to_otime(self.item_finish.time()) if result.finish_time != time_: result.finish_time = time_ time_ = time_to_otime(self.item_start.time()) if result.start_time != time_: result.start_time = time_ time_ = time_to_otime(self.item_credit.time()) if result.credit_time != time_: result.credit_time = time_ time_ = time_to_otime(self.item_penalty.time()) if result.penalty_time != time_: result.penalty_time = time_ if result.penalty_laps != self.item_penalty_laps.value(): result.penalty_laps = self.item_penalty_laps.value() cur_bib = -1 new_bib = self.item_bib.value() if result.person: cur_bib = result.person.bib if new_bib == 0: if result.person and result.is_punch(): if result.person.card_number == result.card_number: result.person.card_number = 0 result.person = None elif cur_bib != new_bib: new_person = find(race().persons, bib=new_bib) if new_person is not None: assert isinstance(new_person, Person) if result.person: if result.is_punch(): result.person.card_number = 0 result.person = new_person if result.is_punch(): race().person_card_number(result.person, result.card_number) result.bib = new_bib GlobalAccess().get_main_window().get_result_table().model().init_cache() if self.item_days.value() != result.days: result.days = self.item_days.value() result.status = ResultStatus.get_by_name(self.item_status.currentText()) status = StatusComments().remove_hint(self.item_status_comment.currentText()) if result.status_comment != status: result.status_comment = status if result.is_punch(): result.clear() try: ResultChecker.checking(result) ResultChecker.calculate_penalty(result) if result.person and result.person.group: GroupSplits(race(), result.person.group).generate(True) except ResultCheckerException as e: logging.error(str(e)) ResultCalculation(race()).process_results() Teamwork().send(result.to_dict())
def get_team_result(person): bib = person.bib % 1000 relay_team = find(race().relay_teams, bib_number=bib) if relay_team: if relay_team.get_lap_finished() == get_leg_count(): return relay_team.get_time()
def import_from_entry_list(entries): obj = race() for person_entry in entries: name = person_entry['group']['name'] if 'short_name' in person_entry['group']: name = person_entry['group']['short_name'] group = find(obj.groups, name=name) if group is None: group = Group() group.long_name = person_entry['group']['name'] if 'short_name' in person_entry['group']: group.name = person_entry['group']['short_name'] else: group.name = group.long_name obj.groups.append(group) org = find(obj.organizations, name=person_entry['organization']['name']) if org is None: org = Organization() org.name = person_entry['organization']['name'] if 'role_person' in person_entry['organization']: org.contact = person_entry['organization']['role_person'] obj.organizations.append(org) for person_entry in entries: person = Person() person.surname = person_entry['person']['family'] person.name = person_entry['person']['given'] name = person_entry['group']['name'] if 'short_name' in person_entry['group']: name = person_entry['group']['short_name'] person.group = find(obj.groups, name=name) person.organization = find(obj.organizations, name=person_entry['organization']['name']) if 'birth_date' in person_entry['person']: person.birth_date = dateutil.parser.parse( person_entry['person']['birth_date']).date() if len(person_entry['race_numbers']): person.comment = 'C:' + ''.join(person_entry['race_numbers']) if person_entry['control_card']: person.card_number = int(person_entry['control_card']) if 'bib' in person_entry['person']['extensions'] and person_entry[ 'person']['extensions']['bib']: person.bib = int(person_entry['person']['extensions']['bib']) if 'qual' in person_entry['person']['extensions'] and person_entry[ 'person']['extensions']['qual']: person.qual = Qualification.get_qual_by_name( person_entry['person']['extensions']['qual']) obj.persons.append(person) persons_dupl_cards = obj.get_duplicate_card_numbers() persons_dupl_names = obj.get_duplicate_names() if len(persons_dupl_cards): logging.info('{}'.format( _('Duplicate card numbers (card numbers are reset)'))) for person in persons_dupl_cards: logging.info('{} {} {} {}'.format( person.full_name, person.group.name if person.group else '', person.organization.name if person.organization else '', person.card_number)) person.card_number = 0 if len(persons_dupl_names): logging.info('{}'.format(_('Duplicate names'))) for person in persons_dupl_names: person.card_number = 0 logging.info('{} {} {} {}'.format( person.full_name, person.get_year(), person.group.name if person.group else '', person.organization.name if person.organization else ''))
def create_objects(self): """Create objects in memory, according to model""" my_race = race() assert(isinstance(my_race, Race)) my_race.data.title = '\n'.join(self.wdb_object.info.title) my_race.data.location = self.wdb_object.info.place my_race.data.chief_referee = self.wdb_object.info.referee my_race.data.secretary = self.wdb_object.info.secretary for team in self.wdb_object.team: assert (isinstance(team, WDBTeam)) new_team = Organization() new_team.name = team.name new_team.address = Address() new_team.contact = Contact() my_race.organizations.append(new_team) for course in self.wdb_object.dist: assert (isinstance(course, WDBDistance)) new_course = Course() new_course.controls = [] new_course.name = course.name new_course.climb = course.elevation new_course.length = course.length # new_course.type = self.wdb_object.info.type # TODO parse type # controls for i in range(course.point_quantity): control = CourseControl() control.code = str(course.point[i]) if i < len(course.leg): control.length = course.leg[i] new_course.controls.append(control) my_race.courses.append(new_course) for group in self.wdb_object.group: assert (isinstance(group, WDBGroup)) new_group = Group() new_group.name = group.name new_group.price = group.owner_cost course = group.get_course() if course is not None: new_group.course = find(race().courses, name=course.name) my_race.groups.append(new_group) for man in self.wdb_object.man: assert (isinstance(man, WDBMan)) new_person = Person() new_person.surname = man.name.split(" ")[0] new_person.name = man.name.split(" ")[-1] new_person.bib = man.number if man.qualification: if man.qualification == 10: man.qualification = Qualification.MSMK.value # Convert ZMS to MSMK new_person.qual = Qualification.get_qual_by_code(man.qualification) new_person.set_year(man.year) race().person_card_number(new_person, man.si_card) new_person.is_out_of_competition = man.is_not_qualified new_person.comment = man.comment new_person.start_group = man.start_group found_group = man.get_group() if found_group: group_name = found_group.name new_person.group = find(race().groups, name=group_name) found_team = man.get_team() if found_team: team_name = found_team.name new_person.organization = find(race().organizations, name=team_name) my_race.persons.append(new_person) new_person.start_time = int_to_otime(man.start) # result fin = man.get_finish() if fin is not None: result = ResultSportident() result.person = new_person result.card_number = int(man.si_card) result.start_time = int_to_otime(man.start) result.finish_time = int_to_otime(fin.time) result.penalty_time = OTime(sec = man.penalty_second) if man.status in self.status: result.status = self.status[man.status] my_race.add_result(result) # splits chip = man.get_chip() if chip is not None: result.splits = [] for i in range(chip.quantity): p = chip.punch[i] assert isinstance(p, WDBPunch) code = p.code time = int_to_otime(p.time) split = Split() split.code = str(code) split.time = time if code > 0: result.splits.append(split) ResultCalculation(race()).process_results()
def import_csv(source): wo_csv = wo.parse_csv(source) obj = memory.race() old_lengths = obj.get_lengths() for group_name in wo_csv.groups: group = memory.find(obj.groups, name=group_name) if group is None: group = memory.Group() group.name = group_name group.long_name = group_name obj.groups.append(group) for team_name in wo_csv.teams: org = memory.find(obj.organizations, name=team_name) if org is None: org = memory.Organization() org.name = team_name obj.organizations.append(org) for person_dict in wo_csv.data: if person_dict['qual_id'] and person_dict['qual_id'].isdigit(): qual_id = int(person_dict['qual_id']) else: qual_id = 0 person_org = memory.find(obj.organizations, name=person_dict['team_name']) person_org.contact = person_dict['representative'] person = memory.Person() person.name = person_dict['name'] person.surname = person_dict['surname'] person.bib = person_dict['bib'] person.set_year(person_dict['year']) person.card_number = int(person_dict['sportident_card']) person.group = memory.find(obj.groups, name=person_dict['group_name']) person.organization = person_org person.qual = Qualification(qual_id) person.comment = person_dict['comment'] obj.persons.append(person) new_lengths = obj.get_lengths() logging.info(_('Import result')) logging.info('{}: {}'.format(_('Persons'), new_lengths[0] - old_lengths[0])) # logging.info('{}: {}'.format(_('Race Results'), new_lengths[1]-old_lengths[1])) logging.info('{}: {}'.format(_('Groups'), new_lengths[2] - old_lengths[2])) # logging.info('{}: {}'.format(_('Courses'), new_lengths[3]-old_lengths[3])) logging.info('{}: {}'.format(_('Teams'), new_lengths[4] - old_lengths[4])) persons_dupl_cards = obj.get_duplicate_card_numbers() persons_dupl_names = obj.get_duplicate_names() if len(persons_dupl_cards): logging.info('{}'.format( _('Duplicate card numbers (card numbers are reset)'))) for person in persons_dupl_cards: logging.info('{} {} {} {}'.format( person.full_name, person.group.name if person.group else '', person.organization.name if person.organization else '', person.card_number)) person.card_number = 0 if len(persons_dupl_names): logging.info('{}'.format(_('Duplicate names'))) for person in persons_dupl_names: person.card_number = 0 logging.info('{} {} {} {}'.format( person.full_name, person.get_year(), person.group.name if person.group else '', person.organization.name if person.organization else ''))
def execute(self): for result in race().results: if result.person is None and result.card_number: result.person = find(race().persons, card_number=result.card_number) self.app.refresh()
def apply_changes_impl(self): person = self.current_object assert (isinstance(person, Person)) if self.is_new: race().persons.insert(0, person) if person.name != self.item_name.currentText(): person.name = self.item_name.currentText() if person.surname != self.item_surname.text(): person.surname = self.item_surname.text() if (person.group is not None and person.group.name != self.item_group.currentText()) or\ (person.group is None and len(self.item_group.currentText()) > 0): person.group = find(race().groups, name=self.item_group.currentText()) if (person.organization is not None and person.organization.name != self.item_team.currentText()) or \ (person.organization is None and len(self.item_team.currentText()) > 0): organization = find(race().organizations, name=self.item_team.currentText()) if organization is None: organization = Organization() organization.name = self.item_team.currentText() race().organizations.append(organization) Teamwork().send(organization.to_dict()) person.organization = organization if person.qual.get_title() != self.item_qual.currentText(): person.qual = Qualification.get_qual_by_name( self.item_qual.currentText()) if person.bib != self.item_bib.value(): person.bib = self.item_bib.value() new_time = time_to_otime(self.item_start.time()) if person.start_time != new_time: person.start_time = new_time if person.start_group != self.item_start_group.value( ) and self.item_start_group.value(): person.start_group = self.item_start_group.value() if (not person.card_number or int(person.card_number) != self.item_card.value()) \ and self.item_card.value: race().person_card_number(person, self.item_card.value()) if person.is_out_of_competition != self.item_out_of_competition.isChecked( ): person.is_out_of_competition = self.item_out_of_competition.isChecked( ) if person.is_paid != self.item_paid.isChecked(): person.is_paid = self.item_paid.isChecked() if person.is_rented_card != self.item_rented.isChecked(): person.is_rented_card = self.item_rented.isChecked() if person.is_personal != self.item_personal.isChecked(): person.is_personal = self.item_personal.isChecked() if person.comment != self.item_comment.toPlainText(): person.comment = self.item_comment.toPlainText() use_birthday = Config().configuration.get('use_birthday', False) if use_birthday: new_birthday = qdate_to_date(self.item_birthday.date()) if person.birth_date != new_birthday and new_birthday: if person.birth_date or new_birthday != date.today(): person.birth_date = new_birthday else: if person.get_year() != self.item_year.value(): person.set_year(self.item_year.value()) ResultCalculation(race()).process_results() Teamwork().send(person.to_dict())