funcguard 0.1.4__py3-none-any.whl → 0.1.5__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 funcguard might be problematic. Click here for more details.

funcguard/tools.py CHANGED
@@ -68,30 +68,31 @@ def send_request(
68
68
 
69
69
 
70
70
  # 打印时间
71
- def time_log(message, i = 0, max_num = 0, s_time = None) :
71
+ def time_log(message, i = 0, max_num = 0, start_from = 0, s_time = None,) :
72
72
  """
73
73
  打印带时间戳的日志信息,支持进度显示和预计完成时间
74
74
 
75
75
  :param message: 日志消息
76
- :param i: 当前进度(从0开始)
76
+ :param i: 当前进度
77
77
  :param max_num: 总进度数量
78
+ :param start_from: i是否从0开始,0表示从0开始,1表示从1开始
78
79
  :param s_time: 开始时间,用于计算预计完成时间
79
80
  :return: None
80
81
  """
81
82
  now = datetime.now( timezone( timedelta( hours = 8 ) ) )
82
83
  time_log = "{:02d}:{:02d}:{:02d}".format( now.hour, now.minute, now.second )
83
- if i < 2 :
84
+ if i < 2 or max_num < 2 :
84
85
  print( time_log + " " + message )
86
+
85
87
  else :
86
- if max_num == 0 :
87
- text = "{}".format( i )
88
- else :
89
- text = "{}/{}".format( i, max_num )
88
+ # 根据start_from参数计算实际处理的项目数
89
+ process_item = i + 1 if start_from == 0 else i
90
+ text = "{}/{}".format( process_item, max_num )
90
91
  # 检查是否应该显示预计完成时间和剩余时间
91
- if i % 10 == 0 and s_time is not None and i < max_num :
92
+ if process_item % 10 == 0 and s_time is not None and process_item < max_num :
92
93
  duration = now - s_time
93
- ev_duration = duration / i # 每项平均耗时
94
- remaining_items = max_num - i
94
+ ev_duration = duration / process_item # 每项平均耗时
95
+ remaining_items = max_num - process_item
95
96
  time_left = ev_duration * remaining_items
96
97
  end_time = now + time_left
97
98
  end_time_str = end_time.strftime( "%Y-%m-%d %H:%M" )
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: funcguard
3
- Version: 0.1.4
4
- Summary: A funcguard for Python.
3
+ Version: 0.1.5
4
+ Summary: FuncGuard是一个Python库,提供函数执行超时控制、重试机制、HTTP请求封装和格式化打印工具。
5
5
  Home-page: https://github.com/tinycen/funcguard
6
6
  Author: tinycen
7
7
  Author-email: sky_ruocen@qq.com
@@ -145,18 +145,41 @@ from funcguard import time_log, time_diff
145
145
  # 获取开始时间
146
146
  start_time = time_diff()
147
147
 
148
- # 记录任务开始
149
- time_log("开始处理数据", 0, 100, start_time)
148
+ # 记录任务开始(i从0开始)
149
+ time_log("开始处理数据", 0, 100, 0, start_time)
150
150
 
151
151
  # 模拟处理过程
152
152
  import time
153
153
  for i in range(1, 101):
154
154
  time.sleep(0.1) # 模拟处理时间
155
155
  if i % 20 == 0:
156
- time_log(f"处理进度", i, 100, start_time) # 显示进度和预计完成时间
156
+ time_log(f"处理进度", i, 100, 0, start_time) # 显示进度和预计完成时间
157
157
 
158
158
  # 记录任务完成并打印统计信息
159
- time_log("数据处理完成", 100, 100, start_time)
159
+ time_log("数据处理完成", 100, 100, 0, start_time)
160
+ time_diff(start_time, 100, "cn") # 中文显示统计信息
161
+ ```
162
+
163
+ 或者当i从1开始时:
164
+
165
+ ```python
166
+ from funcguard import time_log, time_diff
167
+
168
+ # 获取开始时间
169
+ start_time = time_diff()
170
+
171
+ # 记录任务开始(i从1开始)
172
+ time_log("开始处理数据", 1, 100, 1, start_time)
173
+
174
+ # 模拟处理过程
175
+ import time
176
+ for i in range(1, 101):
177
+ time.sleep(0.1) # 模拟处理时间
178
+ if i % 20 == 0:
179
+ time_log(f"处理进度", i, 100, 1, start_time) # 显示进度和预计完成时间
180
+
181
+ # 记录任务完成并打印统计信息
182
+ time_log("数据处理完成", 100, 100, 1, start_time)
160
183
  time_diff(start_time, 100, "cn") # 中文显示统计信息
161
184
  ```
162
185
 
@@ -165,6 +188,7 @@ time_diff(start_time, 100, "cn") # 中文显示统计信息
165
188
  - 支持进度显示和预计完成时间计算
166
189
  - 提供中英文双语统计信息
167
190
  - 可显示总耗时、平均耗时等详细统计
191
+ - 支持i从0或从1开始的计数方式
168
192
 
169
193
  ## API文档
170
194
 
@@ -207,12 +231,13 @@ time_diff(start_time, 100, "cn") # 中文显示统计信息
207
231
  - **返回值**: 根据return_type参数返回不同格式的响应数据
208
232
  - **异常**: 当请求失败且重试次数用尽后,抛出相应的异常
209
233
 
210
- #### time_log(message, i=0, max_num=0, s_time=None)
234
+ #### time_log(message, i=0, max_num=0, start_from=0, s_time=None)
211
235
 
212
236
  - **参数**:
213
237
  - `message`: 日志消息
214
- - `i`: 当前进度(从0开始),默认为0
238
+ - `i`: 当前进度,默认为0
215
239
  - `max_num`: 总进度数量,默认为0
240
+ - `start_from`: i是否从0开始,0表示从0开始,1表示从1开始,默认为0
216
241
  - `s_time`: 开始时间,用于计算预计完成时间,默认为None
217
242
  - **返回值**: 无
218
243
  - **功能**: 打印带时间戳的日志信息,支持进度显示和预计完成时间计算
@@ -1,13 +1,13 @@
1
1
  funcguard/__init__.py,sha256=iyM7STP-KSxUn7PUaBWEQcZus2XskiGTTweI4qjoETE,342
2
2
  funcguard/core.py,sha256=-rFRkE-udxM0wxlcv9Qi_yIQBRdVrGgwza-LYQsVRLg,3632
3
3
  funcguard/printer.py,sha256=c93x6Z-6a7nnead_Rk_f0Xe23kdVdSj4qaxsuBMKfd0,958
4
- funcguard/tools.py,sha256=S7t46KurOedvVKCVoFLW_CoDvLSC__lfVLUYBse5ABM,5433
4
+ funcguard/tools.py,sha256=jpmZFEEepzeEHLahbV0SwVZDy1I_mwB5MxeLFspMR6U,5623
5
5
  tests/__init__.py,sha256=VW6FdWdSC_PL3zEtpkRQfUMf6yVD2OfwtSds82jawTs,26
6
6
  tests/run_test.py,sha256=-SLdUV7gDifLxuCCAlU8qLxYMx6KpK4cxfG4UYfUIgA,1005
7
7
  tests/test_core.py,sha256=aZNbQK4eTnnkCI4c2txYZNTcYIUhSJvII5Dvn0vNJKo,3732
8
8
  tests/test_tools.py,sha256=g9dK-WW1s5SIobscRuelufBfPrSgNLZU8d1AJteBpd0,5609
9
- funcguard-0.1.4.dist-info/LICENSE,sha256=jgOquECfjiXp5xXQ2zuzItDr4XDBLan-bIzIXl1lS4Y,1064
10
- funcguard-0.1.4.dist-info/METADATA,sha256=ayz3u_YGwUqH3ziy-awhbPMjWgFdPWYCxSQmTZJF-HI,7175
11
- funcguard-0.1.4.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
12
- funcguard-0.1.4.dist-info/top_level.txt,sha256=7wL9mWT062DttKNO7Wi1wYWTZilR2AOPRO0rE3gvtB4,16
13
- funcguard-0.1.4.dist-info/RECORD,,
9
+ funcguard-0.1.5.dist-info/LICENSE,sha256=jgOquECfjiXp5xXQ2zuzItDr4XDBLan-bIzIXl1lS4Y,1064
10
+ funcguard-0.1.5.dist-info/METADATA,sha256=pi5iZvJkeJKPh-Ix3uptlcLwxuDl5SnyGg8THa-PS0k,8027
11
+ funcguard-0.1.5.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
12
+ funcguard-0.1.5.dist-info/top_level.txt,sha256=7wL9mWT062DttKNO7Wi1wYWTZilR2AOPRO0rE3gvtB4,16
13
+ funcguard-0.1.5.dist-info/RECORD,,