From 0ed2c53acd278d57a39390fd4db78c5aaf088e0a Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期五, 21 四月 2023 18:03:54 +0800
Subject: [PATCH] 开盘啦数据解析

---
 trade/first_code_score_manager.py |  168 ++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 109 insertions(+), 59 deletions(-)

diff --git a/trade/first_code_score_manager.py b/trade/first_code_score_manager.py
index 1b25f63..8e1c2bc 100644
--- a/trade/first_code_score_manager.py
+++ b/trade/first_code_score_manager.py
@@ -5,7 +5,7 @@
 # bidding 鏄惁婊¤冻绔炰环
 # deal_big_money 鎴愪氦澶ч噾棰濇槸鍚︽弧瓒�
 # code_nature = (鏄惁鏈夋定鍋滐紝鏄惁鏈夋孩浠�)
-# hot_block(鏉垮潡涓定鍋滅エ涓暟锛堝寘鍚嚜宸憋級锛屾澘鍧楃偢鏉跨エ涓暟, 鏂版澘鍧楀悕绉� , 楂樹綅鏉夸俊鎭�)
+# hot_block(鏉垮潡涓定鍋滅エ涓暟锛堝寘鍚嚜宸憋級锛屾澘鍧楃偢鏉跨エ涓暟,鏉垮潡鐐告澘鍥炲皝涓暟, (鏉垮潡鍚嶇О,鍑虹幇娆℃暟), 楂樹綅鏉夸俊鎭�)
 # zyltgb鑷敱娴侀�氬競鍊兼槸鍚﹀ぇ浜�250浜�
 # limit_price 娑ㄥ仠浠锋槸鍚﹀ぇ浜�100鍧�
 # limit_up_time 鏄惁10鐐逛箣鍓嶆定鍋�
@@ -24,18 +24,15 @@
                 deal_big_money_rate):
     score_list = []
     if zyltgb:
-        zyltgbs = [0, 10, 31, 51, 101, 150, 250, 1000000]
-        zyltgb_score = [15, 25, 15, 5, -5, -55, -1000]
-        for i in range(1, len(zyltgbs)):
-            if zyltgbs[i - 1] <= zyltgb / 100000000 < zyltgbs[i]:
-                score_list.append(zyltgb_score[i - 1])
+        zyltgb_y = round(zyltgb / 100000000, 0)
+        if zyltgb_y <= 80:
+            score_list.append(max(int(round(0.5 * zyltgb_y - 10, 0)), -10))
+        else:
+            score_list.append(max(int(round(30 - 5 * ((zyltgb_y-80)//20), 0)), -10))
     else:
         score_list.append(0)
 
-    if limit_price:
-        score_list.append(-1000)
-    else:
-        score_list.append(0)
+    score_list.append(max(int(round(-1 * limit_price + 31, 0)), -69))
 
     # 寮�鐩樺墠绔炰环
     if bidding:
@@ -81,7 +78,7 @@
     if k_form[6]:
         k_score.append(0)
     else:
-        k_score.append(0)
+        k_score.append(20)
 
     # 鏄惁澶╅噺澶ч槼
     if k_form[7] and not k_form[1]:
@@ -94,64 +91,93 @@
 
     nature_score = []
 
+    # 棣栨澘娑ㄥ仠娆℃暟,棣栨澘婧环鐜�,棣栨澘寮�鏉挎孩浠风巼
     if code_nature is None:
-        code_nature = [True, False]
-
-    if not code_nature[0]:
-        nature_score.append(5)
+        code_nature = [0, 0, 0]
+    if code_nature[0] <= 0:
+        nature_score.append(20)
+    else:
+        nature_score.append(min(10 + code_nature[0], 20))
+    if code_nature[1]:
+        nature_score.append(min(int(round(code_nature[1] * 20 - 10)), 10))
     else:
         nature_score.append(0)
-    if code_nature[1]:
-        nature_score.append(20)
+    if code_nature[2]:
+        nature_score.append(min(int(round(code_nature[2] * 20 - 10)), 10))
     else:
         nature_score.append(0)
 
     score_list.append(nature_score)
 
     hot_block_score = []
-    # 鏉垮潡涓彧鏈夎嚜宸辨定鍋滐紝涓旀棤鐐告澘
-    if hot_block[1] >= 2 and hot_block[2] == 0:
-        hot_block_score.append(30)
-    elif hot_block[3] and not k_form[6]:
-        # 鏈夋柊棰樻潗锛屼笖娌℃湁K绾垮舰鎬�
-        hot_block_score.append(30)
-    elif hot_block[1] == 1 and hot_block[2] == 0:
-        hot_block_score.append(20)
-    elif hot_block[4] is not None and not k_form[6]:
-        # 鏈夐珮浣嶆澘涓旀棤K绾垮舰鎬�
-        hot_block_score.append(20)
+    # --------------- 鏉垮潡------------------
+    # 鏉垮潡 - 浠g爜骞冲潎娑ㄥ箙
+    __average_rate = round(hot_block["block_codes_rates_info"][0] / hot_block["block_codes_rates_info"][1], 2)
+    if hot_block["target_block_info"][0] == "鏃犳澘鍧�":
+        hot_block_score.append(5)
     else:
-        hot_block_score.append(0)
+        hot_block_score.append(min(int(round(__average_rate * 2 - 10)), 10))
+    # 鏉垮潡 - 娑ㄥ仠鍙暟
+    if hot_block["limit_up_codes_count"] <= 1:
+        hot_block_score.append(1)
+    else:
+        hot_block_score.append(max(12 - hot_block["limit_up_codes_count"], 2))
+    # 鏉垮潡 - 鏉垮潡娑ㄥ箙
+    hot_block_score.append(min(int(round(hot_block["target_block_info"][1] * 2)), 10))
+    # 鏉垮潡 - 绗嚑鍙定鍋�
+    if hot_block["limit_up_index"] <= 0:
+        hot_block_score.append(25)
+    else:
+        hot_block_score.append(max(60 - hot_block["limit_up_index"] * 5, 10))
+    # 鏉垮潡 - 楂樹綅鏉�
+    high_score = 0
+    for high_info in hot_block["high_block_infos"]:
+        c_count = int(high_info[1][-2:-1])
+        high_score += min(2 * c_count - 2, 10)
+    hot_block_score.append(high_score)
+    # 鏉垮潡 - 鏉垮潡鍘嗗彶鍑虹幇娆℃暟
+    if hot_block["target_block_info"][2] <= 1:
+        hot_block_score.append(10)
+    else:
+        hot_block_score.append(max(-3 * hot_block["target_block_info"][2] + 20, -10))
+
     score_list.append(hot_block_score)
+    # --------------- 鏉垮潡缁撴潫-----------------
 
     # 閲�
-    volume_score = [0, 40, 50, 60, 50, 40, 20, 0, -25]
-    volume_rates = [0, 0.349, 0.499, 0.649, 0.799, 0.949, 1.099, 1.249, 1.399]
-    volume_add = False
-    for i in range(1, len(volume_rates)):
-        if volume_rates[i - 1] <= volume_rate < volume_rates[i]:
-            score_list.append(volume_score[i - 1])
-            volume_add = True
-            break
-    if not volume_add:
-        score_list.append(volume_score[-1])
+    if volume_rate <= 0.5:
+        score_list.append(int(round(100 * volume_rate)))
+    elif volume_rate < 0.6:
+        score_list.append(50)
+    elif volume_rate < 0.7:
+        score_list.append(55)
+    elif volume_rate <= 1.0:
+        score_list.append(60)
+    else:
+        score_list.append(max(int(round(-100 * volume_rate + 160, 0)), -20))
+
+    # 鍒濆鍖栦负褰撳墠鏃堕棿
+    limit_up_time_m = tool.trade_time_sub(tool.get_now_time_str(), "09:00:00") // 60
 
     if limit_up_time:
-        times = ["10:00:00", "11:30:00", "14:00:00", "15:00:00"]
-        time_scores = [5, 4, 3, 2]
-        for i in range(0, len(times)):
-            if int(times[i].replace(":", "")) >= int(limit_up_time.replace(":", "")):
-                score_list.append(time_scores[i])
-                break
+        limit_up_time_m = tool.trade_time_sub(limit_up_time, "09:00:00") // 60
+
+    if limit_up_time_m < 240:
+        # 14:30涔嬪墠閫傜敤
+        score_list.append(min(int(0 - round(limit_up_time_m / 15) + 12), 10))
+    elif limit_up_time_m <= 270:
+        # 15:00涔嬪墠鍔�
+        score_list.append(100)
     else:
         score_list.append(0)
 
     # 澶у崟鎴愪氦
-    deal_big_money_rates = [0, 0.00001, 0.5, 1, 1.2, 1.5, 10000]
-    deal_big_money_scores = [0, -20, -10, 20, 30, 40]
-    for i in range(1, len(deal_big_money_rates)):
-        if deal_big_money_rate < deal_big_money_rates[i]:
-            score_list.append(deal_big_money_scores[i - 1])
+    if deal_big_money_rate < 1:
+        score_list.append(0)
+    else:
+        d_score = int(round(10 * deal_big_money_rate, 0))
+        d_score = min(d_score, 60)
+        score_list.append(d_score)
 
     score = 0
     for s in score_list:
@@ -163,7 +189,7 @@
     return score, score_list
 
 
-def get_score(code, volume_rate, limit_up_time, with_source_data=False):
+def get_score(code, volume_rate, limit_up_time, with_source_data=False, estimate_deal_big_money_num=0):
     source_datas = []
 
     # 鑾峰彇鑷敱娴侀�氳偂鏈�
@@ -208,10 +234,28 @@
 
     hot_block = hot_block_data_process.get_info(code)
     if hot_block is None:
-        hot_block = ('鏃犳澘鍧�', 1, 0, None, None)
-    else:
-        # 鍔犱笂鑷繁
-        hot_block = (hot_block[0], hot_block[1] + 1, hot_block[2], hot_block[3], hot_block[4])
+        hot_block = {
+            # 鐩爣鏉垮潡淇℃伅锛堟澘鍧楀悕绉�,鏉垮潡娑ㄥ箙,鍘嗗彶鏉垮潡鍑虹幇娆℃暟锛�
+            "target_block_info": ("鏃犳澘鍧�", 0, 0),
+            # 娑ㄥ仠椤哄簭
+            "limit_up_index": 0,
+            # 娑ㄥ仠浠g爜鏁伴噺
+            "limit_up_codes_count": 0,
+            # 鏉垮潡浠g爜娑ㄥ箙淇℃伅
+            "block_codes_rates_info": (0, 0),
+            # 鐐告澘浠g爜鏁伴噺
+            "break_size": 0,
+            # 鐐告澘鍥炲皝鏁伴噺
+            "re_limit_up_size": 0,
+            # 楂樹綅鐗堜俊鎭�
+            "high_block_infos": [],
+        }
+    # 灏嗕唬鐮佹湰韬殑淇℃伅鍖呭惈杩涘幓
+    hot_block["limit_up_codes_count"] = hot_block["limit_up_codes_count"] + 1
+    pre_close_price = gpcode_manager.get_price_pre(code)
+    hot_block["block_codes_rates_info"] = (
+        hot_block["block_codes_rates_info"][0] + round((limit_price - pre_close_price) * 100 / pre_close_price, 2),
+        hot_block["block_codes_rates_info"][1] + 1)
 
     source_datas.append(hot_block)
 
@@ -221,6 +265,8 @@
 
     # 鑾峰彇鎴愪氦澶у崟
     deal_big_num = deal_big_money_manager.get_deal_big_money_num(code)
+    if estimate_deal_big_money_num > 0:
+        deal_big_num = estimate_deal_big_money_num
     m = l2_trade_factor.L2TradeFactorUtil.get_base_safe_val(zyltgb)
     source_datas.append((deal_big_num * limit_price * 100, m))
     deal_big_num_rate = (deal_big_num * limit_price * 100) / m
@@ -228,7 +274,7 @@
     for i in range(0, len(k_form)):
         k_form_1.append(k_form[i][0])
 
-    result = __get_score(zyltgb, limit_price > 100, bidding, k_form_1, code_nature, hot_block,
+    result = __get_score(zyltgb, limit_price, bidding, k_form_1, code_nature, hot_block,
                          volume_rate, limit_up_time, deal_big_num_rate)
     if with_source_data:
         return result, source_datas
@@ -236,6 +282,10 @@
 
 
 if __name__ == "__main__":
-    global_data_loader.load_zyltgb()
-    score = get_score("603829", 1.2, "15:00:01", True)
-    print(score)
+    limit_price = 35
+    prices = [0, 5, 10, 20, 30, 40, 50, 10000]
+    price_scores = [20, 15, 10, 0, -10, -20, -1000]
+    for i in range(1, len(prices)):
+        if prices[i] > limit_price:
+            print(price_scores[i - 1])
+            break

--
Gitblit v1.8.0