-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPriority.html
More file actions
185 lines (126 loc) · 4.25 KB
/
Priority.html
File metadata and controls
185 lines (126 loc) · 4.25 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<!DOCTYPE html>
<html>
<head>
<title>Priority Scheduling Algorithm</title>
<script type="text/javascript" src="lib/jquery.js"></script>
<script type="text/javascript" src="lib/jquery.color.js"></script>
<link rel="stylesheet" type="text/css" href="lib/bootstrap.css">
<link rel="stylesheet" type="text/css" href="lib/aos.css">
<script type="text/javascript" src="lib/aos.js"></script>
<style type="text/css">
body {
background: -webkit-linear-gradient(to left, #ECE9E6 , #FFFFFF);
background: linear-gradient(to left, #ECE9E6 , #FFFFFF);
}
td {
text-align: center;
vertical-align: middle;
}
img {
width: 5%;
margin-left: -30px;
}
</style>
</head>
<body>
<script>
AOS.init({
duration: 1000
});
</script>
<br/><br/>
<div class="container">
<div data-aos="zoom-out-left">
<h1><a href="index.html"><img src="lib/icon.png" /></a> Priority Scheduling Algorithm</h1><br/><br/>
</div>
<div data-aos="fade-left">
<strong>Enter number of program:</strong>
<div class="row-lg-12">
<div class="col-lg-3">
<input type="" id="count" class="form-control">
</div></div>
<input type="button" id="ok" value="Show Programs" class="btn btn-warning">
<input type="button" value="RUN PROCESS" id="run" class="btn btn-danger"><br/>
<br/>
<p> <b>Programs</b> </p>
<br/><br/>
<table border="2" width="900px" style="box-shadow: 10px 10px 20px black;">
</table>
<span></span>
</div>
<br/><br/><br/><br/>
<script type="text/javascript">
$("#ok").click(function(){
// generate ng input box
c = $("#count").val();
for (var i = 1; i <= c; i++){
$("p").append('<br/><div data-aos="fade-right"><div class="row-lg-12"><div class="container"><div class="col-lg-1">Program' + i + '</div><div class="col-lg-1">Burst</div><div class="col-lg-2"><input type="text" id="b'+i+'" class="form-control"></div><div class="col-lg-1">Priority</div><div class="col-lg-2"><input type="text" id="p'+i+'" class="form-control"></div></div></div></div>');
$("table").append('<td id="td'+i+'"></td>');
}
});
$("#run").click(function(){
val = 0;
arr = Array();
//para sa pag sum ng lahat ng value sa textbox
for (var i = 0; i < c; i++) {
$("#b"+(i+1)+"").each(function() {
val +=parseInt($(this).val());
});
arr[i] = $("#b"+(i+1)+"").val();
}
total = val;
// para sa pagkuha ng percent
for (var i = 0; i < c; i++) {
y = arr[i];
x = total;
arr[i] = Math.floor((y/x)*100);
}
arrSort = Array(50);
for (var i = 0; i <= c; i++) {
arrSort[i] = new Array(50);
}
for (var i = 0; i < c; i++) {
for (var j= 0; j < 1; j++) {
arrSort[i][0] = $('#p'+(i+1)+'').val(); // value ng priority
arrSort[i][1] = $('#b'+(i+1)+'').val(); // value ng burst
arrSort[i][2] = arr[i]; // percentage
arrSort[i][3] = (i+1); // program number
}
}
// sort first section of array
arrSort.sort(sortFunction);
function sortFunction(a, b) {
if (a[0] === b[0]) {
return 0;
}
else {
return (a[0] < b[0]) ? -1 : 1;
}
}
for (var i = 1; i <= c; i++) {
for (var j= 0; j < 1; j++) {
console.log(arrSort[i][0]); // value ng priority
console.log(arrSort[i][1]); // value ng burst
console.log(arrSort[i][2]); // percentage
console.log(arrSort[i][3]); // program number
}
}
col = Array("#89070b","#d06960","#e8d568","#2bb1e0","#fea45d","#fd6c3d","#b9353a","#b86a30","#f4c685","#8c6f50","#6e6e71","#ffc296","#cbe6ea","#30688b","#476663","#8a0001","#d76001","#eacb86","#f1cbff","#c9c9ff","#ffbdbd","#e1f7d5","#d9d7d8","#bcd7cf","#f8dfca","#d6928b","#e8e1d7","#e9b481","#ea5c7d","#edbcc0","#e9b481","#d9d7d8","#bcd7cf","#f8dfca","#d6928b","#e8e1d7","#e9b481","#ea5c7d","#edbcc0","#e9b481");
i = 1; // loop the animation
sum = 0;
myLoop();
function myLoop(){
setTimeout(function(){
sum += parseInt(arrSort[i][1]);
console.log(sum);
$("#td"+i+"").replaceWith('<td style="background-color: '+col[Math.floor(Math.random() * col.length)]+'" height="100px" width="'+arrSort[i][2]+'%">P'+arrSort[i][3]+': Value: '+sum+'</td>');
i++;
if(i <= c) {
myLoop();
}
},1000)
}
});
</script>
</body>
</html>