Skip to content

Commit 641933d

Browse files
committed
:fix metode WMA
1 parent 49f481f commit 641933d

File tree

2 files changed

+147
-10
lines changed

2 files changed

+147
-10
lines changed

index.php

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,142 @@
2626
* THE SOFTWARE.
2727
*
2828
*/
29+
30+
include "vendor/autoload.php";
31+
32+
$data = [
33+
[
34+
"bulan" => "januari",
35+
"tahun" => 2018,
36+
"penjualan" => 89,
37+
],
38+
[
39+
"bulan" => "februari",
40+
"tahun" => 2018,
41+
"penjualan" => 95,
42+
],
43+
[
44+
"bulan" => "maret",
45+
"tahun" => 2018,
46+
"penjualan" => 85,
47+
],
48+
[
49+
"bulan" => "april",
50+
"tahun" => 2018,
51+
"penjualan" => 75,
52+
],
53+
[
54+
"bulan" => "mei",
55+
"tahun" => 2018,
56+
"penjualan" => 86,
57+
],
58+
[
59+
"bulan" => "juni",
60+
"tahun" => 2018,
61+
"penjualan" => 100,
62+
],
63+
[
64+
"bulan" => "juli",
65+
"tahun" => 2018,
66+
"penjualan" => 120,
67+
],
68+
[
69+
"bulan" => "agustus",
70+
"tahun" => 2018,
71+
"penjualan" => 95,
72+
],
73+
[
74+
"bulan" => "september",
75+
"tahun" => 2018,
76+
"penjualan" => 80,
77+
],
78+
[
79+
"bulan" => "oktober",
80+
"tahun" => 2018,
81+
"penjualan" => 92,
82+
],
83+
[
84+
"bulan" => "november",
85+
"tahun" => 2018,
86+
"penjualan" => 92,
87+
],
88+
[
89+
"bulan" => "desember",
90+
"tahun" => 2018,
91+
"penjualan" => 88,
92+
],
93+
[
94+
"bulan" => "januari",
95+
"tahun" => 2018,
96+
"penjualan" => 90,
97+
],
98+
[
99+
"bulan" => "februari",
100+
"tahun" => 2018,
101+
"penjualan" => 95,
102+
],
103+
[
104+
"bulan" => "maret",
105+
"tahun" => 2018,
106+
"penjualan" => 100,
107+
],
108+
[
109+
"bulan" => "april",
110+
"tahun" => 2018,
111+
"penjualan" => 102,
112+
],
113+
[
114+
"bulan" => "mei",
115+
"tahun" => 2018,
116+
"penjualan" => 100,
117+
],
118+
[
119+
"bulan" => "juni",
120+
"tahun" => 2018,
121+
"penjualan" => 104,
122+
],
123+
];
124+
125+
use Nagara\Src\Metode\MetodeWMA;
126+
127+
// initialize metode
128+
$metode = new MetodeWMA;
129+
$pergerakan = 3;
130+
131+
$metode->proses($data, "penjualan", $pergerakan);
132+
133+
$normalisasi = $metode->getNormalisasi();
134+
$prediksi = $metode->getResult();
135+
$sum = $metode->getSum();
136+
137+
// dd($sum);
138+
139+
?>
140+
141+
<h3>Example metode WMA Hasil Dalam Bentuk Table</h3>
142+
<p>dengan pergerakan = <?=$pergerakan?></p>
143+
<table border="1">
144+
<tr>
145+
<th>No<th>
146+
<th>normalisasi</th>
147+
<th>sum</th>
148+
<th>prediksi</th>
149+
</tr>
150+
<?php $no = 1?>
151+
<?php foreach ($normalisasi as $key => $value): ?>
152+
<tr>
153+
<td><?=$no++?><td>
154+
<td><?=$normalisasi[$key]?></td>
155+
<?php if (!isset($sum[$key])): ?>
156+
<td> - </td>
157+
<?php else: ?>
158+
<td><?=$sum[$key]?></td>
159+
<?php endif;?>
160+
<?php if (!isset($prediksi[$key])): ?>
161+
<td> - </td>
162+
<?php else: ?>
163+
<td><?=$prediksi[$key]?></td>
164+
<?php endif;?>
165+
</tr>
166+
<?php endforeach;?>
167+
</table>

src/metode/weight-moving-average/MetodeWMA.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,27 +115,25 @@ public function proses($data = [], $field = "", $pergerakan = 6)
115115
// menghitung berdasarkan pergerakan
116116
$pergerakan_w = $pergerakan;
117117

118-
// $slicedata = array_slice(self::$normalisasi_data,0, $pergerakan);
119-
// $peramalan = array_sum($slicedata) / count($slicedata);
120-
121118
$peramalan = [];
122119
// step 0
123120
$slicedata;
124121
foreach (self::$normalisasi_data as $iteration => $value) {
125122
$slicedata[$iteration] = array_slice(self::$normalisasi_data, $iteration, $pergerakan_w);
126-
// array_push($container_1, $slicedata);
127-
// $hasil = array_sum($slicedata) / count($slicedata);
128-
// $peramalan[$pergerakan++] = $hasil;
129123
}
130124

131-
// dump($slicedata);
132125
// step 3 mencari jumlah n pergerakan
133126
$hasil = 0;
134127
for ($i = 1; $i <= $pergerakan_w; $i++) {
135128
$hasil += $i;
136129
}
137-
// echo "pergerakan n";
138-
// dump($hasil);
130+
131+
// step 3.1 kalikan data dengan bobot
132+
foreach ($slicedata as $key => $value) {
133+
foreach ($value as $index => $nilai) {
134+
$slicedata[$key][$index] = ($nilai * ($index + 1));
135+
}
136+
}
139137

140138
// step 4 dapat jumlah bagian atas / sum
141139
foreach ($slicedata as $index => $value) {
@@ -146,7 +144,7 @@ public function proses($data = [], $field = "", $pergerakan = 6)
146144
$sum = [];
147145
$pergerakan_s = $pergerakan;
148146
foreach ($slicedata as $key => $value) {
149-
$sum[$pergerakan_s++] = "{$value}/{$hasil}";
147+
$sum[$pergerakan_s++] = "($value/$hasil)";
150148
}
151149
self::$hasil_sum = $sum;
152150

0 commit comments

Comments
 (0)