python_PyQt5运行股票研究python方法工具V1.1_增加表格展示控件

承接 【python_PyQt5运行股票研究python方法工具V1.0】

地址 python_PyQt5运行股票研究python方法工具V1.0_程序猿与金融与科技的博客-CSDN博客

目录

 结果展示:

 代码:

示例py文件代码(计算股票日横截面数据)

参数json文件

表格控件

ExcuteShowWidget 中 process_excute_event 方法修改


 结果展示:

1 选择py文件所在目录

2 选择py文件目录后,会提起该目录下所有的py文件,放入下拉列表

3 选择要执行的方法,点击“执行”,子线程会执行对应py文件中的代码,执行完毕后会返回结果

4 返回结果为map形式,map中的key用于识别不用结果分别对应什么内容,key会在下拉列表中展示,可以通过下拉列表切换,或上一个,下一个切换表格内容

5 显示执行结果内容

 代码:

示例py文件代码(计算股票日横截面数据)

def excute_code(json_obj:dict):
    '''
    横截面股票日数据查看
    :param json_obj:
    :return:
    '''
    import pandas as pd
    import os

    code_list = json_obj['code_list']
    daily_dir = json_obj['daily_dir']
    start_date = json_obj['start_date']
    end_date = json_obj['end_date']
    # second_level {行业名:[股票代码]}
    second_level = json_obj['second_level']

    res_target_name_map = {}

    df = None
    column_list = ['ticker','tradeDate','o','c','h','l','turnoverVol','dealAmount','turnoverRate','negMarketValue','marketValue','chgPct','PE']

    for code in code_list:
        daily_file_path = daily_dir + os.path.sep + code + '.csv'
        one_df = pd.read_csv(daily_file_path,encoding='utf-8')
        one_df['o_date'] = pd.to_datetime(one_df['tradeDate'])
        one_df = one_df.loc[(one_df['o_date'] >= start_date) & (one_df['o_date'] <= end_date)].copy()
        one_df = one_df.loc[one_df['openPrice'] > 0].copy()
        one_df['o'] = one_df['openPrice'] * one_df['accumAdjFactor']
        one_df['c'] = one_df['closePrice'] * one_df['accumAdjFactor']
        one_df['h'] = one_df['highestPrice'] * one_df['accumAdjFactor']
        one_df['l'] = one_df['lowestPrice'] * one_df['accumAdjFactor']
        one_df['chgPct'] = one_df['chgPct']*100

        one_df['ticker'] = code
        one_df.sort_values(by='o_date',ascending=False,inplace=True)

        one_df = one_df.loc[:,column_list]

        if df is None:
            df = one_df
        else:
            df = pd.concat([df,one_df])
        pass

    df_group = df.groupby(by='tradeDate')
    for name,group in df_group:
        key_name = f'{name},all'
        val_data = group.loc[:,column_list].values.tolist()
        res_target_name_map[key_name] = val_data
        pass

    for key,val in second_level.items():
        df_two = df.loc[df['ticker'].isin(val)].copy()
        df_two_group = df_two.groupby(by='tradeDate')
        for name, group in df_two_group:
            key_name = f'{name},{key}'
            val_data = group.loc[:, column_list].values.tolist()
            res_target_name_map[key_name] = val_data
            pass
        pass

    target_style = 'table'
    target_data = res_target_name_map
    header_list = ['ticker','日期','开盘价','收盘价','最高价','最低价','成交量','成交笔数','日换手率','流通市值','总市值','涨跌幅','滚动市盈率']

    final_map = {
        'target_style':target_style,
        'target_header':header_list,
        'target_data':target_data
    }
    return final_map

参数json文件

{
	"code_list":["000025","000031","000058","000061","000068","000096","000410","000428","000503","000509","000514","000523","000536","000548","000557","000558","000565","000566","000599","000605","000632","000638","000652","000655","000701","000709","000727","000755","000758","000767","000797","000825","000850","000856","000878","000897","000898","000901","000912","000927","000952","000958","000960","000972","001896","002022","002037","002047","002061","002097","002106","002114","002160","002168","002183","002217","002278","002285","002305","002339","002343","002344","002354","002366","002400","002427","002431","002479","002480","002500","002522","002542","002573","002642","002659","002672","002673","002676","002682","002712","002722","002783","002807","600022","600037","600058","600076","600100","600108","600115","600119","600149","600150","600156","600169","600198","600202","600239","600249","600287","600292","600299","600300","600307","600320","600322","600343","600358","600376","600397","600403","600423","600433","600448","600526","600550","600601","600604","600617","600623","600626","600629","600630","600637","600648","600649","600650","600651","600653","600675","600676","600679","600684","600686","600692","600705","600708","600712","600716","600726","600743","600748","600758","600783","600798","600800","600805","600815","600825","600844","600855","600864","600871","600874","600880","600881","600889","600939","600959","600960","600981","600986","601016","601106","601168","601198","601368","601588","601600","601718","601727","601766","601857","601866","601918","601989","601991","603021","603169","603817","603999"],
	"daily_dir":"E:/daily/",
	"start_date":"2023-07-01",
	"end_date":"2023-08-11",
	"second_level":{"\u4ea4\u901a\u8fd0\u8f93": ["000548", "000557", "000755", "002183", "002682", "600115", "600119", "600650", "600798", "601866"], "\u4f20\u5a92": ["002343", "002354", "002400", "002712", "600037", "600358", "600637", "600825", "600959", "600986", "603999"], "\u516c\u7528\u4e8b\u4e1a": ["000767", "001896", "002479", "002480", "600149", "600617", "600726", "601016", "601991"], "\u519c\u6797\u7267\u6e14": ["000972", "600108"], "\u533b\u836f\u751f\u7269": ["000566", "000952", "002022"], "\u5546\u8d38\u96f6\u552e": ["000058", "000061", "002344", "600058", "600287", "600712", "600981"], "\u56fd\u9632\u519b\u5de5": ["600150", "601989"], "\u57fa\u7840\u5316\u5de5": ["000565", "000912", "002037", "002427", "002522", "002783", "600299", "600423", "600623", "600844", "600889"], "\u5bb6\u7528\u7535\u5668": ["002676"], "\u5efa\u7b51\u88c5\u9970": ["002047", "002061", "002431", "002542", "600629", "600939"], "\u623f\u5730\u4ea7": ["000031", "000514", "000558", "000797", "000897", "002285", "002305", "600239", "600322", "600376", "600604", "600648", "600649", "600675", "600684", "600692", "600708", "600716", "600743", "600748", "601588"], "\u6709\u8272\u91d1\u5c5e": ["000758", "000878", "000960", "002114", "002160", "601168", "601600"], "\u673a\u68b0\u8bbe\u5907": ["000410", "000856", "000927", "002097", "002278", "600169", "600202", "600320", "600343", "600783", "600815", "601106", "601766", "603169"], "\u6c7d\u8f66": ["000599", "000901", "600626", "600653", "600679", "600686", "600960"], "\u7164\u70ad": ["600397", "600403", "600758", "601918"], "\u73af\u4fdd": ["000068", "000605", "002573", "002672", "600292", "600526", "600874", "601368", "603817"], "\u7535\u529b\u8bbe\u5907": ["002168", "002339", "002366", "600550", "601727"], "\u7535\u5b50": ["000509", "000536", "000701", "000727", "002106", "002217", "600601", "600651"], "\u77f3\u6cb9\u77f3\u5316": ["000096", "600800", "600871", "601857"], "\u793e\u4f1a\u670d\u52a1": ["000428", "002659", "600880"], "\u7eba\u7ec7\u670d\u9970": ["000850", "002722", "600156", "600448", "600630", "601718"], "\u7efc\u5408": ["000025", "000632", "000652", "600676", "600805", "600881"], "\u7f8e\u5bb9\u62a4\u7406": ["000523", "600249"], "\u8ba1\u7b97\u673a": ["000503", "000638", "002642", "600100", "600855"], "\u8f7b\u5de5\u5236\u9020": ["600076", "600433", "603021"], "\u901a\u4fe1": ["600198"], "\u94a2\u94c1": ["000655", "000709", "000825", "000898", "600022", "600307"], "\u94f6\u884c": ["002807"], "\u975e\u94f6\u91d1\u878d": ["000958", "002500", "002673", "600705", "600864", "601198"], "\u98df\u54c1\u996e\u6599": ["600300"]}
}

表格控件

class TableNodeWidget(QtWidgets.QWidget):
    def __init__(self):
        super().__init__()
        self.init_data()
        self.init_ui()
        pass
    def init_data(self):
        self.whole_data:Dict = None
        self.target_name_list: List = None
        self.current_target_name: str = None
        self.please_select_str: str = '-- 请选择 --'
        pass
    def init_ui(self):
        pre_btn = QtWidgets.QPushButton('上一个')
        pre_btn.clicked.connect(self.pre_btn_clicked)
        self.target_combox = QtWidgets.QComboBox()
        self.target_combox.currentTextChanged.connect(self.target_combox_currentTextChanged)
        next_btn = QtWidgets.QPushButton('下一个')
        next_btn.clicked.connect(self.next_btn_clicked)

        layout_one = QtWidgets.QHBoxLayout()
        layout_one.addStretch(1)
        layout_one.addWidget(pre_btn)
        layout_one.addWidget(self.target_combox)
        layout_one.addWidget(next_btn)
        layout_one.addStretch(1)

        self.title_label = QtWidgets.QLabel()
        self.title_label.setAlignment(Qt.AlignCenter)
        self.title_label.setStyleSheet('QLabel{font-size:32px;font-weight:bold;}')

        tip_label = QtWidgets.QLabel('提示:最多显示500条数据')

        self.table = QtWidgets.QTableWidget()

        layout = QtWidgets.QVBoxLayout()
        layout.addLayout(layout_one)
        layout.addWidget(self.title_label)
        layout.addWidget(tip_label)
        layout.addWidget(self.table)
        self.setLayout(layout)
        pass
    def set_data(self,data:Dict):
        self.table.clear()
        self.target_combox.clear()

        header = data['header']
        self.whole_data = data['data']
        self.target_name_list = list(self.whole_data.keys())
        self.current_target_name = self.target_name_list[0]

        self.target_combox.addItem(self.please_select_str)
        self.target_combox.addItems(self.target_name_list)

        self.table.setColumnCount(len(header))
        self.table.setHorizontalHeaderLabels(header)

        self.fill_table_content()
        pass
    def fill_table_content(self):
        data = self.whole_data[self.current_target_name]
        self.title_label.setText(self.current_target_name)
        self.table.setRowCount(len(data))
        for i_r, row in enumerate(data):
            for i_c, col in enumerate(row):
                self.table.setItem(i_r, i_c, QtWidgets.QTableWidgetItem(str(col)))
        pass

    def pre_btn_clicked(self):
        cur_i = self.target_name_list.index(self.current_target_name)
        if cur_i<=0:
            cur_i = len(self.target_name_list)-1
        else:
            cur_i = cur_i -1
        self.current_target_name = self.target_name_list[cur_i]
        self.fill_table_content()
        pass
    def next_btn_clicked(self):
        cur_i = self.target_name_list.index(self.current_target_name)
        if cur_i >= len(self.target_name_list) - 1:
            cur_i = 0
        else:
            cur_i = cur_i + 1
        self.current_target_name = self.target_name_list[cur_i]
        self.fill_table_content()
        pass
    def target_combox_currentTextChanged(self,txt:str):
        cur_txt = self.target_combox.currentText()
        if not cur_txt or cur_txt == self.please_select_str:
            return
        self.current_target_name = cur_txt
        self.fill_table_content()
        pass

ExcuteShowWidget 中 process_excute_event 方法修改

    def process_excute_event(self,data:Dict):
        mark_str = data['mark_str']
        status = data['status']
        if status == 'success':
            self.excute_info_label.setText(f'{mark_str} 执行成功')

            ret = data['ret']
            target_style = ret['target_style']
            if target_style == 'table':
                # 表格类型结果
                pre_map = {
                    'header':ret['target_header'],
                    'data':ret['target_data']
                }
                node_widget = TableNodeWidget()
                node_widget.set_data(pre_map)
                self.fill_scroll_area([node_widget])
                pass
        else:
            self.excute_info_label.setText(f'{mark_str} 失败!失败!')
            now_str = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
            log_str = f'{now_str}::{mark_str}::{data["msg"]}'
            self.log_list.append(log_str)

            self.thread_caculate = None
            self.progress_finished()
            pass
        pass

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/77845.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

ABAP 新语法--Data Processing

1. String Template 新语法引入了字符串模板&#xff0c;用于处理字符串连接以及格式转换 字符串模板在 | … | 之间定义&#xff0c;主要分为两部分&#xff0c;固定文本和变量 其中&#xff0c;变量只能在 { … } 内使用&#xff0c;大括号之外的所有字符均作为固定文本使用…

git权限问题解决方法Access denied fatal: Authentication failed

文章目录 遇到Access denied 的权限问题解决方法1、git的密码修改过&#xff0c;但是本地没更新。2、确定问题&#xff0c;然后增加配置① 查询用户信息②如果名称和email不对&#xff0c;设置名称&#xff1a;③ 检查ssh-add是否链接正常④ 设置不要每次都输入用户名密码 3、配…

Linux学习之基本指令一

在学习Linux下的基本指令之前首先大家要知道Linux下一切皆目录&#xff0c;我们的操作基本上也都是对目录的操作&#xff0c;这里我们可以联想我们是如何在windows上是如何操作的&#xff0c;只是形式上不同&#xff0c;类比学习更容易理解。 目录 01.ls指令 02. pwd命令 0…

Linux的基本权限(文件,目录)

文章目录 前言一、Linux权限的概念二、Linux权限管理 1.文件访问者分类2.文件类型和访问类型3.文件访问权限的相关设置方法三、目录的权限四、权限的总结 前言 Linux下一切皆文件&#xff0c;指令的本质就是可执行文件&#xff0c;直接安装到了系统的某种路径下 一、Linux权限的…

带你了解Cloudquery 安装使用功能

&#x1f3e0;个人主页&#xff1a;晨犀主页 &#x1f9d1;个人简介&#xff1a;大家好&#xff0c;我是晨犀&#xff0c;希望我的文章可以帮助到大家&#xff0c;您的满意是我的动力&#x1f609;&#x1f609; &#x1f495;欢迎大家&#xff1a;这里是CSDN&#xff0c;我总结…

第九章 动态规划part10(代码随想录)

121. 买卖股票的最佳时机 1. 确定dp数组&#xff08;dp table&#xff09;以及下标的含义 用二维dp数组表示第i天的2种状态 dp[i][0] 表示第i天持有股票所得最多现金&#xff0c;可能i-1天就买股票了 dp[i][1] 表示第i天不持有股票所得最多现金 最后求&#xff1a;dp[len-1][0…

Python系统学习1-9-类一之类语法

一、类之初印象 1、类就是空表格&#xff0c;将变量&#xff08;列名&#xff09;和函数&#xff08;行为&#xff09;结合起来 2、创建对象&#xff0c;表达具体行 3、创建类就是创建数据的模板 --操作数据时有提示 --还能再组合数据的行为 --结构更加清晰 4、类的内存分配…

git日常操作-案例

文章目录 查看tag对应版本tag一个版本切换到指定tag查看远程有那些分支 查看tag对应版本 要查看 Git 仓库中标签&#xff08;tag&#xff09;对应的版本&#xff0c;可以使用以下命令&#xff1a; git show <tag>将 替换为你要查看的标签名称。该命令将显示与标签对应的…

爬虫IP时效问题:优化爬虫IP使用效果实用技巧

目录 1. 使用稳定的代理IP服务提供商&#xff1a; 2. 定期检测代理IP的可用性&#xff1a; 3. 配置合理的代理IP切换策略&#xff1a; 4. 使用代理IP池&#xff1a; 5. 考虑代理IP的地理位置和速度&#xff1a; 6. 设置合理的请求间隔和并发量&#xff1a; 总结 在爬虫过…

POSTGRESQL 关于2023-08-14 数据库自动启动文章中使用KILL 来进行配置RELOAD的问题解释...

开头还是介绍一下群&#xff0c;如果感兴趣Polardb ,mongodb ,MySQL ,Postgresql ,redis &#xff0c;SQL SERVER ,ORACLE,Oceanbase 等有问题&#xff0c;有需求都可以加群群内有各大数据库行业大咖&#xff0c;CTO&#xff0c;可以解决你的问题。加群请加 liuaustin3微信号 &…

postgresql中基础sql查询

postgresql中基础sql查询 创建表插入数据创建索引删除表postgresql命令速查简单查询计算查询结果 利用查询条件过滤数据模糊查询 创建表 -- 部门信息表 CREATE TABLE departments( department_id INTEGER NOT NULL -- 部门编号&#xff0c;主键, department_name CHARACTE…

【深入理解C语言】-- 关键字2

&#x1f407; &#x1f525;博客主页&#xff1a; 云曦 &#x1f4cb;系列专栏&#xff1a;深入理解C语言 &#x1f4a8;吾生也有涯&#xff0c;而知也无涯 &#x1f49b; 感谢大家&#x1f44d;点赞 &#x1f60b;关注&#x1f4dd;评论 文章目录 前言一、关键字 - static&…

星际争霸之小霸王之小蜜蜂(二)--类的使用

目录 前言 一、将设置内容写在一个类里 二、设置小蜜蜂的造型 三、设置猫蜜蜂的参数 四、绘制猫蜜蜂到窗口 总结 前言 昨天我们设置好了窗口&#xff0c;下面我们需要向窗口中添加元素了。 一、将设置内容写在一个类里 我个人理解书上的意思是要创建一个类&#xff0c;将所有需…

爬虫逆向实战(三)--天某云登录

一、数据接口分析 主页地址&#xff1a;天某云 1、抓包 通过抓包可以发现登录接口是account/login 2、判断是否有加密参数 请求参数是否加密&#xff1f; 通过“载荷”模块可以发现password、comParam_signature、comParam_seqCode是加密的 请求头是否加密&#xff1f; 无…

【CTF-web】备份是个好习惯(查找备份文件、双写绕过、md5加密绕过)

题目链接&#xff1a;https://ctf.bugku.com/challenges/detail/id/83.html 经过扫描可以找到index.php.bak备份文件&#xff0c;下载下来后打开发现是index.php的原代码&#xff0c;如下图所示。 由代码可知我们要绕过md5加密&#xff0c;两数如果满足科学计数法的形式的话&a…

设计模式之七:适配器模式与外观模式

面向对象适配器将一个接口转换成另一个接口&#xff0c;以符合客户的期望。 // 用火鸡来冒充一下鸭子class Duck { public:virtual void quack() 0;virtual void fly() 0; };class Turkey { public:virtual void gobble() 0;virtual void fly() 0; };class TurkeyAdapter :…

【大数据Hive】hive 事务表使用详解

目录 一、前言 二、Hive事务背景知识 hive事务实现原理 hive事务原理之 —— delta文件夹命名格式 _orc_acid_version 说明 bucket_00000 合并器(Compactor) 二、Hive事务使用限制 参数设置 客户端参数设置 客户端参数设置 三、Hive事务使用操作演示 操作步骤 客…

深入学习SpringCloud Alibaba微服务架构,揭秘Nacos、Sentinel、Seata等核心技术,助力构建高效系统!

课程链接&#xff1a; 链接: https://pan.baidu.com/s/1hRN0R8VFcwjyCTWCEsz-8Q?pwdj6ej 提取码: j6ej 复制这段内容后打开百度网盘手机App&#xff0c;操作更方便哦 --来自百度网盘超级会员v4的分享 课程介绍&#xff1a; &#x1f4da;【第01阶段】课程简介&#xff1a;全…

Git和GitHub

文章目录 1.Git介绍2. 常用命令3. Git分支操作4. Git团队协作机制5. GitHub操作6. IDEA集成Git7.IDEA操作GitHub8. Gitee 1.Git介绍 Git免费的开源的分布式版本控制系统&#xff0c;可以快速高效从小到大的各种项目 Git易于学习&#xff0c;占地面积小&#xff0c;性能快。它…

haproxy负载均衡

1、配置环境 作用环境windows测试  192.168.33.158 172.25.0.11 haproxy负载均衡haproxy&#xff1a;2.8.1&#xff0c;centos7172.25.0.31web服务器1--rs1Apache&#xff1a;2.4&#xff0c;redhat9172.25.0.32web服务器2--rs2Apache&#xff1a;2.4 &#xff0c; redhat9 2、…