From 8535f56dbf6e410b4a09f02f95d4d49bcc8753f2 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期一, 27 三月 2023 18:58:54 +0800
Subject: [PATCH] 看盘页面数据调整

---
 code_volumn_manager.py |   22 +++++++++++++++++-----
 1 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/code_volumn_manager.py b/code_volumn_manager.py
index 97935b7..2582c88 100644
--- a/code_volumn_manager.py
+++ b/code_volumn_manager.py
@@ -5,6 +5,8 @@
 # 璁剧疆鍘嗗彶閲�
 # max60 60澶╂渶澶ч噺
 # yesterday 鏄ㄥぉ鐨勯噺
+import json
+
 import global_util
 import gpcode_manager
 from db import redis_manager
@@ -15,11 +17,11 @@
 
 
 # 璁剧疆鍘嗗彶閲�
-def set_histry_volumn(code, max60, yesterday):
+def set_histry_volumn(code, max60, yesterday, max60_day=''):
     redis = __redis_manager.getRedis()
     global_util.max60_volumn[code] = max60
     global_util.yesterday_volumn[code] = yesterday
-    redis.setex("volumn_max60-{}".format(code), tool.get_expire(), max60)
+    redis.setex("volumn_max60-{}".format(code), tool.get_expire(), json.dumps((max60,max60_day)))
     redis.setex("volumn_yes-{}".format(code), tool.get_expire(), yesterday)
 
 
@@ -30,6 +32,8 @@
     redis = __redis_manager.getRedis()
     if max60 is None:
         max60 = redis.get("volumn_max60-{}".format(code))
+        if max60:
+            max60 = json.loads(max60)
     if yesterday is None:
         yesterday = redis.get("volumn_yes-{}".format(code))
     return max60, yesterday
@@ -53,12 +57,15 @@
 
 
 # 鑾峰彇閲忔瘮锛堜粖鏃ラ噺/max(60澶╂渶澶ч噺,鏄ㄦ棩閲�)锛�
-def get_volume_rate(code):
+def get_volume_rate(code, with_info=False):
     today = get_today_volumn(code)
     max60, yesterday = get_histry_volumn(code)
     if today is None or max60 is None or yesterday is None:
         raise Exception("鑾峰彇閲忓け璐�")
-    return round(int(today) / max(int(max60), int(yesterday)), 2)
+    rate = round(int(today) / max(int(max60[0]), int(yesterday)), 2)
+    if not with_info:
+        return rate
+    return rate, (today, max(int(max60[0]), int(yesterday)))
 
 
 # 鑾峰彇閲忔瘮绱㈠紩
@@ -90,7 +97,10 @@
     if keys is not None:
         for k in keys:
             code = k.split("-")[1]
-            global_util.max60_volumn[code] = redis.get(k)
+            max60_volumn = redis.get(k)
+            if max60_volumn:
+                max60_volumn = json.loads(max60_volumn)
+            global_util.max60_volumn[code] = max60_volumn
     keys = redis.keys("volumn_yes-*")
     if keys is not None:
         for k in keys:
@@ -98,3 +108,5 @@
             global_util.yesterday_volumn[code] = redis.get(k)
 
 
+if __name__ == "__main__":
+    print(get_histry_volumn("603717"))
\ No newline at end of file

--
Gitblit v1.8.0