async def _requestMore(self):
        logger.debug("Request more messages from channel %s", self.channelId)
        url = BASE_URL + 'channels.history'
        params = {
            'token': self.slackService.token,
            'channel': self.channelId,
            'count': MESSAGE_REQUEST_COUNT,
            'latest': self._latest
        }
        async with self.slackService.session.get(url,
                                                 headers=HEADERS,
                                                 params=params) as resp:
            logger.debug("response: %s", resp)
            data = await resp.json()
            #logger.debug("data: %s", data)
            messageData = data['messages']
            if messageData:
                self._latest = messageData[0]['ts']
            messages = [
                MessagesItem(ts=QDateTime.fromMSecsSinceEpoch(
                    float(m['ts']) * 1000),
                             date=QDateTime.fromMSecsSinceEpoch(
                                 float(m['ts']) * 1000).date(),
                             time=QDateTime.fromMSecsSinceEpoch(
                                 float(m['ts']) * 1000).time(),
                             user=m.get('username', m.get('user')),
                             text=m['text']) for m in data['messages']
                if m['type'] == 'message'
            ]

            self.addItems(list(reversed(messages)))
Exemplo n.º 2
0
 def _timeSpan(self):
     tmin = np.inf
     tmax = -np.inf
     for p in self._portToIdx:
         t = self._currentFile["streams"][p][0]["rcvTimestamp"]
         tmin = min(t, tmin)
         t = self._currentFile["streams"][p][-1]["rcvTimestamp"]
         tmax = max(t, tmax)
     return QDateTime.fromMSecsSinceEpoch(tmin//1000), QDateTime.fromMSecsSinceEpoch(tmax//1000)
Exemplo n.º 3
0
def computeAxisValue(axis: Optional[QtCharts.QAbstractAxis],
                     value: float) -> str:
    """ Provide the label to be visualized at coordinate 'value' of the specified axis """
    if not axis:
        return '-'
    if axis.type() == QtCharts.QAbstractAxis.AxisTypeDateTime:
        axis: QtCharts.QDateTimeAxis
        try:
            qDate = QDateTime.fromMSecsSinceEpoch(int(value))
        except OverflowError as e:
            flogging.appLogger.warning('Axis value error: {}'.format(str(e)))
            text = '-'
        else:
            text = qDate.toString(axis.format())
    elif axis.type() == QtCharts.QAbstractAxis.AxisTypeBarCategory:
        axis: QtCharts.QBarCategoryAxis
        categories = axis.categories()
        if 0 <= round(value) < len(categories):
            text = axis.at(round(value))
        else:
            text = '-'
    elif axis.type() == QtCharts.QAbstractAxis.AxisTypeCategory:
        axis: QtCharts.QCategoryAxis
        categories = axis.categoriesLabels()
        if 0 <= round(value) < len(categories):
            text = axis.categoriesLabels()[round(value)]
        else:
            text = '-'
    else:
        text = '{0:.2f}'.format(value)
    return text
Exemplo n.º 4
0
    def displayPosition(self, value):
        """
        Slot called when the slider is moved. Displays the position without actually seeking to it.

        :param value: the new slider value.
        :return:
        """
        assertMainThread()
        if self.beginTime is None:
            return
        if self.positionSlider.isSliderDown():
            ts = QDateTime.fromMSecsSinceEpoch(self.beginTime.toMSecsSinceEpoch() + value, self.beginTime.timeSpec())
            self.currentLabel.setEnabled(False)
            self.currentLabel.setText(ts.toString("hh:mm:ss.zzz"))
Exemplo n.º 5
0
 def _transmit(self, pname):
     idx = self._portToIdx[pname]
     # read data sample from HDF5 file
     content, dataType, dataTimestamp, rcvTimestamp = self._currentFile["streams"][pname][idx]
     # create sample to transmit
     sample = DataSample(content.tobytes(), dataType, dataTimestamp)
     res = time.perf_counter_ns()
     # transmit sample over corresponding port
     self._ports[[p.name() for p in self._ports].index(pname)].transmit(sample)
     self._currentTimestampChanged(QDateTime.fromMSecsSinceEpoch(rcvTimestamp//1000))
     if self._untilStream is not None:
         if self._untilStream == pname or self._untilStream == '':
             self.pausePlayback()
     return res
Exemplo n.º 6
0
    def onSliderValueChanged(self, value):
        """
        Slot called whenever the slider value is changed.

        :param value: the new slider value
        :return:
        """
        assertMainThread()
        if self.beginTime is None or self.preventSeek:
            return
        if self.actStart.isEnabled():
            ts = QDateTime.fromMSecsSinceEpoch(self.beginTime.toMSecsSinceEpoch() + value, self.beginTime.timeSpec())
            self._seekTime.emit(ts)
        else:
            logger.warning("Can't seek while playing.")
Exemplo n.º 7
0
    def data(self, index, role):
        """
        overwritten from base class

        :param index:
        :param role:
        :return:
        """
        c = self._children[index.row()]
        if role == Qt.DisplayRole:
            if index.column() == 0:
                return c.name if c.name != "" else str(c)
            if index.column() == 1:
                if c.is_dir():
                    return ""
                try:
                    s = c.stat().st_size
                except Exception:  # pylint: disable=broad-except
                    return ""
                if s >= 1024 * 1024 * 1024:
                    return "%.0f GB" % (s / (1024 * 1024 * 1024))
                if s >= 1024 * 1024:
                    return "%.0f MB" % (s / (1024 * 1024))
                if s >= 1024:
                    return "%.0f kB" % (s / 1024)
                return s
            if index.column() == 2:
                try:
                    return QDateTime.fromMSecsSinceEpoch(c.stat().st_mtime *
                                                         1000)
                except Exception:  # pylint: disable=broad-except
                    return ""
        if role == Qt.DecorationRole:
            if index.column() == 0:
                if c.is_dir():
                    return self._iconProvider.icon(QFileIconProvider.Drive)
                return self._iconProvider.icon(QFileInfo(str(c.absolute())))
        if role == Qt.UserRole:
            if index.column() == 0:
                return c
        if role in [Qt.DisplayRole, Qt.EditRole]:
            if index.column() == 3:
                if index.row() > 0:
                    return str(c) + (os.path.sep if c.is_dir() else "")
                return str(c.parent) + os.path.sep
        return None
def createCandlestickChart(data):

    chart = QtCharts.QChart()
    chart.setTitle("Simple Candlestick Series example")
    chart.setAnimationOptions(QtCharts.QChart.SeriesAnimations)

    series1 = QtCharts.QCandlestickSeries()
    series1.setName("Acme")
    series1.setIncreasingColor(Qt.green)
    series1.setDecreasingColor(Qt.red)

    for x in data:

        category = float(x[0])
        csSet = QtCharts.QCandlestickSet(category)
        csSet.setOpen(x[1])
        csSet.setHigh(x[2])
        csSet.setLow(x[3])
        csSet.setClose(x[4])

        series1.append(csSet)

    chart.addSeries(series1)

    chart.createDefaultAxes()

    axisX = QtCharts.QBarCategoryAxis()
    axisX.setCategories(
        [QDateTime.fromMSecsSinceEpoch(d[0]).toString("d") for d in data])
    axisX.setTitleText("day")

    axisY = QtCharts.QValueAxis()
    axisY.setMax(chart.axisY().max() * 1.01)
    axisY.setMin(chart.axisY().min() * 0.99)

    chart.setAxisX(axisX, series1)
    chart.setAxisY(axisY, series1)

    chartView = QtCharts.QChartView(chart)
    chartView.setRenderHint(QPainter.Antialiasing)

    return chartView
Exemplo n.º 9
0
 def newDuration(self, newDuration):
     logger.debug("newDuration %s", newDuration)
     self.sequenceOpened.emit(self.filename,
                              QDateTime.fromMSecsSinceEpoch(0),
                              QDateTime.fromMSecsSinceEpoch(newDuration),
                              ["video"])
Exemplo n.º 10
0
        category = x[0]
        csSet = QtCharts.QCandlestickSet(category)
        csSet.setOpen(x[1])
        csSet.setHigh(x[2])
        csSet.setLow(x[3])
        csSet.setClose(x[4])

        series1.append(csSet)

    chart.addSeries(series1)

    chart.createDefaultAxes()

    axisX = QtCharts.QBarCategoryAxis()
    axisX.setCategories(
        [QDateTime.fromMSecsSinceEpoch(d[0]).toString("d") for d in data])
    axisX.setTitleText("day")

    axisY = QtCharts.QValueAxis()
    axisY.setMax(chart.axisY().max() * 1.01)
    axisY.setMin(chart.axisY().min() * 0.99)

    chart.setAxisX(axisX, series1)
    chart.setAxisY(axisY, series1)

    chartView = QtCharts.QChartView(chart)
    chartView.setRenderHint(QPainter.Antialiasing)

    window = QMainWindow()
    window.setCentralWidget(chartView)
    window.resize(400, 300)
Exemplo n.º 11
0
def execute_2():
    logger.info("execute_2:begin")
    cfg = Services.getService("Configuration")
    pbc = Services.getService("PlaybackControl")

    app = cfg.configuration().applicationByName("pbApp")

    logger.info("app activated")
    execute_2.i = MethodInvoker(pbc.setSequence, Qt.QueuedConnection,
                                glob.glob("./*.h5")[0])
    _, tbegin, tend, _ = waitForSignal(pbc.sequenceOpened)

    execute_2.i = MethodInvoker(pbc.startPlayback, Qt.QueuedConnection)
    waitForSignal(pbc.playbackStarted)
    waitForSignal(pbc.playbackPaused)
    logger.info("played")

    execute_2.i = MethodInvoker(pbc.seekBeginning, Qt.QueuedConnection)
    waitForSignal(pbc.currentTimestampChanged)
    logger.info("seekBeginning")

    for i in range(10):
        execute_2.i = MethodInvoker(pbc.stepForward, Qt.QueuedConnection, None)
        waitForSignal(pbc.playbackPaused)
        logger.info("stepForward[None]")

    for i in range(10):
        execute_2.i = MethodInvoker(pbc.stepForward, Qt.QueuedConnection,
                                    "stream1")
        waitForSignal(pbc.playbackPaused)
        logger.info("stepForward[stream1]")

    for i in range(2):
        execute_2.i = MethodInvoker(pbc.stepForward, Qt.QueuedConnection,
                                    "stream2")
        waitForSignal(pbc.playbackPaused)
        logger.info("stepForward[stream2]")

    execute_2.i = MethodInvoker(
        pbc.seekTime, Qt.QueuedConnection,
        QDateTime.fromMSecsSinceEpoch(
            (tbegin.toMSecsSinceEpoch() + tend.toMSecsSinceEpoch()) // 2))
    waitForSignal(pbc.currentTimestampChanged)
    logger.info("seekTime")

    execute_2.i = MethodInvoker(pbc.seekEnd, Qt.QueuedConnection)
    waitForSignal(pbc.currentTimestampChanged)
    logger.info("seekEnd")

    for i in range(10):
        execute_2.i = MethodInvoker(pbc.stepBackward, Qt.QueuedConnection,
                                    None)
        waitForSignal(pbc.playbackPaused)
        logger.info("stepBackward[None]")

    execute_2.i = MethodInvoker(
        pbc.seekTime, Qt.QueuedConnection,
        QDateTime.fromMSecsSinceEpoch(tbegin.toMSecsSinceEpoch() - 1000))
    waitForSignal(pbc.currentTimestampChanged)
    logger.info("seekTimeBegin")

    execute_2.i = MethodInvoker(
        pbc.seekTime, Qt.QueuedConnection,
        QDateTime.fromMSecsSinceEpoch(tend.toMSecsSinceEpoch() + 1000))
    waitForSignal(pbc.currentTimestampChanged)
    logger.info("seekTimeEnd")

    execute_2.i = MethodInvoker(QCoreApplication.quit, Qt.QueuedConnection)
    logger.info("execute_2:end")