From 3045231303b20da6e461d6920b2e65af45d347be Mon Sep 17 00:00:00 2001 From: guanjihuan Date: Tue, 21 May 2024 09:38:00 +0800 Subject: [PATCH] 0.1.101 --- PyPI/setup.cfg | 2 +- PyPI/src/guan.egg-info/PKG-INFO | 2 +- PyPI/src/guan/decorators.py | 25 +++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/PyPI/setup.cfg b/PyPI/setup.cfg index 37f10f0..bd00c6d 100644 --- a/PyPI/setup.cfg +++ b/PyPI/setup.cfg @@ -1,7 +1,7 @@ [metadata] # replace with your username: name = guan -version = 0.1.100 +version = 0.1.101 author = guanjihuan author_email = guanjihuan@163.com description = An open source python package diff --git a/PyPI/src/guan.egg-info/PKG-INFO b/PyPI/src/guan.egg-info/PKG-INFO index e610764..b8c1252 100644 --- a/PyPI/src/guan.egg-info/PKG-INFO +++ b/PyPI/src/guan.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: guan -Version: 0.1.100 +Version: 0.1.101 Summary: An open source python package Home-page: https://py.guanjihuan.com Author: guanjihuan diff --git a/PyPI/src/guan/decorators.py b/PyPI/src/guan/decorators.py index bd53c6e..eff9757 100644 --- a/PyPI/src/guan/decorators.py +++ b/PyPI/src/guan/decorators.py @@ -33,6 +33,31 @@ def timer_decorator_hours(func): return result return wrapper +# 函数的装饰器,用于获取计算时间(秒,分,时),可将运行的时间写入文件 +def timer_decorator_with_parameters(unit='second', print_show=1, write_file=0, filename='timer'): + def timer_decorator(func): + import time + def wrapper(*args, **kwargs): + start = time.time() + result = func(*args, **kwargs) + end = time.time() + if unit == 'second': + timer_text = f"Running time of {func.__name__}: {end - start} seconds" + elif unit == 'minute': + timer_text = f"Running time of {func.__name__}: {(end - start)/60} minutes" + elif unit == 'hour': + timer_text = f"Running time of {func.__name__}: {(end - start)/3600} hours" + else: + timer_text = f"Running time of {func.__name__}: {end - start} seconds" + if print_show == 1: + print(timer_text) + if write_file == 1: + with open(filename+'.txt', 'a') as f: + f.write(timer_text+'\n') + return result + return wrapper + return timer_decorator + # 函数的装饰器,用于GUAN软件包函数的使用统计 def statistics_decorator(func): def wrapper(*args, **kwargs):