Skip to content

Commit 3b62fc9

Browse files
committed
Added checker if GTChart.png already exist in order to delete the file if it does
1 parent 937ffe8 commit 3b62fc9

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed
2.08 KB
Loading

CPU_Scheduler/Optimized_Version/PreemptivePriorityScheduling.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from random import randint, seed
22
from copy import deepcopy
33
from matplotlib import pyplot as plt
4-
import numpy as np
4+
import numpy as np
5+
import os
56

67
class _PreemptivePriorityScheduling:
78
process_list = []
@@ -91,30 +92,30 @@ def schedulingProcess(self):
9192

9293
self.TT = total_wt / len(self.process_list)
9394
self.WT = total_tt / len(self.process_list)
94-
95+
print(cur_process_data)
9596
return cur_process_data
9697

9798
def plot_gantt_chart(self, cur_process_data):
9899
fig, gnt = plt.subplots()
99100
gnt.set_xlabel('Time')
100101
gnt.set_ylabel('Processes')
101102

102-
try:
103-
colors = plt.cm.viridis(np.linspace(0, 1, len(cur_process_data)))
104103

105-
for i, (key, value) in enumerate(cur_process_data.items()):
106-
process_name = value[0]
107-
start_time = value[1]
108-
end_time = value[2]
104+
colors = plt.cm.viridis(np.linspace(0, 1, len(cur_process_data)))
105+
106+
for i, (key, value) in enumerate(cur_process_data.items()):
107+
process_name = value[0]
108+
start_time = value[1]
109+
end_time = value[2]
109110

110-
color = colors[i]
111-
gnt.broken_barh([(start_time, end_time - start_time)], (0, 1), facecolors=(color))
111+
color = colors[i]
112+
gnt.broken_barh([(start_time, end_time - start_time)], (0, 1), facecolors=(color))
112113

113-
gnt.text(start_time + 1, 1, process_name, verticalalignment='center', horizontalalignment='center', color='black')
114+
gnt.text(start_time + 1, 1, process_name, verticalalignment='center', horizontalalignment='center', color='black')
115+
if os.path.isfile("GTChart.png"):
116+
os.remove("GTChart.png")
117+
plt.savefig("GTChart.png", bbox_inches='tight', dpi=150)
114118

115-
plt.savefig("./GANTT_OUTPUT/GTChart.png", bbox_inches='tight', dpi=100)
116-
except:
117-
plt.savefig("./GANTT_OUTPUT/GTChart.png", bbox_inches='tight', dpi=100)
118119

119120
def runner(process_list):
120121
proseso = _PreemptivePriorityScheduling()
84 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)