From 3da5d1ef00cf7665c2d37f837e6845c92d22e31c Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期五, 15 十二月 2023 16:02:08 +0800
Subject: [PATCH] 前日炸板策略修改

---
 third_data/kpl_data_manager.py |   62 +++++++++++++++++++++++++++----
 1 files changed, 54 insertions(+), 8 deletions(-)

diff --git a/third_data/kpl_data_manager.py b/third_data/kpl_data_manager.py
index a63bf2a..1d5e713 100644
--- a/third_data/kpl_data_manager.py
+++ b/third_data/kpl_data_manager.py
@@ -1,4 +1,6 @@
+import copy
 import json
+import logging
 import os
 import threading
 import time
@@ -6,12 +8,13 @@
 import requests
 
 import constant
-from db.redis_manager import RedisUtils
+from db.redis_manager_delegate import RedisUtils
+from log_module import async_log_util
 from utils import tool
 
 # 寮�鐩樺暒鍘嗗彶娑ㄥ仠鏁版嵁绠$悊
-from db import mysql_data, redis_manager
-from log_module.log import logger_kpl_limit_up_reason_change
+from db import mysql_data_delegate as mysql_data, redis_manager_delegate as redis_manager
+from log_module.log import logger_kpl_limit_up_reason_change, logger_debug, logger_kpl_limit_up
 from third_data import kpl_util, kpl_api
 from third_data.code_plate_key_manager import LimitUpCodesPlateKeyManager, CodesHisReasonAndBlocksManager
 
@@ -44,6 +47,8 @@
     __kplPlatManager = KPLPlatManager()
     __LimitUpCodesPlateKeyManager = LimitUpCodesPlateKeyManager()
     __CodesPlateKeysManager = CodesHisReasonAndBlocksManager()
+    __current_code_reason_dict = {}
+    __current_reason_codes_dict = {}
 
     @classmethod
     def __load_hist_and_blocks(cls, code):
@@ -74,6 +79,16 @@
         if records:
             cls.latest_origin_datas = records
             cls.__LimitUpCodesPlateKeyManager.set_today_limit_up([(r[0], r[5]) for r in records])
+
+        code_reason_dict = {}
+        reason_code_dict = {}
+        for d in records:
+            code_reason_dict[d[0]] = d[5]
+            if d[5] not in reason_code_dict:
+                reason_code_dict[d[5]] = set()
+            reason_code_dict[d[5]].add(d[0])
+        cls.__current_code_reason_dict = code_reason_dict
+        cls.__current_reason_codes_dict = reason_code_dict
 
         # 娑ㄥ仠鏁版嵁璁板綍
         mysqldb = mysql_data.Mysqldb()
@@ -187,6 +202,24 @@
         bs = set([b[0] for b in results])
         return bs
 
+    @classmethod
+    def get_current_block(cls, code):
+        return cls.__current_code_reason_dict.get(code)
+
+    @classmethod
+    def get_current_codes_by_block(cls, block):
+        return cls.__current_reason_codes_dict.get(block)
+
+    @classmethod
+    def get_current_reason_codes_dict(cls):
+        return copy.deepcopy(cls.__current_reason_codes_dict)
+
+    @classmethod
+    def get_current_reasons(cls):
+        if cls.__current_reason_codes_dict:
+            return cls.__current_reason_codes_dict.keys()
+        return set()
+
 
 class KPLDataManager:
     __latest_datas = {}
@@ -294,6 +327,7 @@
     if day in __limit_up_list_records_dict:
         datas = __limit_up_list_records_dict[day]
     else:
+        logger_debug.info("浠庢枃浠朵腑鑾峰彇鍓嶅嚑澶╃殑瀹炴椂娑ㄥ仠鏁版嵁")
         datas = KPLDataManager().get_latest_from_file(KPLDataType.LIMIT_UP, 10)
         if datas:
             # 淇濆瓨鏁版嵁
@@ -308,9 +342,14 @@
 
 
 def get_yesterday_limit_up_codes():
-    yesterday_limit_up_data_records = get_current_limit_up_data_records(1)[0][1]
+    yesterday_limit_up_data_records = get_yesterday_current_limit_up_records()
     yesterday_codes = set([x[0] for x in yesterday_limit_up_data_records])
     return yesterday_codes
+
+
+def get_yesterday_current_limit_up_records():
+    yesterday_limit_up_data_records = get_current_limit_up_data_records(1)[0][1]
+    return yesterday_limit_up_data_records
 
 
 # 杩愯鎷夊彇浠诲姟
@@ -323,14 +362,21 @@
         requests.post("http://127.0.0.1:9004/upload_kpl_data", json.dumps(root_data))
 
     def get_limit_up():
+        last_time = 0
         while True:
             if tool.is_trade_time():
                 try:
-                    results = kpl_api.daBanList(kpl_api.DABAN_TYPE_LIMIT_UP)
+                    results = kpl_api.getLimitUpInfo()
                     result = json.loads(results)
+                    start_time = time.time()
                     __upload_data("limit_up", result)
+                    if start_time - last_time >= 60:
+                        last_time = time.time()
+                        # 璁板綍娑ㄥ仠鏁版嵁
+                        logger_kpl_limit_up.info(result)
+                    # logger_kpl_limit_up_reason_change.info("涓婁紶鑰楁椂锛歿}", time.time() - start_time)
                 except Exception as e:
-                    pass
+                    logging.exception(e)
             time.sleep(3)
 
     def get_bidding_money():
@@ -369,8 +415,8 @@
 
     threading.Thread(target=get_limit_up, daemon=True).start()
     threading.Thread(target=get_bidding_money, daemon=True).start()
-    threading.Thread(target=get_market_industry, daemon=True).start()
-    threading.Thread(target=get_market_jingxuan, daemon=True).start()
+    # threading.Thread(target=get_market_industry, daemon=True).start()
+    # threading.Thread(target=get_market_jingxuan, daemon=True).start()
 
 
 if __name__ == "__main__":

--
Gitblit v1.8.0