예제 #1
0
    def update(self, timestamp, device, channel, data):
        '''Update the data for the device (+channel) with the most recent
        measurement from the given payload.'''

        item = self.getItem(device, channel)

        value, unit, mqflags = data
        value_str = self.format_value(value)
        unit_str = util.format_unit(unit)
        mqflags_str = self.format_mqflags(mqflags)

        # The display role is a tuple containing the value and the unit/flags.
        disp = (value_str, ' '.join([unit_str, mqflags_str]))
        item.setData(disp, QtCore.Qt.DisplayRole)

        # The samples role is a dictionary that contains the old samples for each unit.
        # Should be trimmed periodically, otherwise it grows larger and larger.
        if not math.isinf(value) and not math.isnan(value):
            sample = (timestamp, value)
            traces = item.data(MeasurementDataModel.tracesRole)

            # It's not possible to use 'collections.defaultdict' here, because
            # PySide doesn't return the original type that was passed in.
            if not (unit in traces):
                traces[unit] = Trace()
            traces[unit].append(sample)

            item.setData(traces, MeasurementDataModel.tracesRole)
예제 #2
0
    def update(self, timestamp, device, channel, data):
        '''Update the data for the device (+channel) with the most recent
        measurement from the given payload.'''

        item = self.getItem(device, channel)

        value, unit, mqflags = data
        value_str = self.format_value(value)
        unit_str = util.format_unit(unit)
        mqflags_str = self.format_mqflags(mqflags)

        # The display role is a tuple containing the value and the unit/flags.
        disp = (value_str, ' '.join([unit_str, mqflags_str]))
        item.setData(disp, QtCore.Qt.DisplayRole)

        # The samples role is a dictionary that contains the old samples for each unit.
        # Should be trimmed periodically, otherwise it grows larger and larger.
        if not math.isinf(value) and not math.isnan(value):
            sample = (timestamp, value)
            traces = item.data(MeasurementDataModel.tracesRole)

            # It's not possible to use 'collections.defaultdict' here, because
            # PySide doesn't return the original type that was passed in.
            if not (unit in traces):
                traces[unit] = Trace()
            traces[unit].append(sample)

            item.setData(traces, MeasurementDataModel.tracesRole)
예제 #3
0
    def _getPlot(self, unit):
        '''Looks up or creates a new plot for 'unit'.'''

        if unit in self._plots:
            return self._plots[unit]

        # create a new plot for the unit
        plot = self.plotwidget.addPlot()
        plot.yaxis.setLabel(util.quantity_from_unit(unit), units=util.format_unit(unit))
        plot.view.setXRange(-settings.graph.backlog.value(), 0, update=False)
        plot.view.setYRange(-1, 1)
        plot.view.enableAutoRange(axis=pyqtgraph.ViewBox.YAxis)
        # lock to the range calculated by the view using additional padding,
        # looks nicer this way
        r = plot.view.viewRange()
        plot.view.setLimits(xMin=r[0][0], xMax=r[0][1])

        self._plots[unit] = plot
        return plot
예제 #4
0
    def _getPlot(self, unit):
        '''Looks up or creates a new plot for 'unit'.'''

        if unit in self._plots:
            return self._plots[unit]

        # Create a new plot for the unit.
        plot = self.plotwidget.addPlot()
        plot.yaxis.setLabel(util.quantity_from_unit(unit), units=util.format_unit(unit))
        plot.view.setXRange(-settings.graph.backlog.value(), 0, update=False)
        plot.view.setYRange(-1, 1)
        plot.view.enableAutoRange(axis=pyqtgraph.ViewBox.YAxis)
        # Lock to the range calculated by the view using additional padding,
        # looks nicer this way.
        r = plot.view.viewRange()
        plot.view.setLimits(xMin=r[0][0], xMax=r[0][1])

        self._plots[unit] = plot
        return plot