mns-common 1.3.9.1__py3-none-any.whl → 1.3.9.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of mns-common might be problematic. Click here for more details.

@@ -39,6 +39,20 @@ def classify_symbol(real_time_quotes_now_df):
39
39
  return real_time_quotes_now_df
40
40
 
41
41
 
42
+ # 增加前缀
43
+ def add_pre_prefix(real_time_quotes_now_df):
44
+ real_time_quotes_now_df['symbol_prefix'] = real_time_quotes_now_df['symbol'].apply(
45
+ lambda symbol: add_pre_prefix_one(symbol))
46
+ return real_time_quotes_now_df
47
+
48
+
49
+ # 增加后缀
50
+ def add_after_prefix(real_time_quotes_now_df):
51
+ real_time_quotes_now_df['symbol_prefix'] = real_time_quotes_now_df['symbol'].apply(
52
+ lambda symbol: add_after_prefix_one(symbol))
53
+ return real_time_quotes_now_df
54
+
55
+
42
56
  # 单个股票分类
43
57
  def classify_symbol_one(symbol):
44
58
  if symbol.startswith('3'):
@@ -54,6 +68,27 @@ def classify_symbol_one(symbol):
54
68
  return 'X'
55
69
 
56
70
 
71
+ # 添加前缀
72
+ def add_pre_prefix_one(symbol):
73
+ symbol_simple = symbol[0:6]
74
+ if symbol_simple.startswith('6'):
75
+ return 'SH' + symbol
76
+ elif symbol_simple.startswith('0') or symbol_simple.startswith('3'):
77
+ return 'SZ' + symbol
78
+ else:
79
+ return 'BJ' + symbol
80
+
81
+ # 添加后缀
82
+ def add_after_prefix_one(symbol):
83
+ symbol_simple = symbol[0:6]
84
+ if symbol_simple.startswith('6'):
85
+ return symbol + '.SH'
86
+ elif symbol_simple.startswith('0') or symbol_simple.startswith('3'):
87
+ return symbol + '.SZ'
88
+ else:
89
+ return symbol + '.BJ'
90
+
91
+
57
92
  def symbol_amount_simple(real_time_quotes_now_df):
58
93
  real_time_quotes_now_df['amount_level'] = round(real_time_quotes_now_df['amount'] / HUNDRED_MILLION, 2)
59
94
  return real_time_quotes_now_df
@@ -0,0 +1,86 @@
1
+ import threading
2
+ from functools import wraps
3
+ from typing import Optional, Callable
4
+
5
+ class ExceptionMonitor:
6
+ """支持动态配置的异常监控器"""
7
+ def __init__(
8
+ self,
9
+ threshold: int = 1000,
10
+ alert_handler: Optional[Callable[[int, int], None]] = None,
11
+ auto_reset: bool = True
12
+ ):
13
+ """
14
+ :param threshold: 报警阈值,默认1000次
15
+ :param alert_handler: 自定义报警函数,格式 func(current_count, threshold)
16
+ :param auto_reset: 触发报警后是否自动重置计数器
17
+ """
18
+ self.counter = 0
19
+ self._threshold = threshold
20
+ self.alert_handler = alert_handler
21
+ self.auto_reset = auto_reset
22
+ self.lock = threading.Lock()
23
+
24
+ @property
25
+ def threshold(self) -> int:
26
+ """当前报警阈值"""
27
+ return self._threshold
28
+
29
+ @threshold.setter
30
+ def threshold(self, value: int):
31
+ """动态设置报警阈值"""
32
+ with self.lock:
33
+ self._threshold = value
34
+
35
+ def increment(self):
36
+ """线程安全的计数器递增"""
37
+ with self.lock:
38
+ self.counter += 1
39
+ if self.counter >= self.threshold:
40
+ self.trigger_alert()
41
+ if self.auto_reset:
42
+ self.reset_counter()
43
+
44
+ def reset_counter(self):
45
+ """手动重置计数器"""
46
+ with self.lock:
47
+ self.counter = 0
48
+
49
+ def trigger_alert(self):
50
+ """触发报警(支持自定义处理逻辑)"""
51
+ if self.alert_handler:
52
+ self.alert_handler(self.counter, self.threshold)
53
+ else:
54
+ print(f"[ALERT] Exception count {self.counter} exceeded threshold {self.threshold}")
55
+
56
+ def exception_counter(
57
+ threshold: int = 1000,
58
+ alert_handler: Optional[Callable[[int, int], None]] = None,
59
+ auto_reset: bool = True
60
+ ):
61
+ """
62
+ 异常计数装饰器工厂
63
+ :param threshold: 报警阈值
64
+ :param alert_handler: 自定义报警处理函数
65
+ :param auto_reset: 是否自动重置计数器
66
+ """
67
+ def decorator(func):
68
+ # 为每个被装饰函数创建独立监控实例
69
+ monitor = ExceptionMonitor(
70
+ threshold=threshold,
71
+ alert_handler=alert_handler,
72
+ auto_reset=auto_reset
73
+ )
74
+
75
+ @wraps(func)
76
+ def wrapper(*args, **kwargs):
77
+ try:
78
+ return func(*args, **kwargs)
79
+ except Exception as e:
80
+ monitor.increment()
81
+ raise # 保持原始异常栈
82
+
83
+ # 暴露监控器以便外部访问
84
+ wrapper.monitor = monitor
85
+ return wrapper
86
+ return decorator
@@ -0,0 +1,7 @@
1
+ import sys
2
+ import os
3
+
4
+ file_path = os.path.abspath(__file__)
5
+ end = file_path.index('mns') + 16
6
+ project_path = file_path[0:end]
7
+ sys.path.append(project_path)
@@ -1,4 +1,4 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mns-common
3
- Version: 1.3.9.1
3
+ Version: 1.3.9.3
4
4
 
@@ -73,7 +73,7 @@ mns_common/api/us/ths_us_company_info_api.py,sha256=qQjv4F-ovQ2uuu-FlBAnxjvVA7qj
73
73
  mns_common/api/xueqiu/__init__.py,sha256=wEg73KlZo-dU0yKGwpA1C2y6LZm4IBb94tNda1tqLeg,163
74
74
  mns_common/api/xueqiu/xue_qiu_k_line_api.py,sha256=Vqal_JvHCYFGPZ5CK2BSgMPQ7ull2N3G79UsJ3sfu2k,4586
75
75
  mns_common/component/__init__.py,sha256=2U9DiKslxsWwLLEcZKjS8UiQPN1QgALvnK3HiJNIZE0,163
76
- mns_common/component/common_service_fun_api.py,sha256=H7HZ-6uxup5unWe2JazNw_EBMLj2As82FC0QqPvao7c,5536
76
+ mns_common/component/common_service_fun_api.py,sha256=ZPPqo-ZBwSJ23I_2xXGxXyN6emYrlPqUuBGjA2Cv4gs,6629
77
77
  mns_common/component/cache/__init__.py,sha256=2U9DiKslxsWwLLEcZKjS8UiQPN1QgALvnK3HiJNIZE0,163
78
78
  mns_common/component/cache/cache_service.py,sha256=QX7tjR1iGsoCyGt6O41w8aRbZ-3xXQ-53Ps3nmUzAGQ,809
79
79
  mns_common/component/classify/__init__.py,sha256=wEg73KlZo-dU0yKGwpA1C2y6LZm4IBb94tNda1tqLeg,163
@@ -95,6 +95,8 @@ mns_common/component/deal/terminal_enum.py,sha256=JUkSTXLQW1fob05PCCzIBg_VKlGmqa
95
95
  mns_common/component/em/__init__.py,sha256=wEg73KlZo-dU0yKGwpA1C2y6LZm4IBb94tNda1tqLeg,163
96
96
  mns_common/component/em/em_real_time_quotes_api.py,sha256=9VAwzj_am-Jd4zG57bhrVjXrrsytzymSu8CIs7T7Lc0,2144
97
97
  mns_common/component/em/em_stock_info_api.py,sha256=r2T9H4cgnZ6p-TUjjeNXsw0aQtwugJQkHeOuHgFl5VY,1192
98
+ mns_common/component/exception/ExceptionMonitor.py,sha256=Ma8DsXcU357ni0l_PAFhRZ-nxghiVvnUWE3vu_UeqSk,2731
99
+ mns_common/component/exception/__init__.py,sha256=wEg73KlZo-dU0yKGwpA1C2y6LZm4IBb94tNda1tqLeg,163
98
100
  mns_common/component/hk/__init__.py,sha256=wEg73KlZo-dU0yKGwpA1C2y6LZm4IBb94tNda1tqLeg,163
99
101
  mns_common/component/hk/company_hk_service_api.py,sha256=c5z3N2OQ1SOiditHSPkb5Hqh-U67aDlpSKAV3s4U3vs,857
100
102
  mns_common/component/industry/__init__.py,sha256=2U9DiKslxsWwLLEcZKjS8UiQPN1QgALvnK3HiJNIZE0,163
@@ -150,7 +152,7 @@ mns_common/utils/date_handle_util.py,sha256=XS-MyA8_7k35LOCFAYOHgVcVkMft_Kc4Wa9U
150
152
  mns_common/utils/db_util.py,sha256=hSmfNAN4vEeEaUva6_cicZEhb2jSnib-Gvk2reke1vc,2590
151
153
  mns_common/utils/file_util.py,sha256=egWu6PenGPRp_ixrNTHKarT4dAnOT6FETR82EHUZJnQ,1042
152
154
  mns_common/utils/ip_util.py,sha256=UTcYfz_uytB__6nlBf7T-izuI7hi4XdB6ET0sJgEel4,969
153
- mns_common-1.3.9.1.dist-info/METADATA,sha256=nvwdxZ3uDb6JLCMDSBLW9cb2cFGYF0DV24VcXTCoXxg,61
154
- mns_common-1.3.9.1.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
155
- mns_common-1.3.9.1.dist-info/top_level.txt,sha256=ZC58kAR-8Hvc6U2xhYNBNLAh3mb6sZazbdj5nZpvEkQ,11
156
- mns_common-1.3.9.1.dist-info/RECORD,,
155
+ mns_common-1.3.9.3.dist-info/METADATA,sha256=dihOQtcjMhsMci4UUXImXg0UGtJnxH0QO1EyGfOMcVU,61
156
+ mns_common-1.3.9.3.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
157
+ mns_common-1.3.9.3.dist-info/top_level.txt,sha256=ZC58kAR-8Hvc6U2xhYNBNLAh3mb6sZazbdj5nZpvEkQ,11
158
+ mns_common-1.3.9.3.dist-info/RECORD,,