admin
2025-06-04 287c506725b2d970f721f80169f83c2418cb0991
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
日志分析
"""
# 获取不可以下单的原因
import os
import re
 
import constant
from utils import tool
 
 
def get_cant_order_reasons_dict():
    file_path = "{}/logs/gp/l2/l2_trade.{}.log".format(constant.get_path_prefix(), tool.get_now_date_str())
    dict_ = {}
    if os.path.exists(file_path):
        with open(file_path, encoding="utf-8") as f:
            line = f.readline()
            while line:
                if line.find("不可以下单,原因:") > -1:
                    code = line.split("code=")[1][:6]
                    time_ = line.split("|")[0].split(" ")[1][:12]
                    reason = line.split("不可以下单,原因:")[1].strip()
                    dict_[code] = (time_, reason)
                    # print(time_, code, reason)
                line = f.readline()
    return dict_
 
 
def get_kpl_can_buy_reasons_dict():
    file_path = "{}/logs/gp/kpl/kpl_block_can_buy.{}.log".format(constant.get_path_prefix(), tool.get_now_date_str())
    dict_ = {}
    if os.path.exists(file_path):
        with open(file_path, encoding="utf-8") as f:
            line = f.readline()
            while line:
                if True:
                    code = line.split("code=")[1][:6]
                    time_ = line.split("|")[0].split(" ")[1][:12]
                    reason = line.split(f"code={code}:")[1].strip()
                    dict_[code] = (time_, reason.replace("可以下单", ""))
                    # print(time_, code, reason)
                line = f.readline()
    return dict_
 
 
# 分析请求时间
def analyse_request_time():
    with open(f"D:\\文件传输\\交易\\日志文件\\request_debug.{tool.get_now_date_str()}.log", encoding="utf-8", mode='r') as f:
        lines = f.readlines()
        keys = {}
        for line in lines:
            if not line:
                continue
            if line.find("请求开始:register") >= 0:
                continue
            try:
                time_str = re.findall(r'\[(.*?)\]', line)[0]
                result = re.findall(r'【(.*?)】', line)
                key = f"{result[0]}-{result[1]}"
                if key not in keys:
                    keys[key] = (time_str, line)
                else:
                    use_time = tool.time_sub_as_ms(time_str, keys[key][0])
                    if use_time > 1000 * 5:
                        print(f"请求时间:{use_time}ms", keys[key][1])
                    keys.pop(key)
            except:
                print(line)
 
        for k in keys:
            print("尚未获取到结果:", keys[k])
 
    pass
 
 
if __name__ == "__main__":
    analyse_request_time()