From cf32945520de905d86f87c04cad426a7402d12d8 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期二, 19 十一月 2024 17:12:20 +0800
Subject: [PATCH] 删除原有的资金净流入统计方式

---
 third_data/custom_block_in_money_manager.py |   58 ++++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 38 insertions(+), 20 deletions(-)

diff --git a/third_data/custom_block_in_money_manager.py b/third_data/custom_block_in_money_manager.py
index 3a15250..22f0fd6 100644
--- a/third_data/custom_block_in_money_manager.py
+++ b/third_data/custom_block_in_money_manager.py
@@ -10,28 +10,39 @@
 from utils import tool
 
 
+@tool.singleton
 class CodeInMoneyManager:
-    """
-    鍗曚釜绁ㄦ祦鍏ョ殑閲戦璁$畻
-    """
-    __code_money_dict = {}
+    def __init__(self):
+        self.__code_money_dict = {}
+        self.__load_data()
 
-    @classmethod
-    def set_market_info(cls, code, price, pre_price, current_amount):
-        """
-        璁剧疆甯傚満琛屾儏淇℃伅
-        @param code:
-        @param price:
-        @param pre_price:
-        @param current_amount:
-        @return:
-        """
-        money = (price - pre_price) * current_amount / pre_price
-        cls.__code_money_dict[code] = int(money)
+    def __load_data(self):
+        with open(f"{constant.get_path_prefix()}\\logs\\huaxin_local\\l2\\upload.{tool.get_now_date_str()}.log") as f:
+            lines = f.readlines()
+            for line in lines:
+                line = line.split(" - ")[1]
+                item = eval(line)
+                self.add_data(item)
 
-    @classmethod
-    def get_money(cls, code):
-        return cls.__code_money_dict.get(code)
+    def add_data(self, item):
+        code = item[0]
+        if code not in self.__code_money_dict:
+            self.__code_money_dict[code] = 0
+        if item[1] == 0:
+            self.__code_money_dict[code] += item[2][2]
+        else:
+            self.__code_money_dict[code] -= item[2][2]
+
+    def get_code_money_dict(self):
+        return self.__code_money_dict
+
+    def get_money(self, code):
+        if code in self.__code_money_dict:
+            return self.__code_money_dict.get(code)
+        return 0
+
+    def set_money(self, code, money):
+        self.__code_money_dict[code] = money
 
 
 @tool.singleton
@@ -76,7 +87,7 @@
         codes = self.codes
         block_money = {}
         for code in codes:
-            money = CodeInMoneyManager.get_money(code)
+            money = CodeInMoneyManager().get_money(code)
             if money is None:
                 continue
             before_fblocks = LimitUpCodesBlockRecordManager().get_radical_buy_blocks(code)
@@ -101,3 +112,10 @@
 
     def get_out_list(self):
         return self.__out_list
+
+
+if __name__ == '__main__':
+    print(CodeInMoneyManager().get_money("300264"))
+    # BlockInMoneyRankManager().compute()
+    # print(BlockInMoneyRankManager().get_in_list()[:20])
+    # print(BlockInMoneyRankManager().get_out_list()[:20])

--
Gitblit v1.8.0