5
5
#time are inputted as space separated
6
6
7
7
import pandas as pd
8
-
8
+ from typing import List
9
9
10
10
11
- def calculate_waitingtime (arrival_time ,burst_time ,no_of_processes ):
11
+ def calculate_waitingtime (
12
+ arrival_time : List [int ],burst_time : List [int ],no_of_processes : int
13
+ ) -> List [int ]:
12
14
13
15
"""
14
16
This function calculates the Waiting Times of each Processes
@@ -34,25 +36,25 @@ def calculate_waitingtime(arrival_time,burst_time,no_of_processes):
34
36
35
37
# Process until all processes gets
36
38
# completed
37
- while ( complete != no_of_processes ) :
39
+ while complete != no_of_processes :
38
40
for j in range (no_of_processes ):
39
- if ( arrival_time [j ]<= increment_time ) :
40
- if ( remaining_time [j ]> 0 ) :
41
- if ( remaining_time [j ]< minm ) :
41
+ if arrival_time [j ]<= increment_time :
42
+ if remaining_time [j ]> 0 :
43
+ if remaining_time [j ]< minm :
42
44
minm = remaining_time [j ]
43
45
short = j
44
46
check = True
45
47
46
- if ( check == False ) :
48
+ if check == False :
47
49
increment_time += 1
48
50
continue
49
51
remaining_time [short ]-= 1
50
52
51
53
minm = remaining_time [short ]
52
- if ( minm == 0 ) :
54
+ if minm == 0 :
53
55
minm = 999999999
54
56
55
- if ( remaining_time [short ] == 0 ) :
57
+ if remaining_time [short ] == 0 :
56
58
complete += 1
57
59
check = False
58
60
@@ -64,13 +66,15 @@ def calculate_waitingtime(arrival_time,burst_time,no_of_processes):
64
66
finar = finish_time - arrival_time [short ]
65
67
waiting_time [short ] = (finar - burst_time [short ])
66
68
67
- if ( waiting_time [short ] < 0 ) :
69
+ if waiting_time [short ] < 0 :
68
70
waiting_time [short ] = 0
69
71
70
72
# Increment time
71
73
increment_time += 1
72
74
return waiting_time
73
- def calculate_turnaroundtime (burst_time , no_of_processes , waiting_time ):
75
+ def calculate_turnaroundtime (
76
+ burst_time : List [int ], no_of_processes : int , waiting_time : List [int ]
77
+ ) -> List [int ]:
74
78
"""
75
79
This function calculates the Turn Around Times of each Processes
76
80
Return: list of Turn Around Time.
@@ -85,7 +89,9 @@ def calculate_turnaroundtime(burst_time, no_of_processes, waiting_time):
85
89
for i in range (no_of_processes ):
86
90
turn_around_time [i ] = burst_time [i ] + waiting_time [i ]
87
91
return turn_around_time
88
- def calculate_average_times (waiting_time ,turn_around_time , no_of_processes ):
92
+ def calculate_average_times (
93
+ waiting_time : List [int ],turn_around_time : List [int ], no_of_processes : int
94
+ ):
89
95
"""
90
96
This function calculates the average of the waiting & turnaround times
91
97
Prints: Average Waiting time & Average Turn Around Time
@@ -104,7 +110,7 @@ def calculate_average_times(waiting_time,turn_around_time, no_of_processes):
104
110
for i in range (no_of_processes ):
105
111
total_waiting_time = total_waiting_time + waiting_time [i ]
106
112
total_turn_around_time = total_turn_around_time + turn_around_time [i ]
107
- print ("\n Average waiting time = %.5f " % (
113
+ print ("Average waiting time = %.5f " % (
108
114
total_waiting_time / no_of_processes ) )
109
115
print ("Average turn around time = " ,
110
116
total_turn_around_time / no_of_processes )
@@ -134,4 +140,3 @@ def calculate_average_times(waiting_time,turn_around_time, no_of_processes):
134
140
# Printing the dataFrame
135
141
pd .set_option ('display.max_rows' , fcfs .shape [0 ]+ 1 )
136
142
print (fcfs )
137
-
0 commit comments