-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
138 lines (123 loc) · 5.01 KB
/
app.py
File metadata and controls
138 lines (123 loc) · 5.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
from flask import Flask, render_template, request
import Algorithms.fcfs as FCFS
import Algorithms.sjf_non_pre as SJFNPE
import Algorithms.sjfpre as SJFPE
import Algorithms.priority as PRIORITY
import Algorithms.rr as RR
import pandas as pd
import math
app = Flask(__name__, template_folder="templates", static_folder="static")
@app.route("/")
def form():
return render_template("form.html")
@app.route("/result", methods=["POST", "GET"])
def result():
if request.method == "POST":
which_fastest = dict()
finalRes = []
speed = int(request.form["speed"])
n = int(request.form["noOfPr"])
algoName = request.form.getlist("algo")
pr_no = list(map(int, request.form["pr_no"].replace(',', ' ').split()))
arrival = list(
map(int, request.form["arrival"].replace(',', ' ').split()))
burst = list(map(int, request.form["burst"].replace(',', ' ').split()))
if "FCFS" in algoName:
Tpr_no, Tarrival, Tburst = FCFS.sort_by_arrival(
pr_no, arrival, burst, n)
wait, TAT, comp, avgWT, avgTAT = FCFS.findAllTimes(
Tpr_no, Tarrival, Tburst, n
)
FCFS.plot(Tpr_no, Tarrival, Tburst, n, speed)
temp = [
"First Come First Serve",
Tpr_no,
Tarrival,
Tburst,
wait,
TAT,
comp,
avgWT,
avgTAT,
]
which_fastest["First Come First Serve"] = [sum(comp)/n, avgWT]
finalRes.append(temp)
if "SJFNPE" in algoName:
# The completion time of all processes
comp = [0 for i in range(n)]
Tpr_no, Tarrival, Tburst = SJFNPE.sort_by_arrival(
pr_no, arrival, burst, n)
(
Tpr_no,
Tarrival,
Tburst,
comp,
wait,
TAT,
avgWT,
avgTAT,
) = SJFNPE.findAllTimes(Tpr_no, Tarrival, Tburst, comp, n)
SJFNPE.plot(Tpr_no, Tarrival, Tburst, n, comp, speed)
temp = [
"SJF Non Preemptive",
Tpr_no,
Tarrival,
Tburst,
wait,
TAT,
comp,
avgWT,
avgTAT,
]
which_fastest["SJF Non Preemptive"] = [sum(comp)/n, avgWT]
finalRes.append(temp)
if "SJFPE" in algoName:
result = pd.DataFrame()
result, avgTAT, avgWT = SJFPE.processData(
n, pr_no, arrival, burst, speed)
temp = ["SJF Preemptive", sorted(pr_no), list(result["arrival_time"]), list(result["burst_time"]),
list(result["waiting_time"]), list(result["turnaround_time"]), list(result["completion_time"]), avgWT, avgTAT]
which_fastest["SJF Preemptive"] = [
sum(list(result["completion_time"]))/n, avgWT]
finalRes.append(temp)
if "Priority" in algoName:
priority = list(
map(int, request.form["priority"].replace(',', ' ').split()))
result = pd.DataFrame()
result, avgTAT, avgWT = PRIORITY.processData(
n, pr_no, arrival, burst, priority, speed)
temp = ["Priority", sorted(pr_no), list(result["arrival_time"]), list(result["burst_time"]),
list(result["waiting_time"]), list(result["turnaround_time"]), list(result["completion_time"]), avgWT, avgTAT, priority]
which_fastest["Priority"] = [
sum(list(result["completion_time"]))/n, avgWT]
finalRes.append(temp)
if "RR" in algoName:
result = pd.DataFrame()
quantum = int(request.form["timeSlice"])
result, avgTAT, avgWT = RR.processData(
n, quantum, pr_no, arrival, burst, speed)
temp = ["Round Robin", sorted(pr_no), list(result["arrival_time"]), list(result["burst_time"]),
list(result["waiting_time"]), list(result["turnaround_time"]), list(result["completion_time"]), avgWT, avgTAT, quantum]
which_fastest["Round Robin"] = [
sum(list(result["completion_time"]))/n, avgWT]
finalRes.append(temp)
print(which_fastest)
fastest_ct, fastest_ct_name = math.inf, None
fastest_wt, fastest_wt_name = math.inf, None
for key, val in which_fastest.items():
if val[0] < fastest_ct:
fastest_ct = val[0]
fastest_ct_name = key
if val[1] < fastest_wt:
fastest_wt = val[1]
fastest_wt_name = key
return render_template(
"result.html",
finalRes=finalRes,
fastest_ct=fastest_ct,
fastest_ct_name=fastest_ct_name,
fastest_wt=fastest_wt,
fastest_wt_name=fastest_wt_name
)
if __name__ == "__main__":
app.run(debug=True)