Пример #1
0
    def __init__(self):
        super(StockDetailWindowImproved, self).__init__()

        #cs通信
        self.client_model = ClientModel.getInstance()

        #数据本地化,查看是否需要请求服务器
        if os.path.exists("stock_detail_local.txt"):
            file_mdate = datetime.datetime.fromtimestamp(
                os.path.getmtime("stock_detail_local.txt"))
            today = datetime.datetime.today()
            if (file_mdate.year, file_mdate.month,
                    file_mdate.day) == (today.year, today.month, today.day):
                with open("stock_detail_local.txt", "r") as f:
                    lines = f.readlines()
                    self.data = list(map(lambda x: x.split('\t')[0:4], lines))
            else:
                self.data = self.client_model.query_stock_detail()
                #持久化到本地
                with open("stock_detail_local.txt", "w") as f:
                    f_lines = map(
                        lambda x: '\t'.join(list(map(lambda y: str(y), x))) +
                        '\t\n', self.data)
                    f.writelines(f_lines)
        else:
            self.data = self.client_model.query_stock_detail()
            #持久化到本地
            with open("stock_detail_local.txt", "w") as f:
                f_lines = map(
                    lambda x: '\t'.join(list(map(lambda y: str(y), x))) +
                    '\t\n', self.data)
                f.writelines(f_lines)

        self.draw()
Пример #2
0
    def __init__(self, parent=None):
        '''
        initialize object

        Args:
            parent: parent widget
        '''
        super(LoginWidget, self).__init__(parent)

        self.client_model = ClientModel.getInstance()

        #self.logger = MyLogger().get_logger()

        #self.setGeometry(QtCore.QRect(80, 40, 631, 471))

        #垂直布局
        self.main_layout = QtWidgets.QVBoxLayout(self)
        self.main_layout.setContentsMargins(0, 0, 0, 0)
        self.main_layout.setSpacing(0)

        #将图片插入垂直布局
        self.pic_label = QtWidgets.QLabel(self)
        pic = QtGui.QPixmap("login_pic.jpg")
        self.pic_label.setPixmap(pic)
        self.pic_label.setScaledContents(True)
        self.main_layout.addWidget(self.pic_label)

        #登陆网格布局
        self.grid_layout = QtWidgets.QGridLayout()
        self.grid_layout.setVerticalSpacing(0)
        self.grid_layout.setContentsMargins(10, -1, 10, -1)
        self.grid_layout.setVerticalSpacing(10)
        self.user_name_edit = QtWidgets.QLineEdit(self)  #账号输入行
        self.user_name_edit.setObjectName("user_name_edit")
        self.grid_layout.addWidget(self.user_name_edit, 0, 1, 1, 1)
        self.label_2 = QtWidgets.QLabel(self)  #账号标签
        self.label_2.setObjectName("label_2")
        self.grid_layout.addWidget(self.label_2, 1, 0, 1, 1)
        self.label = QtWidgets.QLabel(self)  #密码标签
        self.label.setObjectName("label")
        self.grid_layout.addWidget(self.label, 0, 0, 1, 1)
        self.password_edit = QtWidgets.QLineEdit(self)  #密码输入行
        self.password_edit.setObjectName("password_edit")
        self.password_edit.setEchoMode(QtWidgets.QLineEdit.Password)
        self.grid_layout.addWidget(self.password_edit, 1, 1, 1, 1)
        #将登陆网格加入垂直布局
        self.login_groupbox = QtWidgets.QGroupBox(self)
        self.login_groupbox.setLayout(self.grid_layout)
        self.main_layout.addWidget(self.login_groupbox)
        #将登陆按钮插入垂直布局
        self.login_btn = QtWidgets.QPushButton(self)
        self.login_btn.setObjectName("login_btn")
        self.main_layout.addWidget(self.login_btn)
        #登陆按钮按下事件连接
        self.login_btn.clicked.connect(self.loginBtnClicked)
        #设置显示文本
        self.label_2.setText("密码")
        self.label.setText("用户名")
        self.login_btn.setText("登陆")
Пример #3
0
def main():
    args = getArgs()
    hook = sy.TorchHook(torch)
    SyftWorker = WebsocketClientWorker if not args.use_virtual else VirtualWorker

    worker_kwargs = {
        'host': 'localhost',
        'hook': hook,
        'verbose': args.verbose
    }
    worker_ports = (8777, 8778, 8779)
    worker_ids = ('alice', 'bob', 'charlie')

    print("Creating Workers...")
    workers = createWorkers(SyftWorker,
                            worker_ports=worker_ports,
                            worker_ids=worker_ids,
                            worker_kwargs=worker_kwargs)

    use_cuda = torch.cuda.is_available() and args.use_cuda
    print("Using Cuda:", use_cuda)

    torch.manual_seed(args.seed)

    device = torch.device('cuda' if use_cuda else 'cpu')

    model = ClientModel().to(device)

    federated_train_loader = client_dataset.GetTrainLoader(workers, args)
    test_loader = client_dataset.GetTestLoader(workers, args)

    for epoch in range(args.epochs):
        mylogger.logger.info("Epoch %s/%s", epoch, args.epochs)

        model = Federator.FederatedTrainer(model,
                                           device,
                                           federated_train_loader,
                                           args.lr,
                                           fed_after_n_batches=25)
        Federator.test(model, device, test_loader)

    if args.save_model:
        torch.save(model.state_dict(), "fed_model.pt")
Пример #4
0
    def setup_ui(self, MainWindow):
        '''
        ui创建及连接

        Args:
            MainWindow:QMainWindow type, used as application main window
        '''
        #client单例
        self.client_model = ClientModel.getInstance()
        #断线重连
        self.live_check = LiveCheck()
        self.live_check.drop_out.connect(self.show_dialog)
        self.live_check.reconnect_succeed.connect(self.show_dialog)
        self.live_check.reconnect_failed.connect(self.show_dialog)
        self.live_check.start()

        #主窗口
        self.MainWindow = MainWindow
        self.MainWindow.setObjectName("MainWindow")
        self.MainWindow.resize(350, 250)

        #主界面设置为栈堆积,用于切换窗口
        self.stack = QtWidgets.QStackedWidget(self.MainWindow)

        #登陆界面
        self.loginWidget = LoginWidget(self.stack)
        #将登陆界面加入堆积窗口
        self.stack.addWidget(self.loginWidget)

        #建立股票列表界面
        self.list_view = StockListView(self.stack)
        #将股票列表与登陆界面链接,用于实现跳转时加载列表
        self.loginWidget.set_list(self.list_view)
        #将股票列表界面加入堆积窗口
        self.stack.addWidget(self.list_view)

        #建立tab界面垂直布局
        self.tab_view = TabView(self.stack)
        #将tab与股票列表链接, 实现双击时加载tab界面
        self.list_view.set_tab(self.tab_view)
        #将tab界面加入堆积窗口
        self.stack.addWidget(self.tab_view)

        #堆积窗口设为中央组件
        self.MainWindow.setCentralWidget(self.stack)

        #顶部栏
        self.menubar = QtWidgets.QMenuBar(self.MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 22))
        self.MainWindow.setMenuBar(self.menubar)

        #设置各组件名称显示
        self.MainWindow.setWindowTitle("狂赌之渊")
        QtCore.QMetaObject.connectSlotsByName(self.MainWindow)
Пример #5
0
    def __init__(self, parent=None):
        '''
        initializing

        Args:
            parent: parent widget
        '''
        super(StockDetail, self).__init__(parent)

        self.client_model = ClientModel.getInstance()

        self.grid_layout = QtWidgets.QGridLayout(self)
        self.grid_layout.setContentsMargins(0, 0, 0, 0)

        self.stock_detail_now = None
Пример #6
0
 def __init__(self, parent):
     QtWidgets.QTreeView.__init__(self, parent=parent)
     #cs通信
     self.client_model = ClientModel.getInstance()
     #log
     #self.logger = MyLogger().get_logger()
     #建立股票列表界面
     self.list_model = QtGui.QStandardItemModel(0, 2, parent)
     self.setModel(self.list_model)
     #自动排序
     #self.setSortingEnabled(True)
     #载入列表内容
     #self.loadData()
     #设置delegate
     self.setItemDelegate(ListDelegate())
     #设置背景颜色为黑色
     self.setStyleSheet(
         "QHeaderView{background:#303030;color:white}QTreeView{background:black}"
     )
Пример #7
0
    def __init__(self, stock_info):
        super().__init__()
        #cs通信
        self.client_model = ClientModel.getInstance()
        #log
        #self.logger = MyLogger().get_logger()
        #默认stock code: 600519
        self.stock_code = stock_info[0]

        self.setWindowTitle("A股股票历史走势K线图")
        self.main_widget = QtWidgets.QWidget() # 创建一个主部件
        self.main_layout = QtWidgets.QGridLayout() # 创建一个网格布局
        self.main_widget.setLayout(self.main_layout) # 设置主部件的布局为网格
        self.setCentralWidget(self.main_widget) # 设置窗口默认部件

        self.info_header = QtWidgets.QLineEdit() # 创建一个股票代码显示
        self.info_header.setReadOnly(True)
        self.info_header.setText('股票代码:'+stock_info[0]+'  股票名称:'+stock_info[1])
        self.option_sel = QtWidgets.QComboBox() # 创建一个下拉框部件
        self.option_sel.addItem("近60天")
        self.option_sel.addItem("近180天")
        self.option_sel.addItem("近360天")
        self.que_btn = QtWidgets.QPushButton("查询") # 创建一个按钮部件
        self.k_widget = QtWidgets.QWidget() # 实例化一个widget部件作为K线图部件
        self.k_layout = QtWidgets.QGridLayout() # 实例化一个网格布局层
        self.k_widget.setLayout(self.k_layout) # 设置K线图部件的布局层
        self.k_plt_window = pg.GraphicsWindow()
        self.label = pg.LabelItem()
        #self.label.setFixedWidth(300)
        self.k_plt_window.addItem(self.label)
        self.k_plt = pg.PlotItem() # 实例化一个绘图部件
        self.k_plt_window.addItem(self.k_plt, row = 1, col = 0)
        self.k_layout.addWidget(self.k_plt_window) # 添加绘图部件到K线图部件的网格布局层

        # 将上述部件添加到布局层中
        self.main_layout.setContentsMargins(0, 0, 0, 0)
        self.main_layout.addWidget(self.info_header,0,0,1,1)
        self.main_layout.addWidget(self.option_sel,0,1,1,1)
        self.main_layout.addWidget(self.que_btn,0,2,1,1)
        self.main_layout.addWidget(self.k_widget,1,0,3,3)
        
        self.que_btn.clicked.connect(self.query_slot) # 绑定按钮点击信号
Пример #8
0
 def __init__(self, parent=None):
     super(StockListView, self).__init__(parent)
     #cs通信
     self.client_model = ClientModel.getInstance()
     #log
     #self.logger = MyLogger().get_logger()
     #建立股票列表界面垂直布局
     self.setGeometry(QtCore.QRect(80, 40, 631, 471))
     self.layout = QtWidgets.QVBoxLayout(self)
     self.layout.setContentsMargins(0, 0, 0, 0)
     self.setLayout(self.layout)
     #建立股票列表界面
     self.list_view = StockListWidget(self)
     #设置双击事件
     self.list_view.doubleClicked.connect(self.double_clicked)
     #将list_view加入垂直布局
     self.layout.addWidget(self.list_view)
     #返回按钮
     self.list_view_Btn = QtWidgets.QPushButton(self)
     self.list_view_Btn.clicked.connect(self.clicked)
     self.list_view_Btn.setText("退出账号")
     self.layout.addWidget(self.list_view_Btn)
Пример #9
0
        #建立tab界面
        self.tab_widget = QtWidgets.QTabWidget(self)
        self.layout.addWidget(self.tab_widget)
        self.kline_widget = KLine(self.tab_widget)
        self.stock_detail_widget = StockDetail(self.tab_widget)
        self.tab_widget.addTab(self.kline_widget, u"K线图")
        self.tab_widget.addTab(self.stock_detail_widget, u"股票行情")

        #返回按钮
        self.return_btn = QtWidgets.QPushButton(self)
        self.return_btn.clicked.connect(
            lambda: self.parentWidget().setCurrentIndex(1))
        self.return_btn.setText("返回")
        self.layout.addWidget(self.return_btn)

    def lazy_load(self, stock_info):
        '''
        load k-line graph and stock detail graph only when double clicked stock list

        Args:
            stock_info: stock info in stock list, format: [stock_code(str), stock_name(str)]
        '''
        self.kline_widget.load_kline(stock_info)
        self.stock_detail_widget.load_stock_detail()


if __name__ == '__main__':
    app = QtWidgets.QApplication([])
    t = TabView(ClientModel(), "600519 大唐控股")
    t.show()
    app.exec_()
Пример #10
0
            self.hLine_p2.setPos(mousePoint.y())

    def mouseMoved_p2(self, evt):
        '''
        鼠标移动事件
        '''
        pos = evt[
            0]  ## using signal proxy turns original arguments into a tuple
        if self.p2.sceneBoundingRect().contains(pos):
            mousePoint = self.p2.getPlotItem().vb.mapSceneToView(pos)
            index = int(mousePoint.x())
            if index > 0 and index < len(self.y1):
                self.label.setText(
                    "<span style='font-size: 12pt'>时间=%s</span>, <span style='color: white'>当前价=%0.3f</span>, <span style='color: yellow'>成交量=%d</span>, <span style='color: yellow'>均价=%0.3f</span>"
                    % (time.strftime('%H:%M:%S',
                                     time.localtime(self.seconds[index])),
                       self.y1[index], self.y3[index], self.y2[index]))
            self.vLine.setPos(mousePoint.x())
            self.hLine.setPos(mousePoint.y())
            self.vLine_p2.setPos(mousePoint.x())
            self.hLine_p2.setPos(mousePoint.y())


if __name__ == "__main__":
    app = QtWidgets.QApplication([])
    client_model = ClientModel()
    client_model.login("admin", "123456")
    win = StockDetailWindowImproved()
    win.resize(1000, 600)
    win.show()
    app.exec_()