class NewGraph():
    def __init__(self):

        self.curves = []
        self.titleFont = QFont("Helvetica", 12, QFont.Bold)
        self.axisFont = QFont("Helvetica", 11, QFont.Bold)

    def createGraph(self):

        self.plot = QwtPlot()
        self.plot.resize(1000, 1000)
        self.plot.setAxisScaleDraw(QwtPlot.xBottom,
                                   DateTimeTimeScaleDraw(names=False))
        self.plot.replot()
        self.plot.show()

    def createCurve(self, x, y, colour):

        curve = QwtPlotCurve()
        colour = QColor(colour)
        curve.setPen(colour)
        curve.setData(x, y)
        curve.attach(self.plot)
        #self.plot.replot()
        self.curves.append(curve)

    def removeCurve(self, curveIndex):

        self.curves[curveIndex].attach(0)
        del self.curves[curveIndex]

    def setAxisTitles(self, yAxis, xAxis):

        # Create text for graph and axis titles
        xTitle = QwtText()
        xTitle.setText(xAxis)
        xTitle.setFont(self.axisFont)
        yTitle = QwtText()
        yTitle.setText(yAxis)
        yTitle.setFont(self.axisFont)

        self.plot.setAxisTitle(self.plot.yLeft, yTitle)
        self.plot.setAxisTitle(self.plot.xBottom, xTitle)

    def setTitle(self, title):

        titleText = QwtText()
        titleText.setText(title)
        titleText.setFont(self.titleFont)
        self.plot.setTitle(titleText)
class MapDemo(QMainWindow):
    def __init__(self, *args):
        QMainWindow.__init__(self, *args)
        self.plot = QwtPlot(self)
        self.plot.setTitle("A Simple Map Demonstration")
        self.plot.setCanvasBackground(Qt.white)
        self.plot.setAxisTitle(QwtPlot.xBottom, "x")
        self.plot.setAxisTitle(QwtPlot.yLeft, "y")
        self.plot.setAxisScale(QwtPlot.xBottom, 0.0, 1.0)
        self.plot.setAxisScale(QwtPlot.yLeft, 0.0, 1.0)
        self.setCentralWidget(self.plot)
        # Initialize map data
        self.count = self.i = 1000
        self.xs = np.zeros(self.count, np.float)
        self.ys = np.zeros(self.count, np.float)
        self.kappa = 0.2
        self.curve = QwtPlotCurve("Map")
        self.curve.attach(self.plot)
        self.curve.setSymbol(
            QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.red), QPen(Qt.blue),
                      QSize(5, 5)))
        self.curve.setPen(QPen(Qt.cyan))
        toolBar = QToolBar(self)
        self.addToolBar(toolBar)
        # 1 tick = 1 ms, 10 ticks = 10 ms (Linux clock is 100 Hz)
        self.ticks = 10
        self.tid = self.startTimer(self.ticks)
        self.timer_tic = None
        self.user_tic = None
        self.system_tic = None
        self.plot.replot()

    def setTicks(self, ticks):
        self.i = self.count
        self.ticks = int(ticks)
        self.killTimer(self.tid)
        self.tid = self.startTimer(ticks)

    def resizeEvent(self, event):
        self.plot.resize(event.size())
        self.plot.move(0, 0)

    def moreData(self):
        if self.i == self.count:
            self.i = 0
            self.x = random.random()
            self.y = random.random()
            self.xs[self.i] = self.x
            self.ys[self.i] = self.y
            self.i += 1
            chunks = []
            self.timer_toc = time.time()
            if self.timer_tic:
                chunks.append("wall: %s s." %
                              (self.timer_toc - self.timer_tic))
                print(' '.join(chunks))
            self.timer_tic = self.timer_toc
        else:
            self.x, self.y = standard_map(self.x, self.y, self.kappa)
            self.xs[self.i] = self.x
            self.ys[self.i] = self.y
            self.i += 1

    def timerEvent(self, e):
        self.moreData()
        self.curve.setData(self.xs[:self.i], self.ys[:self.i])
        self.plot.replot()
Beispiel #3
0
class MapDemo(QMainWindow):
    def __init__(self, *args):
        QMainWindow.__init__(self, *args)
        self.plot = QwtPlot(self)
        self.plot.setTitle("A Simple Map Demonstration")
        self.plot.setCanvasBackground(Qt.white)
        self.plot.setAxisTitle(QwtPlot.xBottom, "x")
        self.plot.setAxisTitle(QwtPlot.yLeft, "y")    
        self.plot.setAxisScale(QwtPlot.xBottom, 0.0, 1.0)
        self.plot.setAxisScale(QwtPlot.yLeft, 0.0, 1.0)
        self.setCentralWidget(self.plot)
        # Initialize map data
        self.count = self.i = 1000
        self.xs = np.zeros(self.count, np.float)
        self.ys = np.zeros(self.count, np.float)
        self.kappa = 0.2
        self.curve = QwtPlotCurve("Map")
        self.curve.attach(self.plot)
        self.curve.setSymbol(QwtSymbol(QwtSymbol.Ellipse,
                                           QBrush(Qt.red),
                                           QPen(Qt.blue),
                                           QSize(5, 5)))
        self.curve.setPen(QPen(Qt.cyan))
        toolBar = QToolBar(self)
        self.addToolBar(toolBar)
        # 1 tick = 1 ms, 10 ticks = 10 ms (Linux clock is 100 Hz)
        self.ticks = 10
        self.tid = self.startTimer(self.ticks)
        self.timer_tic = None
        self.user_tic = None
        self.system_tic = None    
        self.plot.replot()

    def setTicks(self, ticks):
        self.i = self.count
        self.ticks = int(ticks)
        self.killTimer(self.tid)
        self.tid = self.startTimer(ticks)
        
    def resizeEvent(self, event):
        self.plot.resize(event.size())
        self.plot.move(0, 0)

    def moreData(self):
        if self.i == self.count:
            self.i = 0
            self.x = random.random()
            self.y = random.random()
            self.xs[self.i] = self.x
            self.ys[self.i] = self.y
            self.i += 1
            chunks = []
            self.timer_toc = time.time()
            if self.timer_tic:
                chunks.append("wall: %s s." % (self.timer_toc-self.timer_tic))
                print(' '.join(chunks))
            self.timer_tic = self.timer_toc
        else:
            self.x, self.y = standard_map(self.x, self.y, self.kappa)
            self.xs[self.i] = self.x
            self.ys[self.i] = self.y
            self.i += 1
        
    def timerEvent(self, e):
        self.moreData()
        self.curve.setData(self.xs[:self.i], self.ys[:self.i])
        self.plot.replot()
Beispiel #4
0
class FermentGraph(QWidget):
    _logname = 'FermentGraphGeneric'
    _log = logging.getLogger(f'{_logname}')

    def __init__(self, database, parent=None):
        super().__init__(parent)
        self.db = database
        self.updateTimer = QTimer(self)
        self.updateTimer.start(5000)

        self.plot = QwtPlot()
        self.curve = QwtPlotCurve()
        self.curve.attach(self.plot)
        self.plot.resize(1000, 1000)
        self.plot.show()
        self.plot.setAxisScaleDraw(QwtPlot.xBottom, DateTimeTimeScaleDraw())

        axisFont = QFont("Helvetica", 11, QFont.Bold)
        titleFont = QFont("Helvetica", 12, QFont.Bold)

        xTitle = QwtText()
        xTitle.setText("Time")
        xTitle.setFont(axisFont)
        self.plot.setAxisTitle(self.plot.xBottom, xTitle)

        self.yTitle = QwtText()
        self.yTitle.setFont(axisFont)
        self.plot.setAxisTitle(self.plot.yLeft, self.yTitle)

        self.titleText = QwtText()
        self.titleText.setFont(titleFont)
        self.plot.setTitle(self.titleText)

        mainLayout = QHBoxLayout()
        mainLayout.addWidget(self.plot)
        self.setLayout(mainLayout)

        self.plot.show()
        self.results = []
        self.batchID = None

    def updatePlot(self, variable):
        if self.batchID is not None:
            self.db.flushTables()
            sql = f"SELECT TimeStamp, {variable} FROM Ferment WHERE BatchID = '{self.batchID}'"

            timestamps = []
            self.results = []
            for data in self.db.custom(sql)[1:]:
                timestamps.append(data[0])
                self.results.append(data[1])

            startTime = timestamps[0]
            for i in range(len(timestamps)):
                timestamps[i] = (timestamps[i] - startTime).seconds

            # self.plot.setAxisScaleDraw(QwtPlot.xBottom, TimeScaleDraw())

            self.curve.setData(timestamps, self.results)
            self.plot.replot()
            self.plot.show()

    def changeTank(self, tankID):
        self.titleText.setText(f"Fermentation Tank: {tankID}")
class TabGraph(QWidget):

    _logname = 'TabGraph'
    _log = logging.getLogger(f'{_logname}')

    ##TabGraph constructor
    #
    #Create the graph and accompanying buttons
    def __init__(self, db, parent=None):
        super().__init__(parent)
        # self.LOGIN = LOGIN
        # self.db = dataBase(self.LOGIN, "Brewing")
        self.db = db
        self.dataY = np.zeros(0)
        self.dataX = np.linspace(0, len(self.dataY), len(self.dataY))

        self.count = 0
        self.timeLabel = QLabel("Timer:")
        self.timeLabel.setAlignment(QtCore.Qt.AlignRight)

        self.tempLabel = QLabel("Temp:")
        self.tempLabel.setAlignment(QtCore.Qt.AlignRight)

        self.targetTemp = QLabel("Set Temp:")
        self.targetTime = QLabel("Set Time:")

        self.targetTimeLabel = QLabel("Target: ")
        self.targetTimeLabel.setAlignment(QtCore.Qt.AlignRight)
        self.targetTempLabel = QLabel("Target: ")
        self.targetTempLabel.setAlignment(QtCore.Qt.AlignRight)

        self.startButton = QPushButton()
        self.stopButton = QPushButton()

        self.plot = QwtPlot()
        self.curve = QwtPlotCurve()
        self.curve.attach(self.plot)
        self.plot.resize(1000, 1000)
        self.plot.replot()
        self.plot.show()

        axisFont = QFont("Helvetica", 11, QFont.Bold)
        titleFont = QFont("Helvetica", 12, QFont.Bold)

        xTitle = QwtText()
        xTitle.setText("Time")
        xTitle.setFont(axisFont)
        self.plot.setAxisTitle(self.plot.xBottom, xTitle)
        yTitle = QwtText()
        yTitle.setText(f"Temperature {DEGREESC}")
        yTitle.setFont(axisFont)
        self.plot.setAxisTitle(self.plot.yLeft, yTitle)

        self.tempStatusLED = QLed(self,
                                  onColour=QLed.Green,
                                  offColour=QLed.Red,
                                  shape=QLed.Circle)
        self.tempStatusLED.value = False
        self.tempStatusLED.setMaximumSize(25, 25)

        self.timeStatusLED = QLed(self,
                                  onColour=QLed.Green,
                                  offColour=QLed.Red,
                                  shape=QLed.Circle)
        self.timeStatusLED.value = False
        self.timeStatusLED.setMaximumSize(25, 25)

        self.recipeGrid = QGridLayout()
        self.recipeGrid.addWidget(QLabel(f"Recipe:"), 0, 0)
        self.recipeGrid.addWidget(QLabel(f"{self.recipedata['recipeName']}"),
                                  0, 1)
        self.recipeGrid.addWidget(QHLine(), 1, 0, 1, 2)
        self.recipeGrid.addWidget(self.targetTemp)
        self.recipeGrid.addWidget(self.targetTempLabel)
        self.recipeGrid.addWidget(self.targetTime)
        self.recipeGrid.addWidget(self.targetTimeLabel)
        self.recipeGrid.addWidget(QHLine(), 4, 0, 1, 2)

        self.tempLayout = QHBoxLayout()
        # self.tempLayout.addWidget(self.targetTempLabel)
        # self.tempLayout.addStretch(10)
        self.tempLayout.addWidget(self.tempLabel)
        # self.tempLayout.addStretch(10)
        self.tempLayout.addWidget(self.tempStatusLED)
        self.tempLayout.addStretch(10)

        self.timeLayout = QHBoxLayout()
        # self.timeLayout.addWidget(self.targetTimeLabel)
        # self.timeLayout.addStretch(10)
        self.timeLayout.addWidget(self.timeLabel)
        # self.timeLayout.addStretch(10)
        self.timeLayout.addWidget(self.timeStatusLED)
        self.timeLayout.addStretch(10)

        self.plotLayout = QVBoxLayout()
        self.plotLayout.addLayout(self.timeLayout)
        # self.plotLayout.addStretch(10)
        self.plotLayout.addLayout(self.tempLayout)
        # self.plotLayout.addStretch(10)
        self.plotLayout.addWidget(self.plot)

        self.buttonLayout = QVBoxLayout()
        self.buttonLayout.addWidget(self.startButton)
        self.buttonLayout.addWidget(self.stopButton)
        self.buttonLayout.addLayout(self.recipeGrid)
        self.buttonLayout.addStretch(100)

        mainLayout = QHBoxLayout()
        mainLayout.addLayout(self.buttonLayout)
        mainLayout.addLayout(self.plotLayout)

        vLayout = QVBoxLayout(self)
        vLayout.addLayout(mainLayout)

        self.minuteTimer = QTimer(self)
        self.minuteTimer.timeout.connect(lambda: self.addTimer(60))

    ##Keep track of the timer
    def addTimer(self, seconds):
        self.count += seconds

    ##convery the time from seconds to hours/minutes
    def display_time(self, seconds, granularity=2):
        result = []
        for name, count in TIME_INTERVALS:
            value = seconds // count
            if value:
                seconds -= value * count
                if value == 1:
                    name = name.rstrip('s')
                result.append("{} {}".format(value, name))
        return ', '.join(result[:granularity])