Esempio n. 1
0
    def buttonOpenClicked(self):
        fileDialog = QFileDialog(
            self, "打开历史数据文件", QApplication.applicationDirPath() + "/../data", "Database File (*.db *.mdb)"
        )
        if fileDialog.exec_() == QDialog.Rejected:
            return
        # clear curve
        self.curveHistory.clear()
        #
        filePaths = fileDialog.selectedFiles()
        if filePaths.isEmpty():
            return
        filePath = filePaths.first()
        if filePath.isEmpty():
            return
        # open database
        if not DatabaseMgr().open(filePath):
            return
        #
        startTime = QDateTime.fromMSecsSinceEpoch(DatabaseMgr().startTime())
        endTime = QDateTime.fromMSecsSinceEpoch(DatabaseMgr().endTime())
        self.dateTimeEditStart.setDateTimeRange(startTime, endTime)
        self.dateTimeEditEnd.setDateTimeRange(startTime, endTime)
        self.dateTimeEditEnd.setDateTime(endTime)
        self.dateTimeEditStart.setDateTime(startTime)

        # title of curve
        self.curveHistory.setTitle("历史数据回放" + "(" + QFileInfo(filePath).fileName() + ")")
Esempio n. 2
0
        def addEntryFunc():
            dbobj = HistoryDbModel.select().where(
                HistoryDbModel.url == url.toString()).first()
            if dbobj:
                # update
                before = self.HistoryEntry()
                before.id = dbobj.id
                before.count = dbobj.count
                before.date = QDateTime.fromMSecsSinceEpoch(dbobj.date)
                before.url = url
                before.urlString = before.url.toEncoded().data().decode()
                before.title = dbobj.title

                after = self.HistoryEntry()
                after.id = dbobj.id
                after.count = dbobj.count + 1
                after.date = QDateTime.currentDateTime()
                after.url = url
                after.urlString = after.url.toEncoded().data().decode()
                after.title = title
                after.fillDbobj(dbobj)
                dbobj.save()

                self.historyEntryEdited.emit(before, after)
            else:
                # insert
                dbobj = HistoryDbModel.create(
                    **{
                        'count': 1,
                        'date': QDateTime.currentMSecsSinceEpoch(),
                        'url': url.toString(),
                        'title': title,
                    })
                entry = self.HistoryEntry.CreateFromDbobj(dbobj)
                self.historyEntryAdded.emit(entry)
Esempio n. 3
0
 def CreateFromDbobj(cls, dbobj):
     entry = cls()
     entry.id = dbobj.id
     entry.count = dbobj.id
     entry.date = QDateTime.fromMSecsSinceEpoch(dbobj.date)
     entry.url = QUrl(dbobj.url)
     entry.urlString = entry.url.toEncoded().data().decode()
     entry.title = dbobj.title
     return entry
Esempio n. 4
0
    def _init(self):
        from .History import History
        minTs = HistoryDbModel.select(peewee.fn.Min(
            HistoryDbModel.date)).scalar()
        if minTs <= 0:
            return

        today = QDate.currentDate()
        week = today.addDays(1 - today.dayOfWeek())
        month = QDate(today.year(), today.month(), 1)
        currentTs = QDateTime.currentMSecsSinceEpoch()

        ts = currentTs
        while ts > minTs:
            tsDate = QDateTime.fromMSecsSinceEpoch(ts).date()
            endTs = 0
            itemName = ''

            if tsDate == today:
                endTs = QDateTime(today).toMSecsSinceEpoch()
                itemName = _('Today')
            elif tsDate >= week:
                endTs = QDateTime(week).toMSecsSinceEpoch()
                itemName = _('This Week')
            elif tsDate.month() == month.month() and tsDate.year(
            ) == month.year():
                endTs = QDateTime(month).toMSecsSinceEpoch()
                itemName = _('This Month')
            else:
                startDate = QDate(tsDate.year(), tsDate.month(),
                                  tsDate.daysInMonth())
                endDate = QDate(startDate.year(), startDate.month(), 1)

                ts = QDateTime(startDate, QTime(23, 59,
                                                59)).toMSecsSinceEpoch()
                endTs = QDateTime(endDate).toMSecsSinceEpoch()
                itemName = '%s %s' % (tsDate.year(),
                                      History.titleCaseLocalizedMonth(
                                          tsDate.month()))
            dbobj = HistoryDbModel.select().where(
                HistoryDbModel.date.between(endTs, ts)).first()
            if dbobj:
                item = HistoryItem(self._rootItem)
                item.setStartTimestamp(ts == currentTs and -1 or ts)
                item.setEndTimestamp(endTs)
                item.title = itemName
                item.canFetchMore = True

                if ts == currentTs:
                    self._todayItem = item

            ts = endTs - 1
Esempio n. 5
0
 def getHistoryEntry(self, text):
     '''
     @param: text QString
     '''
     dbobj = HistoryDbModel.select().where(
         HistoryDbModel.url == text).first()
     entry = self.HistoryEntry()
     if dbobj:
         entry.count = dbobj.count
         entry.date = QDateTime.fromMSecsSinceEpoch(entry.date)
         entry.id = dbobj.id
         entry.title = dbobj.title
         entry.url = QUrl(dbobj.url)
     return entry
Esempio n. 6
0
 def mostVisited(self, count):
     '''
     @param: count int
     @return: QVector<HistoryEntry>
     '''
     result = []
     for dbobj in HistoryDbModel.select().order_by(
             HistoryDbModel.count.desc()).limit(count):
         entry = self.HistoryEntry()
         entry.count = dbobj.count
         entry.date = QDateTime.fromMSecsSinceEpoch(dbobj.date)
         entry.id = dbobj.id
         entry.title = dbobj.title
         entry.url = QUrl(dbobj.url)
         result.append(entry)
     return result
Esempio n. 7
0
 def searchHistoryEntry(self, text):
     '''
     @param: text QString
     '''
     list_ = []  # QList<HistoryEntry>
     qs = HistoryDbModel.select().where(
         HistoryDbModel.title.contains(text)
         | HistoryDbModel.url.contains(text)).limit(50)
     for item in qs:
         entry = self.HistoryEntry()
         entry.count = item.count
         entry.date = QDateTime.fromMSecsSinceEpoch(item.date)
         entry.id = item.id
         entry.title = item.title
         entry.url = QUrl(item.url)
         list_.append(entry)
     return list_
Esempio n. 8
0
    # [1]

    # [2]  load the data
    acmeData = QFile("acme_data.txt")
    if not acmeData.open(QIODevice.ReadOnly | QIODevice.Text):
        sys.exit(1)

    categories = []
    dataReader = CandlestickDataReader(acmeData)

    while not dataReader.atEnd():
        line = dataReader.read_candlestick_set()
        if line is not None:
            acmeSeries.append(line)
            categories.append(
                QDateTime.fromMSecsSinceEpoch(line.timestamp()).toString("dd"))

    # [2]

    # [3] create the chart
    chart = QChart()
    chart.addSeries(acmeSeries)
    chart.setTitle("Acme Ltd Historical Data (July 2015)")
    chart.setAnimationOptions(QChart.SeriesAnimations)
    # [3]

    # [4] set the axes properties
    chart.createDefaultAxes()
    axisX = chart.axes(Qt.Horizontal)[0]
    axisX.setCategories(categories)
Esempio n. 9
0
    def drawGridX(self, painter):
        rect = self.getRectPlotter()
        if not rect.isValid():
            return
        painter.save()

        painter.setFont(self._fontGrid)
        painter.setPen(QPen(Qt.black))
        painter.setBrush(Qt.NoBrush)

        # Axis ticks
        dxmsec = rect.width() / self._plotterScale.Scale.X.span()
        fontMetricsF = QFontMetricsF(self._fontGrid)
        index = findIndex(fontMetricsF.width('   00:00   ') / dxmsec, BasePlotter._mSecs_for_grid)
        msec0 = self._plotterScale.Scale.X.Min
        offset = findOffset(msec0, BasePlotter._mSecs_for_grid[index])
        dx = dxmsec * BasePlotter._mSecs_for_grid[index]
        step = BasePlotter._mSecs_for_grid[index]

        for x in numpy.arange(rect.left() - dxmsec * offset, rect.right(), dx):
            if x < rect.left():
                continue

            painter.save()

            heightTick = 3
            datetimelabel = QDateTime.fromMSecsSinceEpoch(msec0, Qt.UTC)

            if step >= 60000:  # больше минуты
                if step >= 86400000:  # больше суток
                    label = datetimelabel.toString('dd.MM.yy')
                    if datetimelabel.time().minute() == 0:
                        heightTick = 8
                        painter.setPen(Qt.SolidLine)
                else:
                    t0 = QDateTime.fromMSecsSinceEpoch(self._plotterScale.Scale.X.Min, Qt.UTC)
                    t1 = QDateTime.fromMSecsSinceEpoch(self._plotterScale.Scale.X.Max, Qt.UTC)
                    if (datetimelabel.time().hour() == 0 and datetimelabel.time().minute() == 0) and (
                                t1.date() > t0.date()):  # Метка даты. Появляется,если листаем график между днями
                        font = QFont(painter.font().family(), painter.font().pointSize())
                        font.setBold(True)
                        painter.setFont(font)
                        label = datetimelabel.toString('dd.MM.yy')
                    else:
                        label = datetimelabel.toString('hh:mm')
                        if datetimelabel.time().minute() == 0:
                            heightTick = 8
                            painter.setPen(Qt.SolidLine)
                        if datetimelabel.time().minute() == 30:
                            heightTick = 6
                            painter.setPen(Qt.DashLine)
                        if datetimelabel.time().minute() == 15 or datetimelabel.time().minute() == 45:
                            heightTick = 4
                            painter.setPen(Qt.DashLine)
            else:
                label = datetimelabel.time().toString('hh:mm:ss')

            painter.drawLine(x, rect.bottom(), x, rect.top())
            rect_label = QRectF(x - fontMetricsF.width(label) / 2, rect.bottom() + heightTick,
                                fontMetricsF.width(label), 2 * fontMetricsF.height())
            painter.drawLine(x, rect.bottom() - heightTick, x, rect.bottom() + heightTick)
            painter.drawText(rect_label, label)

            msec0 += step

            painter.restore()

        painter.restore()