0.1.124
This commit is contained in:
		| @@ -1,6 +1,6 @@ | ||||
| Metadata-Version: 2.1 | ||||
| Name: guan | ||||
| Version: 0.1.123 | ||||
| Version: 0.1.124 | ||||
| Summary: An open source python package | ||||
| Home-page: https://py.guanjihuan.com | ||||
| Author: guanjihuan | ||||
|   | ||||
| @@ -40,6 +40,11 @@ def chat(prompt='你好', model=1, stream=0, top_p=0.8, temperature=0.85): | ||||
|             print('\n--- End Stream Message ---\n') | ||||
|     return response | ||||
|  | ||||
| # 从列表中删除某个匹配的元素 | ||||
| def remove_item_in_one_array(array, item): | ||||
|     new_array = [x for x in array if x != item] | ||||
|     return new_array  | ||||
|  | ||||
| # 并行计算前的预处理,把参数分成多份 | ||||
| def preprocess_for_parallel_calculations(parameter_array_all, task_num=1, task_index=0): | ||||
|     import numpy as np | ||||
| @@ -505,12 +510,6 @@ def fill_zero_data_for_new_dates(old_dates, new_dates, old_data_array): | ||||
|             new_data_array.append(old_data_array[index]) | ||||
|     return new_data_array | ||||
|  | ||||
| # 获取CPU使用率 | ||||
| def get_cpu_usage(interval=1): | ||||
|     import psutil | ||||
|     cpu_usage = psutil.cpu_percent(interval=interval) | ||||
|     return cpu_usage | ||||
|  | ||||
| # 获取内存信息 | ||||
| def get_memory_info(): | ||||
|     import psutil | ||||
| @@ -521,6 +520,72 @@ def get_memory_info(): | ||||
|     used_memory_percent = memory_info.percent | ||||
|     return total_memory, used_memory, available_memory, used_memory_percent | ||||
|  | ||||
| # 获取CPU的平均使用率 | ||||
| def get_cpu_usage(interval=1): | ||||
|     import psutil | ||||
|     cpu_usage = psutil.cpu_percent(interval=interval) | ||||
|     return cpu_usage | ||||
|  | ||||
| # 获取每个CPU核心的使用率,返回列表 | ||||
| def get_cpu_usage_array_per_core(interval=1): | ||||
|     import psutil | ||||
|     cpu_usage_array_per_core = psutil.cpu_percent(interval=interval, percpu=True) | ||||
|     return cpu_usage_array_per_core | ||||
|  | ||||
| # 获取使用率最高的CPU核心的使用率 | ||||
| def get_cpu_max_usage_for_all_cores(interval=1): | ||||
|     import guan | ||||
|     cpu_usage_array_per_core = guan.get_cpu_usage_array_per_core(interval=interval) | ||||
|     max_cpu_usage = max(cpu_usage_array_per_core) | ||||
|     return max_cpu_usage | ||||
|  | ||||
| # 获取非零使用率的CPU核心的平均使用率 | ||||
| def get_cpu_averaged_usage_for_non_zero_cores(interval=1): | ||||
|     import guan | ||||
|     cpu_usage_array_per_core = guan.get_cpu_usage_array_per_core(interval=interval) | ||||
|     cpu_usage_array_per_core_new = guan.remove_item_in_one_array(cpu_usage_array_per_core, 0.0) | ||||
|     averaged_cpu_usage = sum(cpu_usage_array_per_core_new)/len(cpu_usage_array_per_core_new) | ||||
|     return averaged_cpu_usage | ||||
|  | ||||
| # 在一定数量周期内得到CPU的使用率信息。默认为10秒钟收集一次,(interval+sleep_interval)*times 为收集的时间范围,范围默认为60秒,即1分钟后返回列表,总共得到6组数据。其中,数字第一列和第二列分别是平均值和最大值。 | ||||
| def get_cpu_information_for_times(interval=1, sleep_interval=9, times=6): | ||||
|     import guan | ||||
|     import time | ||||
|     cpu_information_array = [] | ||||
|     for _ in range(times): | ||||
|         cpu_information = [] | ||||
|         datetime_date = guan.get_date() | ||||
|         datetime_time = guan.get_time() | ||||
|         cpu_information.append(datetime_date) | ||||
|         cpu_information.append(datetime_time) | ||||
|         cpu_usage_array_per_core = guan.get_cpu_usage_array_per_core(interval=interval) | ||||
|         cpu_information.append(sum(cpu_usage_array_per_core)/len(cpu_usage_array_per_core)) | ||||
|         cpu_information.append(max(cpu_usage_array_per_core)) | ||||
|         for cpu_usage in cpu_usage_array_per_core: | ||||
|             cpu_information.append(cpu_usage) | ||||
|         cpu_information_array.append(cpu_information) | ||||
|         time.sleep(sleep_interval) | ||||
|     return cpu_information_array | ||||
|  | ||||
| # 将得到的CPU的使用率信息写入文件。默认为半分钟收集一次,(interval+sleep_interval)*times 为收集的时间范围,范围默认为60分钟,即1小时写入文件一次,总共得到120组数据。其中,数字第一列和第二列分别是平均值和最大值。 | ||||
| def write_cpu_information_to_file(filename_pre='./cpu_usage', interval=1, sleep_interval=29, times=120): | ||||
|     import guan | ||||
|     while True: | ||||
|         datetime_date = guan.get_date() | ||||
|         filename = filename_pre+'_'+datetime_date | ||||
|         guan.make_file(filename+'.txt') | ||||
|         f = guan.open_file(filename) | ||||
|         cpu_information_array = get_cpu_information_for_times(interval=interval, sleep_interval=sleep_interval, times=times) | ||||
|         for cpu_information in cpu_information_array: | ||||
|             i0 = 0 | ||||
|             for information in cpu_information:  | ||||
|                 if i0 < 2: | ||||
|                     f.write(str(information)+' ') | ||||
|                 else: | ||||
|                     f.write(f'{information:.1f} ') | ||||
|                 i0 += 1 | ||||
|             f.write('\n') | ||||
|  | ||||
| # 获取MAC地址 | ||||
| def get_mac_address(): | ||||
|     import uuid | ||||
|   | ||||
| @@ -58,11 +58,11 @@ def timer_decorator_with_parameters(unit='second', print_show=1, write_file=0, f | ||||
|         return wrapper | ||||
|     return timer_decorator | ||||
|  | ||||
| # 函数的装饰器,用于GUAN软件包函数的使用统计 | ||||
| def statistics_decorator(func): | ||||
|     def wrapper(*args, **kwargs): | ||||
|         result = func(*args, **kwargs) | ||||
|         import guan | ||||
|         guan.statistics_of_guan_package(func.__name__) | ||||
|         return result | ||||
|     return wrapper | ||||
| # # 函数的装饰器,用于GUAN软件包函数的使用统计 | ||||
| # def statistics_decorator(func): | ||||
| #     def wrapper(*args, **kwargs): | ||||
| #         result = func(*args, **kwargs) | ||||
| #         import guan | ||||
| #         guan.statistics_of_guan_package(func.__name__) | ||||
| #         return result | ||||
| #     return wrapper | ||||
| @@ -657,18 +657,6 @@ def plot_stock_line(date_array, opening_array, closing_array, high_array, low_ar | ||||
|     plt.show() | ||||
|     plt.close('all') | ||||
|  | ||||
| # Guan软件包升级检查和提示(如果无法连接或者版本为最新,那么均没有提示) | ||||
| def notification_of_upgrade(timeout=5): | ||||
|     try: | ||||
|         import guan | ||||
|         latest_version = guan.get_latest_version(package_name='guan', timeout=timeout) | ||||
|         current_version = guan.get_current_version('guan') | ||||
|         if latest_version != None and current_version != None: | ||||
|             if latest_version != current_version: | ||||
|                 print('升级提示:您当前使用的版本是 guan-'+current_version+',目前已经有最新版本 guan-'+latest_version+'。您可以通过以下命令对软件包进行升级:pip install --upgrade guan -i https://pypi.python.org/simple 或 pip install --upgrade guan') | ||||
|     except: | ||||
|         pass | ||||
|  | ||||
| # Guan软件包的使用统计(仅仅统计装机数和import次数) | ||||
| def statistics_of_guan_package(function_name=None): | ||||
|     import guan | ||||
| @@ -703,4 +691,16 @@ def statistics_of_guan_package(function_name=None): | ||||
|         client_socket.send(send_message.encode()) | ||||
|         client_socket.close() | ||||
|     except: | ||||
|         pass | ||||
|         pass | ||||
|  | ||||
| # # Guan软件包升级检查和提示(如果无法连接或者版本为最新,那么均没有提示) | ||||
| # def notification_of_upgrade(timeout=5): | ||||
| #     try: | ||||
| #         import guan | ||||
| #         latest_version = guan.get_latest_version(package_name='guan', timeout=timeout) | ||||
| #         current_version = guan.get_current_version('guan') | ||||
| #         if latest_version != None and current_version != None: | ||||
| #             if latest_version != current_version: | ||||
| #                 print('升级提示:您当前使用的版本是 guan-'+current_version+',目前已经有最新版本 guan-'+latest_version+'。您可以通过以下命令对软件包进行升级:pip install --upgrade guan -i https://pypi.python.org/simple 或 pip install --upgrade guan') | ||||
| #     except: | ||||
| #         pass | ||||
		Reference in New Issue
	
	Block a user