From ddd49deef7ac6daff95086f112a0061a641c4fe3 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期四, 13 六月 2024 15:36:00 +0800
Subject: [PATCH] 添加订阅日志

---
 utils/init_data_util.py |   54 +++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 43 insertions(+), 11 deletions(-)

diff --git a/utils/init_data_util.py b/utils/init_data_util.py
index 3cd570e..d1d61c6 100644
--- a/utils/init_data_util.py
+++ b/utils/init_data_util.py
@@ -29,10 +29,40 @@
     return datas
 
 
-# 瑙f瀽鏈�澶ч噺
-def parse_max_volume(datas, is_new_or_near_top=False):
+def parse_max_volume(code,  datas, is_new_or_near_top=False):
+    result = __parse_max_volume(code, datas, is_new_or_near_top)
+    refer_index = result[3]
+    # 璁$畻鏈�浣庝环
+    refer_price = datas[refer_index]["high"]
+    min_price = float(refer_price)
+    for i in range(0, refer_index + 1):
+        if min_price > datas[i]["low"]:
+            min_price = datas[i]["low"]
+    if (refer_price - min_price) / refer_price < 0.4:
+        return result
+    # 瓒呰穼
+    new_datas = []
+    for i in range(0, refer_index):
+        # 鑾峰彇娑ㄥ箙
+        item = datas[i]
+        rate = (item["low"] - item["pre_close"]) / item["pre_close"]
+        new_datas.append((i, rate))
+    new_datas.sort(key=lambda x: x[1])
+    refer_index = new_datas[0][0]
+    # 鑾峰彇褰撳墠澶╁拰鍚庝竴澶╄緝澶ч噺
+    if refer_index > 0:
+        if datas[refer_index - 1]["volume"] > datas[refer_index]["volume"]:
+            refer_index -= 1
+
+    return datas[refer_index]["volume"], datas[refer_index]["volume"], datas[refer_index]['bob'].strftime(
+        "%Y-%m-%d"), refer_index
+
+
+# 杩斿洖锛�(60澶╂渶澶ч噺,鏄ㄦ棩閲�,閲忓弬鑰冩棩鏈�,鍙傝�冮噺鎹粖浜ゆ槗鏃ユ暟)
+def __parse_max_volume(code, datas, is_new_or_near_top=False):
     max_volume = 0
     max_volume_date = None
+    max_volume_index = None
     # 鍒ゆ柇30澶╁唴鏄惁鏈夋定鍋�
     if is_new_or_near_top:
         # 30澶╁唴鏄惁鏈夋定鍋�
@@ -41,7 +71,7 @@
             if i >= len(datas):
                 break
             item = datas[i]
-            limit_up_price = float(gpcode_manager.get_limit_up_price_by_preprice(item["pre_close"]))
+            limit_up_price = float(gpcode_manager.get_limit_up_price_by_preprice(code, item["pre_close"]))
             if abs(limit_up_price - item["high"]) < 0.001:
                 latest_limit_up_index = i
                 break
@@ -50,18 +80,20 @@
             if latest_limit_up_index > 0 and datas[latest_limit_up_index - 1]["volume"] > datas[latest_limit_up_index][
                 "volume"]:
                 return datas[latest_limit_up_index - 1]["volume"], datas[latest_limit_up_index - 1]["volume"], \
-                       datas[latest_limit_up_index - 1]['bob'].strftime("%Y-%m-%d")
+                       datas[latest_limit_up_index - 1]['bob'].strftime("%Y-%m-%d"), latest_limit_up_index - 1
             else:
                 return datas[latest_limit_up_index]["volume"], datas[latest_limit_up_index]["volume"], \
-                       datas[latest_limit_up_index]['bob'].strftime("%Y-%m-%d")
+                       datas[latest_limit_up_index]['bob'].strftime("%Y-%m-%d"), latest_limit_up_index
 
     if is_new_or_near_top:
         # 濡傛灉鏄獊鐮村墠楂樺氨鍙栨渶澶ч噺
-        for item in datas:
+        for i in range(len(datas)):
+            item = datas[i]
             if max_volume < item["volume"]:
                 max_volume = item["volume"]
                 max_volume_date = item["bob"]
-        return max_volume, max_volume, max_volume_date.strftime("%Y-%m-%d")
+                max_volume_index = i
+        return max_volume, max_volume, max_volume_date.strftime("%Y-%m-%d"), max_volume_index
     else:
         date = None
         target_volume = None
@@ -73,7 +105,7 @@
                 max_volume = volume
                 max_volume_date = item['bob']
             # 鏄惁鏈夋定鍋�
-            limit_up_price = float(gpcode_manager.get_limit_up_price_by_preprice(item["pre_close"]))
+            limit_up_price = float(gpcode_manager.get_limit_up_price_by_preprice(code, item["pre_close"]))
             # 涓嶇湅瓒呰繃60澶╃殑娑ㄥ仠
             if abs(limit_up_price - item["high"]) < 0.01 and i <= 59:
                 # 娑ㄥ仠
@@ -84,7 +116,7 @@
                 if volume < next_volume:
                     volume = next_volume
                     date = datas[i - 1]["bob"]
-                target_volume = (volume, date)
+                target_volume = (volume, date, i)
                 break
 
         # 90涓氦鏄撴棩鏃犳定鍋滐紝鍙栨渶杩�30澶╁唴鐨勬渶楂橀噺浣滀负鍙傝�冮噺
@@ -97,6 +129,6 @@
                 item = datas[i]
                 volume = item["volume"]
                 if max_30_volume_info[0] < volume:
-                    max_30_volume_info = [volume, item["bob"]]
+                    max_30_volume_info = [volume, item["bob"], i]
             target_volume = max_30_volume_info
-        return target_volume[0], target_volume[0], target_volume[1].strftime("%Y-%m-%d")
+        return target_volume[0], target_volume[0], target_volume[1].strftime("%Y-%m-%d"), target_volume[2]

--
Gitblit v1.8.0