Beispiel #1
0
    def data(self, index, role=Qt.DisplayRole):
        """Convert msecs to something that looks like a time."""
        if role in (Qt.DisplayRole, Qt.EditRole):
            if index.column(
            ) in self.msecs_from_reference_columns + self.msecs_delta_columns:
                race_table_model = self.modeldb.race_table_model
                if index.column(
                ) in self.msecs_from_reference_columns and self.wall_times:
                    reference_datetime = race_table_model.get_reference_clock_datetime(
                    )
                else:
                    reference_datetime = QDateTime(QDate.currentDate())

                msecs = self.sourceModel().data(self.mapToSource(index), role)

                if msecs == MSECS_UNINITIALIZED:
                    return ''
                elif msecs == MSECS_DNS:
                    return 'DNS'
                elif msecs == MSECS_DNF:
                    return 'DNF'
                elif msecs == MSECS_DNP:
                    return 'DNP'

                return reference_datetime.addMSecs(msecs).toString(
                    defaults.DATETIME_FORMAT)

        return super().data(index, role)
Beispiel #2
0
    def collect_result_submits(self):
        """Go through the racer table and find stuff that needs submitting.

        We collect the list of results that need submitting into self.pending_queue.

        The current implementation of this function won't do a collection until the pending_queue
        has been drained.
        """
        if self.pending_queue:
            return

        racer_table_model = self.modeldb.racer_table_model

        with self.pending_queue_lock:
            # Iterate through all racers and put pending results on the results queue.
            for row in range(racer_table_model.rowCount()):
                record = racer_table_model.record(row)

                if record.value(racer_table_model.STATUS) != 'local':
                    continue

                metadata = json.loads(record.value(racer_table_model.METADATA))

                # Stuff to go into the ontheday result submission.
                # If no ontheday metadata, this racer was not imported from ontheday.net, so skip.
                try:
                    ontheday_id = metadata['ontheday']['id']
                except KeyError:
                    continue

                finish = record.value(racer_table_model.FINISH)
                if msecs_is_valid(finish):
                    # Report time relative to reference clock (which means just use msecs since
                    # midnight).
                    reference_datetime = QDateTime(QDate.currentDate())

                    finish_time = reference_datetime.addMSecs(finish)
                    ontheday_watch_finish_time = finish_time.time().toString(
                        Qt.ISODateWithMs)
                    ontheday_tt_dnf = False
                elif finish in (MSECS_DNF, MSECS_DNP):
                    ontheday_watch_finish_time = self.WATCH_FINISH_TIME_TO_POST
                    ontheday_tt_dnf = True
                else:
                    ontheday_watch_finish_time = self.WATCH_FINISH_TIME_TO_POST
                    ontheday_tt_dnf = False

                result = {
                    'ontheday': {
                        'id': ontheday_id,
                        'watch_finish_time': ontheday_watch_finish_time,
                        'tt_dnf': ontheday_tt_dnf,
                        'status': None
                    },
                    'row': row
                }

                self.pending_queue.append(result)