| Server IP : 172.64.80.1 / Your IP : 172.70.131.126 Web Server : Apache System : Linux mail.federalpolyede.edu.ng 5.10.0-32-amd64 #1 SMP Debian 5.10.223-1 (2024-08-10) x86_64 User : federalpolyede.edu.ng_idh35skikv ( 10000) PHP Version : 7.4.33 Disable Function : opcache_get_status MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/vhosts/federalpolyede.edu.ng/phd_code/ |
Upload File : |
import matplotlib.pyplot as plt, numpy as np
import pandas as pd
import os
# Specify the path and filename of the Excel file
filename = 'SR_output_1.xlsx'
# Check if the file exists
if os.path.exists(filename):
# Delete the file
os.remove(filename)
data = {
'cycle':[0],
'level-0':[0],
'level-1':[0],
'level-2':[0],
'level-Real':[0]
}
df1 = pd.DataFrame(data)
# Reading From Excel Files
df = pd.read_excel('c:/myData/PhD/code/output_1.xlsx')
#print(df.loc[df['sn']>0,['Attacker']])
arr = eval(df.to_json())
#Label the defence levels
defence_2 = 2
defence_1 = 1
defence_0 = 0
x_point = []
y_point_0 = []
y_point_1 = []
y_point_2 = []
y_point_Real=[]
success_0_count=0
success_1_count=0
success_2_count=0
success_real_count=0
for i in range(len(arr['Attacker'])):
attacker = arr['Attacker'][str(i)]
defenderReal = arr['Defender'][str(i)]
#if (defenderReal>attacker):
# success_real=1
# success_real_count+=1
#if defence_0==0:
# if(attacker <= defence_0):
# success_0 = 1
# success_0_count+=1
#if defence_1==1:
# if(attacker <= 1):
# success_1 = 1
# success_1_count+=1
if (attacker<=0): success_0_count+=1
if (attacker<=1): success_1_count+=1
if (attacker<=2): success_2_count+=1
if (attacker<=defenderReal): success_real_count+=1
# print(attacker,defenderReal,success_0_count,success_1_count,success_2_count,success_real_count)
#if defence_2==2:
# if(attacker <= 2):
# success_2 = 1
# success_2_count+=1
x_point.append(i)
#y_point_0.append(success_0_count/i)
#y_point_1.append(success_1_count/i)
#y_point_2.append(success_2_count/i)
for j in range(i+1):
y_point_0.append(success_0_count/i*100)
y_point_1.append(success_1_count/i*100)
y_point_2.append(success_2_count/i*100)
y_point_Real.append(success_real_count/i*100)
if (j%100==0):
print(f'i = {i} and RE = {y_point_0}and RE = {y_point_1}and RE = {y_point_2}and RE = {y_point_Real}')
#print(len(y_point_2), i, len(x_point))
plt_x = np.array(x_point)
plt_y = np.array(y_point_0)
key0, = plt.plot(plt_x, plt_y, label ='Defence: Level-0')
#plt_x = np.array(x_point)
plt_y = np.array(y_point_1)
key1, = plt.plot(plt_x, plt_y, label ='Defence: Level-1')
plt_x = np.array(x_point)
plt_y = np.array(y_point_2)
key2, = plt.plot(plt_x, plt_y, label ='Defence: Level-2')
plt_x = np.array(x_point)
plt_y = np.array(y_point_Real)
keyReal, = plt.plot(plt_x, plt_y, label ='SimDefence: Level-Real')
# Set Axes
plt.xlim(left=0)
leg = plt.legend(loc='upper center')
plt.xlabel('Time (cycle)')
plt.ylabel('Defence Sucess Rate (%)')
plt.title('Success Rate against Times')
plt.show()
print(success_0_count,success_1_count,success_2_count,success_real_count)
print()