import os import time import psutil import pandas as pd import numpy as np def get_stats(file_path): if os.path.exists(file_path): data = pd.read_csv(file_path) else: columns = ['Timestamp', 'MemoryUsed(%)', 'CPU_Used(%)'] data = pd.DataFrame(columns=columns) while True: current_time = time.strftime("%d_%m_%y_%H_%M_%S") # Memory stats memory_stats = psutil.virtual_memory() memory_used = memory_stats.percent # CPU stats #cpu_stats = psutil.cpu_percent(interval=1, percpu=True) cpu_stats = np.mean(psutil.cpu_percent(interval=1, percpu=True)) # Create a new row with the timestamp, memory stats, and CPU stats new_row = {'Timestamp': current_time, 'Memory Stats': memory_used, 'CPU Stats': cpu_stats} # Append the row to the DataFrame data = data.append(new_row, ignore_index=True) # Sleep for 60 seconds time.sleep(5) # Save the DataFrame to a CSV file data.to_csv(file_path, index=False) page_dict = {} page_files = [ 'doc/344_page_1_txt.png', 'doc/344_page_1_table.png', 'doc/5433_page_2_table.png', 'doc/54_page3_img.png', 'doc/32_page3_txt.png', 'doc/32_page3_table.png' ] for file in page_files: # Extracting page number from file name page_number = file.split('_')[1].replace('page', '') if page_number not in page_dict: page_dict[page_number] = [] page_dict[page_number].append(file) print(page_dict)