-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
127 lines (88 loc) · 3.91 KB
/
app.py
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
from flask import Flask, render_template, request
from python.run_algorithms import RunAlgorithms
app = Flask(__name__)
# Route for the home page
@app.route('/')
def home():
return render_template('index.html')
# Route for the FCFS Algorithm page
@app.route('/fcfs', methods=['GET', 'POST'])
def fcfs():
if request.method == 'POST':
arrival_times = request.form.get('arrival-time')
burst_times = request.form.get('burst-time')
return RunAlgorithms().run_fcfs(arrival_times, burst_times)
return render_template('fcfs.html')
# Route for the SJF Non-SjfPreemptive Algorithm page
@app.route('/sjf-non-preemptive', methods=['GET', 'POST'])
def sjf_non_preemptive():
if request.method == 'POST':
arrival_times = request.form.get('arrival-time')
burst_times = request.form.get('burst-time')
return RunAlgorithms().run_sjfnp(arrival_times, burst_times)
return render_template('sjf_non_preemptive.html')
# Route for the SJF SjfPreemptive Algorithm page
@app.route('/sjf-preemptive', methods=['GET', 'POST'])
def sjf_preemptive():
if request.method == 'POST':
arrival_times = request.form.get('arrival-time')
burst_times = request.form.get('burst-time')
return RunAlgorithms().run_sjfp(arrival_times, burst_times)
return render_template('sjf_preemptive.html')
# Route for the Priority Scheduling Algorithm page
@app.route('/priority-scheduling', methods=['GET', 'POST'])
def priority_scheduling():
if request.method == 'POST':
arrival_times = request.form.get('arrival-time')
burst_times = request.form.get('burst-time')
priority = request.form.get('priority')
return RunAlgorithms().run_priority(arrival_times, burst_times, priority)
return render_template('priority_scheduling.html')
# Route for the Round Robin Algorithm page
@app.route('/round-robin', methods=['GET', 'POST'])
def round_robin():
if request.method == 'POST':
arrival_times = request.form.get('arrival-time')
burst_times = request.form.get('burst-time')
time_quantum = request.form.get('time-quantum')
return RunAlgorithms().run_rr(arrival_times, burst_times, time_quantum)
return render_template('round_robin.html')
# Route for Compare Algorithm page
@app.route('/compare', methods=['GET', 'POST'])
def compare():
global global_arrival_times
global global_burst_times
global global_time_quantum
global global_priority
global algo
global gtta
if request.method == 'POST':
algo = request.form.get('algo')
print('Algorithm accessed : ', algo)
if algo is None:
global_arrival_times = request.form.get('arrival-time')
global_burst_times = request.form.get('burst-time')
global_time_quantum = request.form.get('time-quantum')
global_priority = request.form.get('priority')
else:
run = RunAlgorithms()
global_time_quantum = request.form.get('tQ')
global_priority = request.form.get('priority')
if algo == 'fcfs':
return run.run_fcfs(global_arrival_times, global_burst_times)
elif algo == 'sjfnp':
return run.run_sjfnp(global_arrival_times, global_burst_times)
if algo == 'sjfp':
return run.run_sjfp(global_arrival_times, global_burst_times)
elif algo == 'priority':
return run.run_priority(global_arrival_times, global_burst_times, global_priority)
elif algo == 'rr':
return run.run_rr(global_arrival_times, global_burst_times, global_time_quantum)
return render_template('compare.html', at=global_arrival_times, bt=global_burst_times)
# Route for returning to the main menu
@app.route('/index')
def index():
return render_template('index.html')
if __name__ == "__main__":
# app.run(debug=True)
app.run(host="0.0.0.0", port=5000)