import pandas as pd import matplotlib.pyplot as plt def process_files(file1, file2, cpu): hi_values_file1 = [] hi_values_file2 = [] lo_values_file1 = [] lo_values_file2 = [] # Read first 1000 lines from each file for file_index, file in enumerate([file1, file2]): # Read the data with semicolon as the separator if cpu == True: data = pd.read_csv(file, header=None, nrows=1000, sep=';') else: data = pd.read_csv(file, header=None, skiprows=1000, nrows=1000, sep=';') for index, row in data.iterrows(): # Convert columns to numeric cols = row.apply(pd.to_numeric, errors='coerce') # Handle non-numeric gracefully # Calculate sums hi_sum = cols[0] + cols[1] + cols[4] + cols[7] lo_sum = cols[2] + cols[3] + cols[5] + cols[6] if file_index == 0: # File 1 hi_values_file1.append(hi_sum) lo_values_file1.append(lo_sum) else: # File 2 hi_values_file2.append(hi_sum) lo_values_file2.append(lo_sum) return hi_values_file1, hi_values_file2, lo_values_file1, lo_values_file2 def plot_boxplots(hi_values_file1, hi_values_file2, lo_values_file1, lo_values_file2,cpu): # Prepare data for box plots data_hi = [hi_values_file1, hi_values_file2] data_lo = [lo_values_file1, lo_values_file2] # Create Box Plot for HI values plt.figure(figsize=(10, 5)) plt.boxplot(data_hi, labels=['Idle time', 'FTP'], patch_artist=True) plt.title('Evaluation 2: Compute the number of HI missed deadline') plt.ylabel('Number of HI missed deadline') plt.grid(True) if cpu == 70 : plt.savefig("mygraph_eval2_HI_cpu70.png") else : plt.savefig("mygraph_eval2_HI_cpu90.png") # Create Box Plot for LO values plt.figure(figsize=(10, 5)) plt.boxplot(data_lo, labels=['Idle time', 'FTP'], patch_artist=True) plt.title('Evaluation 2: Compute the number of LO missed deadline') plt.ylabel('Number of LO missed deadline') plt.grid(True) if cpu == 70: plt.savefig("mygraph_eval2_LO_cpu70.png") else: plt.savefig("mygraph_eval2_LO_cpu90.png") if __name__ == "__main__": file1 = 'data_eval_protocol1.csv' # Replace with your first file name file2 = 'data_eval_protocol2.csv' # Replace with your second file name hi_values_file1, hi_values_file2, lo_values_file1, lo_values_file2 = process_files(file1, file2,True) plot_boxplots(hi_values_file1, hi_values_file2, lo_values_file1, lo_values_file2,70) hi_values_file1, hi_values_file2, lo_values_file1, lo_values_file2 = process_files(file1, file2,False) plot_boxplots(hi_values_file1, hi_values_file2, lo_values_file1, lo_values_file2,90)