From 77409ec0bbd1e0412944408adbd4122075253434 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E6=80=9D=E5=8D=97?= <15083356+zhu-sinan@user.noreply.gitee.com> Date: Mon, 9 Mar 2026 16:56:39 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A1=AE=E8=AE=A4=E6=AF=8F=E5=A4=A9=E7=9A=84?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- industry_heat_task.py | 37 +++++++++++++++++++++++++++---------- mqreceive_multithread.py | 6 +++--- mqreceivefromllm.py | 1 - 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/industry_heat_task.py b/industry_heat_task.py index 9b0de75..339df78 100644 --- a/industry_heat_task.py +++ b/industry_heat_task.py @@ -48,8 +48,8 @@ class SWIndustryHeatTracker: } # 初始化数据库表 - if self.db_config: - self._init_database() + # if self.db_config: + # self._init_database() def _init_database(self): """初始化MySQL数据库和表""" @@ -104,6 +104,14 @@ class SWIndustryHeatTracker: return set(dates) + def is_trading_day(self, date=None): + """判断是否为交易日""" + if date is None: + date = datetime.now() + if isinstance(date, datetime): + date = date.strftime('%Y-%m-%d') + return date in self.trading_dates + def _update_calendar_cache(self, cache_file): """更新交易日历缓存""" print("正在更新交易日历...") @@ -352,6 +360,18 @@ class SWIndustryHeatTracker: f"量比:{row['volume_ratio']:4.2f} | " f"动量:{row['momentum']:.0%}") + # 打印冷门板块(后10名) + print(f"\n❄️ 冷门板块 (后10名):") + print("-"*80) + bottom10 = heat_df.tail(10) + for _, row in bottom10.iterrows(): + print(f"{row['rank']:2d}. {row['name']:8s} | " + f"热度:{row['heat_score']:5.1f}({row['heat_level']}) | " + f"收益:{row['total_return']:+6.2f}% | " + f"换手:{row['avg_turnover']:5.2f}% | " + f"量比:{row['volume_ratio']:4.2f} | " + f"动量:{row['momentum']:.0%}") + # 保存数据部分 if save: today = datetime.now().strftime('%Y-%m-%d') @@ -378,14 +398,6 @@ class SWIndustryHeatTracker: # 使用示例 if __name__ == "__main__": # 数据库配置 - # config = { - # 'host': 'localhost', - # 'port': 3306, - # 'user': 'your_username', - # 'password': 'your_password', - # 'database': 'your_database', - # 'charset': 'utf8mb4' - # } config = { 'host': '10.127.2.207', 'user': 'financial_prod', @@ -401,5 +413,10 @@ if __name__ == "__main__": db_config=config # 传入数据库配置 ) + check_date = datetime.now().strftime('%Y-%m-%d') + if not tracker.is_trading_day(check_date): + print(f"\n⚠️ {check_date} 不是交易日,跳过计算\n\n") + exit(0) + # 生成报告并自动存入MySQL result = tracker.generate_report(save=True, to_mysql=True) \ No newline at end of file diff --git a/mqreceive_multithread.py b/mqreceive_multithread.py index cd38c03..3e173d4 100644 --- a/mqreceive_multithread.py +++ b/mqreceive_multithread.py @@ -95,8 +95,8 @@ def update_sw_heat_job(): # --- 3. 启动定时调度器 --- scheduler = BackgroundScheduler() -# 每天 18:10 执行更新 -scheduler.add_job(update_sw_heat_job, 'cron', hour=18, minute=10) +# 每天 18:25 执行更新 +scheduler.add_job(update_sw_heat_job, 'cron', hour=18, minute=25) scheduler.start() @@ -157,7 +157,7 @@ def process_single_message(data): first_industry = industry_label[0].split("-")[0] first_industry_confidence = industry_confidence[0] if first_industry_confidence >= 0.75: - sw_heat = sw_heat_map.get(first_industry, 0) + sw_heat = sw_heat_map.get(first_industry, 0) public_opinion_score = tagged_news.get("public_opinion_score", 30) #资讯质量分 China_factor = tagged_news.get("China_factor", 0.2) #中国股市相关度 diff --git a/mqreceivefromllm.py b/mqreceivefromllm.py index 4972cff..41286d6 100644 --- a/mqreceivefromllm.py +++ b/mqreceivefromllm.py @@ -24,7 +24,6 @@ def message_callback(ch, method, properties, body): # 数据写入资讯精选表 write_to_news(data) - # 手动确认消息 ch.basic_ack(delivery_tag=method.delivery_tag) except Exception as e: