Пример #1
0
    def interval(self):
        if SIReaderClient().is_alive() != self.sportident_status:
            self.toolbar_property['sportident'].setIcon(
                QtGui.QIcon(
                    config.icon_dir(
                        self.sportident_icon[SIReaderClient().is_alive()])))
            self.sportident_status = SIReaderClient().is_alive()
        if Teamwork().is_alive() != self.teamwork_status:
            self.toolbar_property['teamwork'].setIcon(
                QtGui.QIcon(
                    config.icon_dir(
                        self.teamwork_icon[Teamwork().is_alive()])))
            self.teamwork_status = Teamwork().is_alive()

        try:
            if self.get_configuration().get('autosave_interval'):
                if self.file:
                    if time.time() - self.last_update > int(
                            self.get_configuration().get('autosave_interval')):
                        self.save_file()
                        logging.info(_('Auto save'))
                else:
                    logging.debug(_('No file to auto save'))
        except Exception as e:
            logging.error(str(e))

        while not self.log_queue.empty():
            text = self.log_queue.get()
            self.statusbar_message(text)
            if hasattr(self, 'logging_tab'):
                self.logging_tab.write(text)
Пример #2
0
 def execute(self):
     host = race().get_setting('teamwork_host', 'localhost')
     port = race().get_setting('teamwork_port', 50010)
     token = race().get_setting('teamwork_token', str(uuid.uuid4())[:8])
     connection_type = race().get_setting('teamwork_type_connection', 'client')
     Teamwork().set_options(host, port, token, connection_type)
     Teamwork().toggle()
     time.sleep(0.5)
     self.app.interval()
Пример #3
0
 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)
Пример #4
0
 def execute(self):
     result = race().new_result()
     race().add_new_result(result)
     Teamwork().send(result.to_dict())
     logging.info('SPORTident result')
     self.app.get_result_table().model().init_cache()
     self.app.refresh()
Пример #5
0
    def apply_changes_impl(self):
        org = self.current_object
        assert (isinstance(org, Organization))
        if self.is_new:
            race().organizations.insert(0, org)

        if org.name != self.item_name.text():
            org.name = self.item_name.text()

        if org.address.country.name != self.item_country.currentText():
            org.address.country.name = self.item_country.currentText()

        if org.address.state != self.item_region.currentText():
            org.address.state = self.item_region.currentText()

        if org.address.city != self.item_city.text():
            org.address.city = self.item_city.text()

        if org.address.street != self.item_address.text():
            org.address.street = self.item_address.text()

        if org.contact.value != self.item_contact.text():
            org.contact.value = self.item_contact.text()
            org.contact.name = 'phone'

        GlobalAccess().get_main_window().refresh()
        Teamwork().send(org.to_dict())
Пример #6
0
    def execute(self):
        if self.app.current_tab != 1:
            logging.warning(_('No result selected'))
            return
        obj = race()

        status_dict = {
            ResultStatus.NONE: ResultStatus.OK,
            ResultStatus.OK: ResultStatus.DISQUALIFIED,
            ResultStatus.DISQUALIFIED: ResultStatus.DID_NOT_START,
            ResultStatus.DID_NOT_START: ResultStatus.DID_NOT_FINISH,
            ResultStatus.DID_NOT_FINISH: ResultStatus.OVERTIME,
            ResultStatus.OVERTIME: ResultStatus.OK,
        }

        table = self.app.get_result_table()
        assert isinstance(table, QTableView)
        index = table.currentIndex().row()
        if index < 0:
            index = 0
        if index >= len(obj.results):
            mes = QMessageBox()
            mes.setText(_('No results to change status'))
            mes.exec()
            return
        result = obj.results[index]
        result.status = status_dict[result.status]
        Teamwork().send(result.to_dict())
        self.app.refresh()
Пример #7
0
 def execute(self):
     result = race().new_result(ResultManual)
     Teamwork().send(result.to_dict())
     race().add_new_result(result)
     logging.info(_('Manual finish'))
     self.app.get_result_table().model().init_cache()
     self.app.refresh()
     self.app.auto_save()
Пример #8
0
 def add_sportident_result_from_sireader(self, result):
     try:
         assignment_mode = race().get_setting('system_assignment_mode',
                                              False)
         if not assignment_mode:
             self.clear_filters(remove_condition=False)
             rg = ResultSportidentGeneration(result)
             if rg.add_result():
                 result = rg.get_result()
                 ResultCalculation(race()).process_results()
                 if race().get_setting('split_printout', False):
                     try:
                         split_printout(result)
                     except NoResultToPrintException as e:
                         logging.error(str(e))
                     except NoPrinterSelectedException as e:
                         logging.error(str(e))
                     except Exception as e:
                         logging.error(str(e))
                 elif result.person and result.person.group:
                     GroupSplits(race(), result.person.group).generate(True)
                 Teamwork().send(result.to_dict())
                 TelegramClient().send_result(result)
                 if result.person:
                     if result.is_status_ok():
                         Sound().ok()
                     else:
                         Sound().fail()
                     if result.person.is_rented_card or RentCards().exists(
                             result.person.card_number):
                         Sound().rented_card()
         else:
             for person in race().persons:
                 if not person.card_number:
                     old_person = race().person_card_number(
                         person, result.card_number)
                     if old_person is not None:
                         Teamwork().send(old_person.to_dict())
                     person.is_rented_card = True
                     Teamwork().send(person.to_dict())
                     break
         self.refresh()
     except Exception as e:
         logging.error(str(e))
Пример #9
0
    def apply_changes_impl(self):
        org = self.current_object
        assert (isinstance(org, Organization))
        if self.is_new:
            race().organizations.insert(0, org)

        org.name = self.item_name.text()
        org.code = self.item_code.text()
        org.country = self.item_country.currentText()
        org.region = self.item_region.currentText()
        org.contact = self.item_contact.text()

        Teamwork().send(org.to_dict())
Пример #10
0
    def interval(self):
        if SIReaderClient().is_alive() != self.sportident_status:
            self.toolbar_property['sportident'].setIcon(
                QtGui.QIcon(config.icon_dir(self.sportident_icon[SIReaderClient().is_alive()])))
            self.sportident_status = SIReaderClient().is_alive()
        if Teamwork().is_alive() != self.teamwork_status:
            self.toolbar_property['teamwork'].setIcon(
                QtGui.QIcon(config.icon_dir(self.teamwork_icon[Teamwork().is_alive()])))
            self.teamwork_status = Teamwork().is_alive()

        if self.saving:
            if self.file:
                self.save_file()
                logging.info(_('Auto save'))
            else:
                logging.warning(_('No file to auto save'))
            self.saving = False

        while not self.log_queue.empty():
            text = self.log_queue.get()
            self.statusbar_message(text)
            if hasattr(self, 'logging_tab'):
                self.logging_tab.write(text)
Пример #11
0
    def post_show(self):
        if self.file:
            self.open_file(self.file)
        elif Configuration().configuration.get('open_recent_file'):
            if len(self.recent_files):
                self.open_file(self.recent_files[0])

        Teamwork().set_call(self.teamwork)
        SIReaderClient().set_call(self.add_sportident_result_from_sireader)
        SportiduinoClient().set_call(self.add_sportiduino_result_from_reader)
        SFRReaderClient().set_call(self.add_sfr_result_from_reader)

        ServiceListenerThread().interval.connect(self.interval)
        ServiceListenerThread().start()
Пример #12
0
    def _delete_object(self):
        indexes = self.get_selected_rows()
        if not len(indexes):
            return

        confirm = messageBoxQuestion(self, _('Question'), _('Please confirm'),
                                     QMessageBox.Yes | QMessageBox.No)
        if confirm == QMessageBox.No:
            return
        tab = self.current_tab
        res = []
        if tab == 0:
            res = race().delete_persons(indexes)
            ResultCalculation(race()).process_results()
            self.refresh()
        elif tab == 1:
            res = race().delete_results(indexes)
            ResultCalculation(race()).process_results()
            self.refresh()
        elif tab == 2:
            try:
                res = race().delete_groups(indexes)
            except NotEmptyException as e:
                logging.warning(str(e))
                QMessageBox.question(self.get_group_table(), _('Error'),
                                     _('Cannot remove group'))
            self.refresh()
        elif tab == 3:
            try:
                res = race().delete_courses(indexes)
            except NotEmptyException as e:
                logging.warning(str(e))
                QMessageBox.question(self.get_course_table(), _('Error'),
                                     _('Cannot remove course'))
            self.refresh()
        elif tab == 4:
            try:
                res = race().delete_organizations(indexes)
            except NotEmptyException as e:
                logging.warning(str(e))
                QMessageBox.question(self.get_organization_table(), _('Error'),
                                     _('Cannot remove organization'))
            self.refresh()
        if len(res):
            Teamwork().delete([r.to_dict() for r in res])
Пример #13
0
 def execute(self):
     try:
         obj = race()
         data_list = [obj.persons, obj.results, obj.groups, obj.courses, obj.organizations]
         if not self.app.current_tab < len(data_list):
             return
         items = data_list[self.app.current_tab]
         indexes = self.app.get_selected_rows()
         items_dict = []
         for index in indexes:
             if index < 0:
                 continue
             if index >= len(items):
                 break
             items_dict.append(items[index].to_dict())
         Teamwork().send(items_dict)
     except Exception as e:
         logging.error(str(e))
Пример #14
0
    def apply_changes_impl(self):
        course = self.current_object
        if self.is_new:
            race().courses.insert(0, course)

        if course.name != self.item_name.text():
            course.name = self.item_name.text()

        if course.length != self.item_length.value():
            course.length = self.item_length.value()

        if course.climb != self.item_climb.value():
            course.climb = self.item_climb.value()

        text = self.item_controls.toPlainText()

        course.controls.clear()
        for i in text.split('\n'):
            control = CourseControl()
            if i is None or len(i) == 0:
                continue
            control.code = i.split()[0]
            if len(i.split()) > 1:
                try:
                    control.length = int(i.split()[1])
                except Exception as e:
                    logging.error(str(e))
                    control.length = 0
            course.controls.append(control)

        obj = race()
        ResultChecker.check_all()
        ResultCalculation(obj).process_results()
        RaceSplits(obj).generate()
        ScoreCalculation(obj).calculate_scores()
        GlobalAccess().get_main_window().refresh()
        Teamwork().send(course.to_dict())
Пример #15
0
    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())
Пример #16
0
    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())
Пример #17
0
 def execute(self):
     result = race().new_result(ResultManual)
     Teamwork().send(result.to_dict())
     race().add_new_result(result)
     logging.info(_('Manual finish'))
     self.app.refresh()
Пример #18
0
    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())