From c20c3c10635ce78db4a86ce9c0bb1d02e90f525d Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期二, 08 八月 2023 17:40:42 +0800
Subject: [PATCH] 单例+缓存优化

---
 third_data/code_plate_key_manager.py |   31 ++++++++++++++++---------------
 1 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/third_data/code_plate_key_manager.py b/third_data/code_plate_key_manager.py
index 80dbcb7..173a83b 100644
--- a/third_data/code_plate_key_manager.py
+++ b/third_data/code_plate_key_manager.py
@@ -312,11 +312,12 @@
 class TargetCodePlateKeyManager:
     __redisManager = redis_manager.RedisManager(1)
     __CodesPlateKeysManager = CodesHisReasonAndBlocksManager()
+    __KPLCodeJXBlockManager = KPLCodeJXBlockManager()
 
     def __get_redis(self):
         return self.__redisManager.getRedis()
 
-    # 杩斿洖key闆嗗悎(鎺掗櫎鏃犳晥鏉垮潡),浠婃棩娑ㄥ仠鍘熷洜,浠婃棩鍘嗗彶娑ㄥ仠鍘熷洜,鍘嗗彶娑ㄥ仠鍘熷洜,浜岀骇,鏉垮潡
+    # 杩斿洖key闆嗗悎(鎺掗櫎鏃犳晥鏉垮潡),浠婃棩娑ㄥ仠鍘熷洜,浠婃棩鍘嗗彶娑ㄥ仠鍘熷洜,鍘嗗彶娑ㄥ仠鍘熷洜,浜岀骇,绮鹃�夋澘鍧�
     def get_plate_keys(self, code):
         keys = set()
         k1 = set()
@@ -332,9 +333,10 @@
         if industry:
             k3 = {industry}
 
-        k4 = self.__CodesPlateKeysManager.get_blocks(code)
-        if k4 is None:
-            k4 = set()
+        k4 = set()
+        jingxuan_blocks = self.__KPLCodeJXBlockManager.get_jx_blocks(code)
+        if jingxuan_blocks:
+            k4 |= set([x[1] for x in jingxuan_blocks])
         for k in [k1, k11, k2, k3, k4]:
             keys |= k
 
@@ -359,7 +361,7 @@
     __TargetCodePlateKeyManager = TargetCodePlateKeyManager()
     __LimitUpCodesPlateKeyManager = LimitUpCodesPlateKeyManager()
     __CodesHisReasonAndBlocksManager = CodesHisReasonAndBlocksManager()
-    __KPLCodeJXBlockManager = KPLCodeJXBlockManager()
+
 
     # 鑾峰彇鍙互涔扮殑鏉垮潡
     # current_limit_up_datas: 浠婃棩瀹炴椂娑ㄥ仠
@@ -401,9 +403,8 @@
         # 濮嬬粓鑾峰彇绮鹃�夋澘鍧�
         if True:
             # 鑾峰彇
-            jx_blocks = cls.__KPLCodeJXBlockManager.get_jx_blocks(code)
-            if jx_blocks:
-                keys |= set([k[1] for k in jx_blocks[:2]])
+            if k4:
+                keys |= k4
         log.logger_kpl_debug.info("{}鏈�缁堝叧閿瘝锛歿}", code, keys)
 
         # 娑ㄥ仠鍒楄〃涓尮閰嶅叧閿瘝锛岃繑鍥烇紙鏉垮潡:浠g爜闆嗗悎锛夛紝浠g爜闆嗗悎涓凡缁忔帓闄よ嚜韬�
@@ -416,12 +417,12 @@
         can_buy_blocks = []
         for block in keys:
             is_top_8_record, top_8_record = kpl_block_util.is_record_top_block(code, block, limit_up_record_datas,
-                                                                               yesterday_current_limit_up_codes, 20)
+                                                                               yesterday_current_limit_up_codes, 50)
             is_top_4_current, top_4_current = kpl_block_util.is_current_top_block(code, block, current_limit_up_datas,
-                                                                                  yesterday_current_limit_up_codes, 10)
+                                                                                  yesterday_current_limit_up_codes, 50)
             is_top_4 = is_top_8_record and is_top_4_current
-            msg_list.append(f"\n瀹炴椂top10: {top_4_current}(娑ㄥ仠鏁伴噺锛歿len(current_limit_up_datas)})")
-            msg_list.append(f"鍘嗗彶top20: {top_8_record}")
+            msg_list.append(f"\n瀹炴椂top10(娑ㄥ仠鏁伴噺锛歿len(current_limit_up_datas)})")
+            msg_list.append(f"鍘嗗彶top20(娑ㄥ仠鏁伴噺锛歿len(top_8_record)})")
 
             # 鑾峰彇涓绘澘瀹炴椂韬綅,鍓旈櫎楂樹綅鏉�
             current_shsz_rank = kpl_block_util.get_code_current_rank(code, block, current_limit_up_datas,
@@ -537,9 +538,9 @@
         # ---------------------------------鍔犺浇宸茬粡涓嬪崟/鎴愪氦鐨勪唬鐮佷俊鎭�------------start-------------
         # match_reasons = match_limit_up_result.keys()
         # 鍒ゆ柇鍖归厤鍒扮殑鍘熷洜鏄惁宸茬粡鏈変笅鍗�/涔板叆鎴愬姛鐨勪唬鐮�
-        codes_delegate = set(trade_manager.get_codes_by_trade_states(
+        codes_delegate = set(trade_manager.CodesTradeStateManager().get_codes_by_trade_states_cache(
             {trade_manager.TRADE_STATE_BUY_DELEGATED, trade_manager.TRADE_STATE_BUY_PLACE_ORDER}))
-        codes_success = set(trade_manager.get_codes_by_trade_states(
+        codes_success = set(trade_manager.CodesTradeStateManager().get_codes_by_trade_states_cache(
             {trade_manager.TRADE_STATE_BUY_SUCCESS}))
 
         codes = codes_delegate | codes_success
@@ -551,7 +552,7 @@
         for c in codes:
             keys_, k1_, k11_, k2_, k3_, k4_ = cls.__TargetCodePlateKeyManager.get_plate_keys(c)
             # 瀹炴椂娑ㄥ仠鍘熷洜
-            trade_codes_blocks_dict[c] = k1_
+            trade_codes_blocks_dict[c] = k1_|k4_
         # 缁熻鏉垮潡涓殑浠g爜
         trade_block_codes_dict = {}
         for c in trade_codes_blocks_dict:

--
Gitblit v1.8.0