diff --git a/app/Exports/PrediksiExport.php b/app/Exports/PrediksiExport.php index df0fa21..cc009ea 100644 --- a/app/Exports/PrediksiExport.php +++ b/app/Exports/PrediksiExport.php @@ -15,10 +15,7 @@ public function collection() $dataUji = DataUji::select([ 'kecamatan', 'data_tahun', - 'jumlah_penduduk', 'phbs', - 'imunisasi_pcv_1', - 'imunisasi_pcv_2', 'rata_rata_imunisasi', 'perilaku_merokok', 'data_kasus', @@ -28,11 +25,8 @@ public function collection() ])->get()->map(function ($item) { return [ $item->kecamatan, - $item->jumlah_penduduk, $item->data_tahun, $item->phbs, - $item->imunisasi_pcv_1, - $item->imunisasi_pcv_2, $item->rata_rata_imunisasi, $item->perilaku_merokok, $item->data_kasus, @@ -45,11 +39,8 @@ public function collection() $hasilPengujian = HasilPengujian::select([ 'kecamatan', - 'jumlah_penduduk', 'data_tahun', 'phbs', - 'pcv1', - 'pcv2', 'imunisasi', 'merokok', 'jumlah_kasus', @@ -60,11 +51,8 @@ public function collection() ])->get()->map(function ($item) { return [ $item->kecamatan, - $item->jumlah_penduduk, $item->data_tahun, $item->phbs, - $item->pcv1, - $item->pcv2, $item->imunisasi, $item->merokok, $item->jumlah_kasus, @@ -83,11 +71,8 @@ public function headings(): array { return [ 'Kecamatan', - 'Jumlah Penduduk', 'Data Tahun', 'PHBS', - 'PCV1', - 'PCV2', 'Imunisasi', 'Merokok', 'Jumlah Kasus', @@ -97,4 +82,4 @@ public function headings(): array 'Status Prediksi', ]; } -} +} \ No newline at end of file diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index 8f0bf8d..0a38f14 100644 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -10,7 +10,21 @@ class DashboardController extends Controller // Fungsi default, menampilkan data untuk tahun 2023 public function index(Request $request) { - $tahunTerpilih = 2023; + // Ambil tahun-tahun yang tersedia dari data_latih + $tahunTersedia = DB::table('data_latih') + ->select('data_tahun') + ->distinct() + ->orderByDesc('data_tahun') + ->pluck('data_tahun'); + + // Ambil tahun dari request (GET), kalau tidak ada pakai yang paling atas (terbaru) + $selectedYear = $request->input('tahun', $tahunTersedia->first()); + + // Hitung total kasus berdasarkan tahun yang dipilih + $jumlahKasusDataLatih = DB::table('data_latih') + ->where('data_tahun', $selectedYear) + ->sum('kasus_2023'); + $data_latih = DB::table('data_latih')->get(); $stats = DB::table('data_latih') ->selectRaw(' @@ -23,7 +37,10 @@ public function index(Request $request) ') ->first(); - $jumlahKasusDataLatih = DB::table('data_latih')->sum('kasus_2023'); + // Ambil semua kolom dari tabel data_latih + $columns = DB::getSchemaBuilder()->getColumnListing('data_latih'); + + $selectedYear = $request->input('tahun') ?? $tahunTersedia->first(); $kabupatens = DB::table('kabupatens') ->join('data_latih', 'kabupatens.nama', '=', 'data_latih.kecamatan') @@ -44,8 +61,12 @@ public function index(Request $request) ->orderByDesc('tahun') ->pluck('tahun'); - // Ambil tahun yang dipilih dari input user (jika ada), jika tidak pakai default - $selectedYear = $request->input('year') ?? $tahunTerpilih; + if (!$selectedYear) { + $selectedYear = DB::table('data_latih') + ->orderByDesc('data_tahun') + ->value('data_tahun'); // Ambil 1 nilai tahun terbaru + } + // Data kasus per bulan untuk tahun yang dipilih $kasusPerBulan = DB::table('kasus') @@ -84,7 +105,8 @@ public function index(Request $request) 'kasusPerBulanByYear', 'availableYears', 'selectedYear', - 'tahunTerpilih' + 'tahunTersedia', + 'selectedYear' )); } @@ -108,7 +130,10 @@ public function dashboard(Request $request) ') ->first(); - $jumlahKasusDataLatih = DB::table('data_latih')->sum('kasus_2023'); +$jumlahKasusDataLatih = DB::table('data_latih') + ->where('data_tahun', $tahunTerpilih) + ->sum('kasus_2023'); + $kabupatens = DB::table('kabupatens') ->join('data_latih', 'kabupatens.nama', '=', 'data_latih.kecamatan') @@ -160,4 +185,4 @@ public function dashboard(Request $request) 'selectedYear' )); } -} +} \ No newline at end of file diff --git a/app/Http/Controllers/ImportController.php b/app/Http/Controllers/ImportController.php index b4dcfe5..8b601f3 100644 --- a/app/Http/Controllers/ImportController.php +++ b/app/Http/Controllers/ImportController.php @@ -24,23 +24,20 @@ public function import(Request $request) foreach ($rows as $index => $row) { if ($index === 0) continue; // skip header - $kecamatan = trim($row[1]); // Kolom ke-1: Kecamatan (index 1 karena id di kolom 0) + $kecamatan = trim($row[1]); // Kolom ke-1: Kecamatan if (empty($kecamatan)) continue; $dataToInsert[] = [ 'kecamatan' => $kecamatan, - 'jumlah_penduduk' => is_numeric($row[2]) ? (int)$row[2] : 0, // kolom 2 - 'data_tahun' => is_numeric($row[3]) ? (int)$row[3] : 2023, // kolom 3 - 'phbs' => is_numeric($row[4]) ? (float)$row[4] : 0, - 'pcv1' => is_numeric($row[5]) ? (float)$row[5] : 0, - 'pcv2' => is_numeric($row[6]) ? (float)$row[6] : 0, - 'imunisasi' => is_numeric($row[7]) ? (float)$row[7] : 0, - 'merokok' => is_numeric($row[8]) ? (float)$row[8] : 0, - 'kasus_2023' => is_numeric($row[9]) ? (int)$row[9] : 0, - 'latitude' => is_numeric($row[10]) ? (float)($row[10] / 1000000) : 0, - 'longitude' => is_numeric($row[11]) ? (float)($row[11] / 1000000) : 0, - 'prediksi_tahun' => isset($row[12]) && is_numeric($row[12]) ? (int)$row[12] : null, - 'hipotesis' => isset($row[13]) && $row[13] !== '' ? trim($row[13]) : null, + 'data_tahun' => is_numeric($row[2]) ? (int)$row[2] : 2023, // Data Tahun + 'phbs' => is_numeric($row[3]) ? (float)$row[3] : 0, // PHBS + 'imunisasi' => is_numeric($row[4]) ? (float)$row[4] : 0, // Imunisasi + 'merokok' => is_numeric($row[5]) ? (float)$row[5] : 0, // Perilaku Merokok + 'kasus_2023' => is_numeric($row[6]) ? (int)$row[6] : 0, // Data Kasus + 'latitude' => is_numeric($row[7]) ? (float)($row[7] / 1000000) : 0, // Latitude + 'longitude' => is_numeric($row[8]) ? (float)($row[8] / 1000000) : 0, // Longitude + 'prediksi_tahun' => isset($row[9]) && is_numeric($row[9]) ? (int)$row[9] : null, // Prediksi Tahun + 'hipotesis' => isset($row[10]) && $row[10] !== '' ? trim($row[10]) : null, // Status 'created_at' => now(), 'updated_at' => now(), ]; diff --git a/app/Http/Controllers/UjiController.php b/app/Http/Controllers/UjiController.php index 8f67917..95fe5f4 100644 --- a/app/Http/Controllers/UjiController.php +++ b/app/Http/Controllers/UjiController.php @@ -167,7 +167,7 @@ public function index() } public function proses(Request $request) { - $dataLatih = DataLatih::all(); + $dataLatih = DataLatih::inRandomOrder()->get(); $persentase = (int) $request->input('persentase'); $total = $dataLatih->count(); @@ -203,19 +203,15 @@ public function proses(Request $request) $hipotesisAsli = ucfirst(strtolower($data->hipotesis)); $prediksi = $this->naiveBayes($data, $dataLatihUpdate); - // Prediksi tahun otomatis = data_tahun + 1, jika data_tahun ada - $prediksiTahun = $data->data_tahun ? ((int)$data->data_tahun + 1) : null; + $prediksiTahun = ((int)$data->data_tahun <= 2024) ? 2025 : ((int)$data->data_tahun + 1); $status = $prediksi === $hipotesisAsli ? '✅ Benar' : '❌ Salah'; $hasil[] = [ 'id' => $data->id, 'kabupaten' => $data->kecamatan, - 'jumlah_penduduk' => $data->jumlah_penduduk, 'data_tahun' => $data->data_tahun, 'phbs' => $data->phbs, - 'pcv1' => $data->pcv1, - 'pcv2' => $data->pcv2, 'imunisasi' => $data->imunisasi, 'merokok' => $data->merokok, 'kasus_2023' => $data->kasus_2023, @@ -231,11 +227,8 @@ public function proses(Request $request) if (!$hasilSudahAda) { HasilPengujian::create([ 'kecamatan' => $data->kecamatan, - 'jumlah_penduduk' => $data->jumlah_penduduk, 'data_tahun' => $data->data_tahun, 'phbs' => $data->phbs, - 'pcv1' => $data->pcv1, - 'pcv2' => $data->pcv2, 'imunisasi' => $data->imunisasi, 'merokok' => $data->merokok, 'jumlah_kasus' => $data->kasus_2023 ?? 0, diff --git a/app/Models/DataLatih.php b/app/Models/DataLatih.php index 7b8ab22..213338f 100644 --- a/app/Models/DataLatih.php +++ b/app/Models/DataLatih.php @@ -14,11 +14,8 @@ class DataLatih extends Model // Tambahkan fillable agar bisa mass assignment tanpa error protected $fillable = [ 'kecamatan', - 'jumlah_penduduk', 'data_tahun', 'phbs', - 'pcv1', - 'pcv2', 'imunisasi', 'merokok', 'kasus_2023', diff --git a/database/migrations/2025_04_10_045430_create_data_latih_table.php b/database/migrations/2025_04_10_045430_create_data_latih_table.php index 250c37a..a9ba1ff 100644 --- a/database/migrations/2025_04_10_045430_create_data_latih_table.php +++ b/database/migrations/2025_04_10_045430_create_data_latih_table.php @@ -11,23 +11,20 @@ */ public function up() { - Schema::create('data_latih', function (Blueprint $table) { - $table->id(); - $table->string('kecamatan'); - $table->integer('jumlah_penduduk'); - $table->integer('data_tahun')->nullable(); - $table->float('phbs'); - $table->float('pcv1'); - $table->float('pcv2'); - $table->float('imunisasi'); // rata-rata - $table->float('merokok'); - $table->integer('kasus_2023'); - $table->decimal('latitude', 10, 7); - $table->decimal('longitude', 10, 7); - $table->string('hipotesis')->nullable(); // hasil naive bayes - $table->integer('prediksi_tahun')->nullable(); // <--- tambahkan ini - $table->timestamps(); -}); +Schema::create('data_latih', function (Blueprint $table) { + $table->id(); + $table->string('kecamatan'); + $table->integer('data_tahun')->nullable(); // sesuai: $row[2] + $table->float('phbs'); // sesuai: $row[3] + $table->float('imunisasi'); // sesuai: $row[4] + $table->float('merokok'); // sesuai: $row[5] + $table->integer('kasus_2023'); // sesuai: $row[6] + $table->decimal('latitude', 10, 7); // sesuai: $row[7] / 1000000 + $table->decimal('longitude', 10, 7); // sesuai: $row[8] / 1000000 + $table->integer('prediksi_tahun')->nullable(); // sesuai: $row[9] + $table->string('hipotesis')->nullable(); // sesuai: $row[10] + $table->timestamps(); // created_at & updated_at + }); } /** diff --git a/database/migrations/2025_05_17_182359_create_hasil_pengujian_table.php b/database/migrations/2025_05_17_182359_create_hasil_pengujian_table.php index c9e1476..0795381 100644 --- a/database/migrations/2025_05_17_182359_create_hasil_pengujian_table.php +++ b/database/migrations/2025_05_17_182359_create_hasil_pengujian_table.php @@ -14,11 +14,8 @@ public function up(): void Schema::create('hasil_pengujian', function (Blueprint $table) { $table->id(); $table->string('kecamatan'); - $table->integer('jumlah_penduduk'); $table->integer('data_tahun')->nullable(); $table->float('phbs'); - $table->float('pcv1'); - $table->float('pcv2'); $table->float('imunisasi'); $table->float('merokok'); $table->integer('jumlah_kasus'); diff --git a/resources/views/admin/dashboard.blade.php b/resources/views/admin/dashboard.blade.php index 26788de..fd8583d 100644 --- a/resources/views/admin/dashboard.blade.php +++ b/resources/views/admin/dashboard.blade.php @@ -4,29 +4,31 @@ @section('content') - + + + + @if(session('login_success')) + + @endif @@ -186,16 +195,35 @@ -
-
+
+
+ + {{-- Dropdown Tahun di Pojok Kanan Atas --}} + @if($tahunTersedia->count() > 1) +
+
+ +
+
+ @endif +
+
Jumlah Kasus

{{ $jumlahKasusDataLatih }}

-

Total kasus Infeksi Saluran Pernapasan Akut pada balita selama 1 tahun

+

Total kasus Infeksi Saluran Pernapasan Akut pada balita di tahun {{ $selectedYear }}

+
+
@@ -204,7 +232,8 @@
-
+
+
@@ -302,59 +331,73 @@ } }); + + + + +