Skip to content

Commit a48d8b0

Browse files
committed
cleaned up code
1 parent d15d679 commit a48d8b0

File tree

4 files changed

+84
-89
lines changed

4 files changed

+84
-89
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# cpu_scheduling_algo_simulator

algo_sim.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626

2727
exec('./target/simulator '.$input, $output, $return_stat);
2828

29-
echo "<table id=\"output_tab\">
29+
$html_ouput;
30+
$html_output = "<table id=\"output_tab\">
3031
<tr>
3132
<th>PID</th><th>BURST TIME</th><th>WAITING TIME</th><th>TURN-AROUND TIME</th>
3233
</tr>";
@@ -37,13 +38,10 @@
3738
foreach ($temp as $result) {
3839
$str = $str."<td>".$result."</td>";
3940
}
40-
echo "<tr>".$str."</tr>";
41+
$html_output .= "<tr>".$str."</tr>";
4142
}
42-
echo "</table>";
43-
echo "<h4>AVERAGE WAITING TIME: ".$output[$num_proc]."<br>AVERAGE TURN-AROUND TIME: ".$output[$num_proc+1]."</h4>";
44-
echo "<h4>GANTT CHART<br></h4>";
43+
$html_output .= "</table><h4>AVERAGE WAITING TIME: ".$output[$num_proc]."<br>AVERAGE TURN-AROUND TIME: ".$output[$num_proc+1]."</h4><h4>GANTT CHART<br></h4><table id=\"gantt_chart\">";
4544

46-
echo "<table id=\"gantt_chart\">";
4745
$temp = explode(" ",$output[$num_proc+2]);
4846
$time = array_slice(explode(" ",$output[$num_proc+3]),1);
4947
$str="";
@@ -57,7 +55,7 @@
5755
$str = $str."<th style=\"width:".((int)$time[$i]-(int)$time[$i-1])*$px."px\">P".$result."</th>";
5856
$i++;
5957
}
60-
echo "<tr>".$str."</tr>";
58+
$html_output .= "<tr>".$str."</tr>";
6159

6260
$str="";
6361
$i=0;
@@ -68,6 +66,7 @@
6866
$str = $str."<td><div style=\"float:right\">".$result."</div></td>";
6967
$i++;
7068
}
71-
echo "<tr>".$str."</tr></table>";
69+
$html_output .= "<tr>".$str."</tr></table>";
7270

71+
echo $html_output;
7372
?>

js/simulator.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
var count=1;
2+
var input = [];
3+
4+
function add_row() {
5+
let table = document.getElementById("input_tab");
6+
let x = document.getElementById("input_tab").rows[0].cells.length;
7+
8+
let newrow = table.insertRow(-1);
9+
10+
let arr = [];
11+
let i=0;
12+
for ( i=0;i<x;i++ ) {
13+
arr[i] = newrow.insertCell(i);
14+
}
15+
16+
count++;
17+
let newtext = document.createTextNode(count);
18+
arr[0].appendChild(newtext);
19+
20+
for( i=1;i<x;i++ ) {
21+
let newinput = document.createElement("INPUT");
22+
newinput.setAttribute("type","text");
23+
arr[i].appendChild(newinput);
24+
}
25+
}
26+
27+
function rem_row() {
28+
let table = document.getElementById("input_tab");
29+
table.deleteRow(-1);
30+
count--;
31+
}
32+
33+
function submit() {
34+
let table = document.getElementById("input_tab");
35+
let r = table.rows.length;
36+
let c = table.rows[0].cells.length;
37+
38+
var i,j;
39+
for( i=1;i<r;i++ ) {
40+
let temp = [];
41+
temp.push(table.rows[i].cells[0].innerHTML);
42+
for( j=1;j<c;j++ ) {
43+
let t = table.rows[i].cells[j].getElementsByTagName("input");
44+
temp.push(t[0].value);
45+
}
46+
input.push(Object.assign({},temp));
47+
}
48+
49+
var json_inp = JSON.stringify(input);
50+
51+
let qtime = document.getElementById("qtime");
52+
let datatosend = 'input='+json_inp;
53+
let urltosend = "algo_sim.php?num_proc="+count;
54+
55+
console.log(qtime);
56+
if( JSON.stringify(qtime) != "null" ) {
57+
urltosend += "&qtime="+qtime.value;
58+
}
59+
60+
$.ajax({
61+
type: "POST",
62+
url: urltosend,
63+
async:true,
64+
data: datatosend,
65+
success: function(output_var) {
66+
console.log(output_var);
67+
document.getElementById("output").innerHTML = output_var;
68+
return true;
69+
},
70+
complete: function() {
71+
console.log("completed");
72+
},
73+
});
74+
}

simulator.php

Lines changed: 2 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,12 @@
11
<html>
22
<head>
33
<title>
4-
sim
4+
simulator
55
</title>
66

77
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
88

9-
<script>
10-
var count=1;
11-
var input = [];
12-
13-
function add_row() {
14-
let table = document.getElementById("input_tab");
15-
let x = document.getElementById("input_tab").rows[0].cells.length;
16-
17-
let newrow = table.insertRow(-1);
18-
19-
let arr = [];
20-
let i=0;
21-
for ( i=0;i<x;i++ ) {
22-
arr[i] = newrow.insertCell(i);
23-
}
24-
25-
count++;
26-
let newtext = document.createTextNode(count);
27-
arr[0].appendChild(newtext);
28-
29-
for( i=1;i<x;i++ ) {
30-
let newinput = document.createElement("INPUT");
31-
newinput.setAttribute("type","text");
32-
arr[i].appendChild(newinput);
33-
}
34-
}
35-
36-
function rem_row() {
37-
let table = document.getElementById("input_tab");
38-
table.deleteRow(-1);
39-
count--;
40-
}
41-
42-
function submit() {
43-
let table = document.getElementById("input_tab");
44-
let r = table.rows.length;
45-
let c = table.rows[0].cells.length;
46-
47-
var i,j;
48-
for( i=1;i<r;i++ ) {
49-
let temp = [];
50-
temp.push(table.rows[i].cells[0].innerHTML);
51-
for( j=1;j<c;j++ ) {
52-
let t = table.rows[i].cells[j].getElementsByTagName("input");
53-
temp.push(t[0].value);
54-
}
55-
input.push(Object.assign({},temp));
56-
}
57-
58-
var json_inp = JSON.stringify(input);
59-
60-
let qtime = document.getElementById("qtime");
61-
let datatosend = 'input='+json_inp;
62-
let urltosend = "algo_sim.php?num_proc="+count;
63-
64-
console.log(qtime);
65-
if( JSON.stringify(qtime) != "null" ) {
66-
urltosend += "&qtime="+qtime.value;
67-
}
68-
69-
$.ajax({
70-
type: "POST",
71-
url: urltosend,
72-
async:true,
73-
data: datatosend,
74-
success: function(output_var) {
75-
console.log(output_var);
76-
document.getElementById("output").innerHTML = output_var;
77-
return true;
78-
},
79-
complete: function() {
80-
console.log("completed");
81-
},
82-
});
83-
}
84-
85-
function display_output() {
86-
87-
}
88-
</script>
9+
<script src="js/simulator.js"></script>
8910

9011
<style>
9112
table,th,td {

0 commit comments

Comments
 (0)