forked from ipang-dwi/SPK-BERBASIS-WEB-DENGAN-METODE-TOPSIS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
analisa.php
370 lines (346 loc) · 13.2 KB
/
analisa.php
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
<?php
session_start();
include('configdb.php');
?>
<!DOCTYPE html>
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="favicon.ico">
<title><?php echo $_SESSION['judul']." - ".$_SESSION['by'];?></title>
<!-- Bootstrap core CSS -->
<link href="ui/css/bootstrap.css" rel="stylesheet">
<link href="ui/css/united.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="ui/css/jumbotron.css" rel="stylesheet">
<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
<!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<!--script src="./index_files/ie-emulation-modes-warning.js"></script-->
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<style>
body {
padding-top: 10px; /* 10px to make the container go all the way to the bottom of the topbar */
background-image:url(img/bg_dotted.png);
</style>
<body>
<div class="container">
<!-- Static navbar -->
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"><?php echo $_SESSION['judul'];?></a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="index.php">Home</a></li>
<li><a href="kriteria.php">Data Kriteria</a></li>
<li><a href="alternatif.php">Data Alternatif</a></li>
<li class="active"><a href="#">Analisa</a></li>
<li><a href="perhitungan.php">Perhitungan</a></li>
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container-fluid -->
</nav>
<ol class="breadcrumb">
<li><a href="index.php">Home</a></li>
<li class="active">Analisa</li>
</ol>
<!-- Main component for a primary marketing message or call to action -->
<div class="panel panel-primary">
<!-- Default panel contents -->
<div class="panel-heading">Analisa</div>
<div class="panel-body">
<div>
<canvas id="canvas"></canvas>
</div>
<br />
<center>
<?php
//echo "<b>Matrix Alternatif - Kriteria</b></br>";
$alt = get_alternatif();
$alt_name = get_alt_name();
$kep = get_kepentingan();
$cb = get_costbenefit();
$k = jml_kriteria();
$a = jml_alternatif();
//echo "<table class='table table-striped table-bordered table-hover'>";
//echo "<thead><tr><th>Alternatif / Kriteria</th><th>K1</th><th>K2</th><th>K3</th><th>K4</th><th>K5</th><th>K6</th></tr></thead>";
for($i=0;$i<$a;$i++){
//echo "<tr><td><b>A".($i+1)."</b></td>";
for($j=0;$j<$k;$j++){
//echo "<td>".$alt[$i][$j]."</td>";
}
//echo "</tr>";
}
//echo "</table><hr>";
// ======================================================================== //
//echo "<b>Matrix Pembagi</b></br>";
//echo "<table class='table table-striped table-bordered table-hover'>";
//echo "<thead><tr><th></th><th>K1</th><th>K2</th><th>K3</th><th>K4</th><th>K5</th><th>K6</th></tr></thead>";
//echo "<tr><td><b>Pembagi</b></td>";
for($i=0;$i<$k;$i++){
$pembagi[$i] = 0;
for($j=0;$j<$a;$j++){
$pembagi[$i] = $pembagi[$i] + pow($alt[$j][$i],2);
}
$pembagi[$i] = round(sqrt($pembagi[$i]),4);
//echo "<td>".$pembagi[$i]."</td>";
}
//echo "</tr>";
//echo "</table><hr>";
// ======================================================================== //
//echo "<b>Matrix Ternormalisasi</b></br>";
//echo "<table class='table table-striped table-bordered table-hover'>";
//echo "<thead><tr><th>Alternatif / Kriteria</th><th>K1</th><th>K2</th><th>K3</th><th>K4</th><th>K5</th><th>K6</th></tr></thead>";
for($i=0;$i<$a;$i++){
//echo "<tr><td><b>A".($i+1)."</b></td>";
for($j=0;$j<$k;$j++){
$nor[$i][$j] = round(($alt[$i][$j] / $pembagi[$j]),4);
//echo "<td>".$nor[$i][$j]."</td>";
}
//echo "</tr>";
}
//echo "</table><hr>";
// ======================================================================== //
//echo "<b>Matrix Terbobot</b></br>";
//echo "<table class='table table-striped table-bordered table-hover'>";
//echo "<thead><tr><th>Alternatif / Kriteria</th><th>K1</th><th>K2</th><th>K3</th><th>K4</th><th>K5</th><th>K6</th></tr></thead>";
for($i=0;$i<$a;$i++){
//echo "<tr><td><b>A".($i+1)."</b></td>";
for($j=0;$j<$k;$j++){
$bob[$i][$j] = round(($nor[$i][$j] * $kep[$j]),4);
//echo "<td>".$bob[$i][$j]."</td>";
}
//echo "</tr>";
}
//echo "</table><hr>";
// ======================================================================== //
//echo "<b>Min Max Berdasarkan Cost Benefit Kriteria</b></br>";
//echo "<table class='table table-striped table-bordered table-hover'>";
//echo "<thead><tr><th></th><th>K1</th><th>K2</th><th>K3</th><th>K4</th><th>K5</th><th>K6</th></tr></thead>";
//echo "<tr><td><b>A+</b></td>";
for($i=0;$i<$k;$i++){
for($j=0;$j<$a;$j++){
$temp[$j] = $bob[$j][$i];
}
if($cb[$i]=='benefit')
$aplus[$i] = max($temp);
if($cb[$i]=='cost')
$aplus[$i] = min($temp);
//echo "<td>".$aplus[$i]."</td>";
}
//echo "</tr>";
//echo "<tr><td><b>A+</b></td>";
for($i=0;$i<$k;$i++){
for($j=0;$j<$a;$j++){
$temp[$j] = $bob[$j][$i];
}
if($cb[$i]=='benefit')
$amin[$i] = min($temp);
if($cb[$i]=='cost')
$amin[$i] = max($temp);
//echo "<td>".$amin[$i]."</td>";
}
//echo "</tr>";
//echo "</table><hr>";
// ======================================================================== //
//echo "<b>Nilai D+ dan D-</b></br>";
//echo "<table class='table table-striped table-bordered table-hover'>";
//echo "<thead><tr><th></th><th>D+</th><th>D-</th></tr></thead>";
for($i=0;$i<$a;$i++){
//echo "<tr><td><b>A".($i+1)."</b></td>";
$dplus[$i] = 0;
for($j=0;$j<$k;$j++){
$dplus[$i] = $dplus[$i] + pow(($aplus[$j] - $bob[$i][$j]),2);
}
$dplus[$i] = round(sqrt($dplus[$i]),4);
//echo "<td>".$dplus[$i]."</td>";
$dmin[$i] = 0;
for($j=0;$j<$k;$j++){
$dmin[$i] = $dmin[$i] + pow(($amin[$j] - $bob[$i][$j]),2);
}
$dmin[$i] = round(sqrt($dmin[$i]),4);
//echo "<td>".$dmin[$i]."</td>";echo "</tr>";
}
//echo "</table><hr>";
// ======================================================================== //
//echo "<b>Hasil Akhir</b></br>";
//echo "<table class='table table-striped table-bordered table-hover'>";
//echo "<thead><tr><th></th><th>V</th></tr></thead>";
for($i=0;$i<$a;$i++){
//echo "<tr><td><b>A".($i+1)."</b></td>";
$v[$i][0] = round(($dmin[$i] / ($dplus[$i]+$dmin[$i])),4);
$v[$i][1] = $alt_name[$i];
//echo "<td>".$v[$i][0]."</td>";
}
//echo "</table><hr>";
usort($v, "cmp");
$i = 0;
while (list($key, $value) = each($v)) {
$hsl[$i] = array($value[1],$value[0]);
$i++;
}
// ======================================================================== //
echo "<b>Hasil Analisa</b></br>";
echo "Berikut ini hasil analisa diurutkan berdasarkan hasil nilai tertinggi. </br>Jadi dapat disimpulkan bahwa Alternatif terbaik adalah <b>".ucwords(($hsl[0][0]))."</b> dengan nilai <b>".$hsl[0][1]."</b>.";
echo "<table class='table table-striped table-bordered table-hover'>";
echo "<thead><tr><th>No.</th><th>Alternatif</th><th>Hasil Akhir</th></tr></thead>";
echo "<tbody>";
for($i=0;$i<$a;$i++){
echo "<tr><td>".($i+1).".</td><td>".ucwords(($hsl[$i][0]))."</td><td>".$hsl[$i][1]."</td></tr>";
}
echo "</tbody></table><hr>";
function jml_kriteria(){
include 'configdb.php';
$kriteria = $mysqli->query("select * from kriteria");
return $kriteria->num_rows;
}
function jml_alternatif(){
include 'configdb.php';
$alternatif = $mysqli->query("select * from alternatif");
return $alternatif->num_rows;
}
function get_kepentingan(){
include 'configdb.php';
$kepentingan = $mysqli->query("select * from kriteria");
if(!$kepentingan){
echo $mysqli->connect_errno." - ".$mysqli->connect_error;
exit();
}
$i=0;
while ($row = $kepentingan->fetch_assoc()) {
@$kep[$i] = $row["kepentingan"];
$i++;
}
return $kep;
}
function get_costbenefit(){
include 'configdb.php';
$costbenefit = $mysqli->query("select * from kriteria");
if(!$costbenefit){
echo $mysqli->connect_errno." - ".$mysqli->connect_error;
exit();
}
$i=0;
while ($row = $costbenefit->fetch_assoc()) {
@$cb[$i] = $row["cost_benefit"];
$i++;
}
return $cb;
}
function get_alt_name(){
include 'configdb.php';
$alternatif = $mysqli->query("select * from alternatif");
if(!$alternatif){
echo $mysqli->connect_errno." - ".$mysqli->connect_error;
exit();
}
$i=0;
while ($row = $alternatif->fetch_assoc()) {
@$alt[$i] = $row["alternatif"];
$i++;
}
return $alt;
}
function get_alternatif(){
include 'configdb.php';
$alternatif = $mysqli->query("select * from alternatif");
if(!$alternatif){
echo $mysqli->connect_errno." - ".$mysqli->connect_error;
exit();
}
$i=0;
while ($row = $alternatif->fetch_assoc()) {
@$alt[$i][0] = $row["k1"];
@$alt[$i][1] = $row["k2"];
@$alt[$i][2] = $row["k3"];
@$alt[$i][3] = $row["k4"];
@$alt[$i][4] = $row["k5"];
@$alt[$i][5] = $row["k6"];
$i++;
}
return $alt;
}
function cmp($a, $b){
if ($a == $b) {
return 0;
}
return ($a > $b) ? -1 : 1;
}
function print_ar(array $x){ //just for print array
echo "<pre>";
print_r($x);
echo "</pre></br>";
}
?>
</center>
</div>
<div class="panel-footer"><?php echo $_SESSION['by'];?><div class="pull-right"></div></div>
</div>
</div> <!-- /container -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="ui/js/jquery-1.10.2.min.js"></script>
<script src="ui/js/bootstrap.min.js"></script>
<script src="ui/js/bootswatch.js"></script>
<script src="ui/js/Chart.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="ui/js/ie10-viewport-bug-workaround.js"></script>
<!-- chart -->
<script>
var randomScalingFactor = function(){ return Math.round(Math.random()*100)};
var barChartData = {
labels : [
<?php
for($i=0;$i<$a;$i++){
echo '"'.ucwords(($v[$i][1])).'",';
}
?>
],
datasets : [
{
fillColor : "rgba(255,255,0,0.5)",
strokeColor : "rgba(220,220,220,0.8)",
highlightFill: "rgba(255,128,0,0.75)",
highlightStroke: "rgba(220,220,220,1)",
data : [
<?php
for($i=0;$i<$a;$i++){
echo $v[$i][0].',';
}
?>
]
},
/*{
fillColor : "rgba(151,187,205,0.5)",
strokeColor : "rgba(151,187,205,0.8)",
highlightFill : "rgba(151,187,205,0.75)",
highlightStroke : "rgba(151,187,205,1)",
data : [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()]
}*/
]
}
window.onload = function(){
var ctx = document.getElementById("canvas").getContext("2d");
window.myBar = new Chart(ctx).Bar(barChartData, {
responsive : true
});
}
</script>
</body></html>