Beispiel #1
0
    def init_ui(self):
        """"""
        self.setWindowTitle("参数优化结果")
        self.resize(1100, 500)

        table = QtWidgets.QTableWidget()

        table.setColumnCount(2)
        table.setRowCount(len(self.result_values))
        table.setHorizontalHeaderLabels(["参数", self.target_display])
        table.setEditTriggers(table.NoEditTriggers)
        table.verticalHeader().setVisible(False)

        table.horizontalHeader().setSectionResizeMode(
            0, QtWidgets.QHeaderView.ResizeToContents
        )
        table.horizontalHeader().setSectionResizeMode(
            1, QtWidgets.QHeaderView.Stretch
        )

        for n, tp in enumerate(self.result_values):
            setting, target_value, _ = tp
            setting_cell = QtWidgets.QTableWidgetItem(str(setting))
            target_cell = QtWidgets.QTableWidgetItem(str(target_value))

            setting_cell.setTextAlignment(QtCore.Qt.AlignCenter)
            target_cell.setTextAlignment(QtCore.Qt.AlignCenter)

            table.setItem(n, 0, setting_cell)
            table.setItem(n, 1, target_cell)

        vbox = QtWidgets.QVBoxLayout()
        vbox.addWidget(table)

        self.setLayout(vbox)
Beispiel #2
0
    def get_algo_cells(self, algo_name: str):
        """"""
        cells = self.algo_cells.get(algo_name, None)

        if not cells:
            stop_func = partial(self.stop_algo, algo_name=algo_name)
            stop_button = QtWidgets.QPushButton("停止")
            stop_button.clicked.connect(stop_func)

            name_cell = QtWidgets.QTableWidgetItem(algo_name)
            parameters_cell = QtWidgets.QTableWidgetItem()
            variables_cell = QtWidgets.QTableWidgetItem()

            self.insertRow(0)
            self.setCellWidget(0, 0, stop_button)
            self.setItem(0, 1, name_cell)
            self.setItem(0, 2, parameters_cell)
            self.setItem(0, 3, variables_cell)

            cells = {
                "name": name_cell,
                "parameters": parameters_cell,
                "variables": variables_cell
            }
            self.algo_cells[algo_name] = cells

        return cells
Beispiel #3
0
    def get_setting_cells(self, setting_name: str):
        """"""
        cells = self.setting_cells.get(setting_name, None)

        if not cells:
            use_func = partial(self.use_setting, setting_name=setting_name)
            use_button = QtWidgets.QPushButton("使用")
            use_button.clicked.connect(use_func)

            remove_func = partial(self.remove_setting,
                                  setting_name=setting_name)
            remove_button = QtWidgets.QPushButton("移除")
            remove_button.clicked.connect(remove_func)

            name_cell = QtWidgets.QTableWidgetItem(setting_name)
            setting_cell = QtWidgets.QTableWidgetItem()

            self.insertRow(0)
            self.setCellWidget(0, 0, use_button)
            self.setCellWidget(0, 1, remove_button)
            self.setItem(0, 2, name_cell)
            self.setItem(0, 3, setting_cell)

            cells = {"name": name_cell, "setting": setting_cell}
            self.setting_cells[setting_name] = cells

        return cells
Beispiel #4
0
    def init_ui(self):
        """"""
        self.setWindowTitle("回测每日明细")
        self.resize(1300, 800)

        table = QtWidgets.QTableWidget()

        table.setColumnCount(18)
        table.setRowCount(len(self.daily_df))
        table.setHorizontalHeaderLabels(self.daily_df.columns)
        table.setVerticalHeaderLabels(str(i) for i in self.daily_df.index)
        table.verticalHeader().setVisible(True)

        for r, (d, s) in enumerate(self.daily_df.iterrows()):
            for c, (t, v) in enumerate(s.items()):
                if t == 'trades':
                    cell = QtWidgets.QTableWidgetItem("交易明细")
                    cell.setFlags(QtCore.Qt.ItemIsSelectable
                                  | QtCore.Qt.ItemIsEnabled)
                else:
                    cell = QtWidgets.QTableWidgetItem(str(v))
                    cell.setFlags(QtCore.Qt.ItemIsEnabled)

                cell.setTextAlignment(QtCore.Qt.AlignCenter)
                table.setItem(r, c, cell)

        table.itemDoubleClicked.connect(self.show_trade_data)

        vbox = QtWidgets.QVBoxLayout()
        vbox.addWidget(table)

        self.setLayout(vbox)
Beispiel #5
0
    def process_log_event(self, event):
        """"""
        msg = event.data
        timestamp = datetime.now().strftime("%H:%M:%S")

        timestamp_cell = QtWidgets.QTableWidgetItem(timestamp)
        msg_cell = QtWidgets.QTableWidgetItem(msg)

        self.insertRow(0)
        self.setItem(0, 0, timestamp_cell)
        self.setItem(0, 1, msg_cell)
Beispiel #6
0
 def updateLogTriggerHandler(self, log):
     # print("append task log emite triggered!", log);
     # self.logDisplay.append(log)
     if log and log.strip():
         rowCount = self.logDisplay.rowCount()
         newItem1 = QtWidgets.QTableWidgetItem(log)
         newItem2 = QtWidgets.QTableWidgetItem("QA_SU_save_stock_list")
         self.logDisplay.setRowCount(rowCount + 1)
         self.logDisplay.setItem(rowCount, 0, newItem1)
         self.logDisplay.setItem(rowCount, 1, newItem2)
         # self.logDisplay.scrollToBottom()
     pass
Beispiel #7
0
    def outputWritten(self, text):
        # 🛠todo logDisplay QTableWidget
        # cursor = self.logDisplay.textCursor()
        # cursor.movePosition(QtGui.QTextCursor.End)
        # cursor.insertText(text)
        # self.logDisplay.setTextCursor(cursor)
        # self.logDisplay.ensureCursorVisible()
        if text and text.strip():
            rowCount = self.logDisplay.rowCount()
            newItem1 = QtWidgets.QTableWidgetItem(text)
            newItem2 = QtWidgets.QTableWidgetItem("stdout/stderr")

            self.logDisplay.setRowCount(rowCount + 1)
            self.logDisplay.setItem(rowCount, 0, newItem1)
            self.logDisplay.setItem(rowCount, 1, newItem2)
            self.logDisplay.scrollToBottom()
Beispiel #8
0
    def init_ui(self):
        """"""
        self.setWindowTitle(f"{self.daily_trade_result.name}交易明细")
        self.resize(1100, 500)

        table = QtWidgets.QTableWidget()
        fields = self.trade_values[0].__dataclass_fields__
        table.setColumnCount(len(fields))
        table.setRowCount(len(self.trade_values))
        table.setHorizontalHeaderLabels(fields.keys())
        table.verticalHeader().setVisible(False)

        for r, tradeData in enumerate(self.trade_values):
            for c, k in enumerate(fields.keys()):
                v = getattr(tradeData, k)
                if isinstance(v, Enum):
                    v = v.value
                cell = QtWidgets.QTableWidgetItem(str(v))
                cell.setFlags(QtCore.Qt.ItemIsEnabled)

                cell.setTextAlignment(QtCore.Qt.AlignCenter)
                table.setItem(r, c, cell)

        table.doubleClicked.connect(self.visulize)
        vbox = QtWidgets.QVBoxLayout()
        vbox.addWidget(table)

        self.setLayout(vbox)
Beispiel #9
0
    def init_ui(self):
        """"""
        self.setWindowTitle("参数优化结果")
        self.resize(1100, 500)

        # Creat table to show result
        table = QtWidgets.QTableWidget()

        table.setColumnCount(2)
        table.setRowCount(len(self.result_values))
        table.setHorizontalHeaderLabels(["参数", self.target_display])
        table.setEditTriggers(table.NoEditTriggers)
        table.verticalHeader().setVisible(False)

        table.horizontalHeader().setSectionResizeMode(
            0, QtWidgets.QHeaderView.ResizeToContents
        )
        table.horizontalHeader().setSectionResizeMode(
            1, QtWidgets.QHeaderView.Stretch
        )

        for n, tp in enumerate(self.result_values):
            setting, target_value, _ = tp
            setting_cell = QtWidgets.QTableWidgetItem(str(setting))
            target_cell = QtWidgets.QTableWidgetItem(f"{target_value:.2f}")

            setting_cell.setTextAlignment(QtCore.Qt.AlignCenter)
            target_cell.setTextAlignment(QtCore.Qt.AlignCenter)

            table.setItem(n, 0, setting_cell)
            table.setItem(n, 1, target_cell)

        # Create layout
        button = QtWidgets.QPushButton("保存")
        button.clicked.connect(self.save_csv)

        hbox = QtWidgets.QHBoxLayout()
        hbox.addStretch()
        hbox.addWidget(button)

        vbox = QtWidgets.QVBoxLayout()
        vbox.addWidget(table)
        vbox.addLayout(hbox)

        self.setLayout(vbox)
Beispiel #10
0
    def init_ui(self):
        """"""
        self.setRowCount(len(self.KEY_NAME_MAP))
        self.setVerticalHeaderLabels(list(self.KEY_NAME_MAP.values()))

        self.setColumnCount(1)
        self.horizontalHeader().setVisible(False)
        self.horizontalHeader().setSectionResizeMode(
            QtWidgets.QHeaderView.Stretch)

        for row, key in enumerate(self.KEY_NAME_MAP.keys()):
            cell = QtWidgets.QTableWidgetItem()
            self.setItem(row, 0, cell)
            self.cells[key] = cell
Beispiel #11
0
 def init_ui(self):
     """"""
     self.setRowCount(len(self.KEY_NAME_MAP))
     self.setVerticalHeaderLabels(list(self.KEY_NAME_MAP.values()))
     # 设置表格除标题以外的列数,并让数字作为列名
     self.setColumnCount(1)
     # 设置数字列名不可见
     self.horizontalHeader().setVisible(False)
     # 自适应布局的大小
     self.horizontalHeader().setSectionResizeMode(
         QtWidgets.QHeaderView.Stretch
     )
     self.setEditTriggers(self.NoEditTriggers)
     # 每一行根据表名绑定一个Item
     for row, key in enumerate(self.KEY_NAME_MAP.keys()):
         cell = QtWidgets.QTableWidgetItem()
         self.setItem(row, 0, cell)
         self.cells[key] = cell
Beispiel #12
0
    def init_ui(self):
        """"""
        labels = list(self._data.keys())
        self.setColumnCount(len(labels))
        self.setHorizontalHeaderLabels(labels)

        self.setRowCount(1)
        self.verticalHeader().setSectionResizeMode(
            QtWidgets.QHeaderView.Stretch)
        self.verticalHeader().setVisible(False)
        self.setEditTriggers(self.NoEditTriggers)

        for column, name in enumerate(self._data.keys()):
            value = self._data[name]

            cell = QtWidgets.QTableWidgetItem(str(value))
            cell.setTextAlignment(QtCore.Qt.AlignCenter)

            self.setItem(0, column, cell)
            self.cells[name] = cell