From f0248f54f90a12f491245f0ee3ccfbe8f477a76b Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期五, 22 十二月 2023 14:24:20 +0800 Subject: [PATCH] bug修复 --- code_attribute/code_volumn_manager.py | 36 ++++++++++++++++++++++++------------ 1 files changed, 24 insertions(+), 12 deletions(-) diff --git a/code_attribute/code_volumn_manager.py b/code_attribute/code_volumn_manager.py index 35295fd..c5a58f2 100644 --- a/code_attribute/code_volumn_manager.py +++ b/code_attribute/code_volumn_manager.py @@ -7,11 +7,13 @@ # yesterday 鏄ㄥぉ鐨勯噺 import json -from db.redis_manager import RedisUtils +from db.redis_manager_delegate import RedisUtils +from log_module import async_log_util from utils import global_util, tool -from db import redis_manager +from db import redis_manager_delegate as redis_manager from log_module.log import logger_day_volumn +__db = 0 __redis_manager = redis_manager.RedisManager(0) @@ -21,9 +23,9 @@ global_util.max60_volumn[code] = (max60, max60_day) global_util.yesterday_volumn[code] = yesterday try: - RedisUtils.setex(redis, "volumn_max60-{}".format(code), tool.get_expire(), json.dumps((max60, max60_day)), - auto_free=False) - RedisUtils.setex(redis, "volumn_yes-{}".format(code), tool.get_expire(), yesterday, auto_free=False) + RedisUtils.setex_async(0, "volumn_max60-{}".format(code), tool.get_expire(), json.dumps((max60, max60_day)), + auto_free=False) + RedisUtils.setex_async(0, "volumn_yes-{}".format(code), tool.get_expire(), yesterday, auto_free=False) finally: RedisUtils.realse(redis) @@ -52,7 +54,7 @@ # 璁剧疆浠婃棩閲� def set_today_volumn(code, volumn): - logger_day_volumn.info("code:{} volumn:{}".format(code, volumn)) + async_log_util.info(logger_day_volumn, "code:{} volumn:{}".format(code, volumn)) global_util.today_volumn[code] = volumn # 鏈�1000鎵嬬殑鍙樺寲鎵嶄繚瀛� if code in __today_volumn_cache and volumn - __today_volumn_cache[code] < 100000: @@ -63,17 +65,15 @@ # datas:[(code, volumn)] def set_today_volumns(datas): - pipe = __redis_manager.getRedis().pipeline() for d in datas: code, volumn = d - logger_day_volumn.info("code:{} volumn:{}".format(code, volumn)) + async_log_util.info(logger_day_volumn, "code:{} volumn:{}".format(code, volumn)) global_util.today_volumn[code] = volumn # 鏈�1000鎵嬬殑鍙樺寲鎵嶄繚瀛� if code in __today_volumn_cache and volumn - __today_volumn_cache[code] < 100000: continue __today_volumn_cache[code] = volumn - RedisUtils.setex(pipe, "volumn_today-{}".format(code), tool.get_expire(), volumn) - pipe.execute() + RedisUtils.setex_async(__db, "volumn_today-{}".format(code), tool.get_expire(), volumn) # 鑾峰彇浠婃棩閲� @@ -85,17 +85,29 @@ # 鑾峰彇閲忔瘮锛堜粖鏃ラ噺/max(60澶╂渶澶ч噺,鏄ㄦ棩閲�)锛� -def get_volume_rate(code, with_info=False): +# 灏嗘�诲崠閲忚绠楀湪鍐� +def get_volume_rate(code, total_sell_volume=0, 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("鑾峰彇閲忓け璐�") - rate = round(int(today) / max(int(max60[0]), int(yesterday)), 2) + rate = round((int(today) + total_sell_volume) / max(int(max60[0]), int(yesterday)), 2) if not with_info: return rate return rate, (today, max(int(max60[0]), int(yesterday))) +# 鑾峰彇閲忓弬鑰冩棩鏈� +def get_volume_refer_date(code): + max60, yesterday = get_histry_volumn(code) + if max60 is None or yesterday is None: + raise Exception("鑾峰彇澶辫触") + if int(max60[0]) >= int(yesterday): + return max60[1] + else: + return "涓婁釜浜ゆ槗鏃�" + + # 鑾峰彇閲忔瘮绱㈠紩 def get_volume_rate_index(volume_rate): rates = [0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4, 1.6] -- Gitblit v1.8.0