From d55bca99b9cae3f3cad1f3d2a16aeae08b7eef4d Mon Sep 17 00:00:00 2001 From: Yuri Dimas Date: Tue, 9 Dec 2025 18:15:20 +0700 Subject: [PATCH] feat: chart Total Data Terverifikasi & Aktif Transaksi --- Controllers/Main/DashboardController.cs | 48 +++++++- Models/DashboardChartViewModel.cs | 25 ++++ Views/Main/Dashboard/Index.cshtml | 156 +++++++++++++++++++++++- 3 files changed, 224 insertions(+), 5 deletions(-) diff --git a/Controllers/Main/DashboardController.cs b/Controllers/Main/DashboardController.cs index 4c638f4..866d006 100644 --- a/Controllers/Main/DashboardController.cs +++ b/Controllers/Main/DashboardController.cs @@ -35,9 +35,27 @@ namespace BankSampahApp.Controllers.Main ["Offtaker"] = new() { 1050, 1080, 1100, 1140, 1180, 1220, 1260, 1300, 1340, 1380, 1420, 1480 } }; + var entities = new List { "BSI", "BSU", "Offtaker" }; + var verifiedActiveBase = new Dictionary Verified, List Active)> + { + ["BSI"] = ( + new List { 400, 420, 460, 500, 520, 560, 580, 600, 640, 660, 700, 720 }, + new List { 300, 320, 350, 370, 390, 420, 440, 460, 500, 520, 550, 580 } + ), + ["BSU"] = ( + new List { 380, 400, 420, 450, 470, 500, 520, 550, 580, 600, 640, 670 }, + new List { 250, 270, 300, 330, 350, 380, 400, 420, 450, 480, 500, 530 } + ), + ["Offtaker"] = ( + new List { 600, 620, 640, 660, 700, 720, 750, 780, 820, 850, 880, 910 }, + new List { 420, 440, 460, 500, 520, 540, 580, 600, 640, 670, 700, 740 } + ) + }; + var years = Enumerable.Range(2020, 6).ToList(); var firstYear = years.Min(); var yearlyData = new Dictionary(); + var verifiedActiveYearlyData = new Dictionary>(); foreach (var year in years) { @@ -64,12 +82,40 @@ namespace BankSampahApp.Controllers.Main } yearlyData[year] = payload; + + var entityPayloads = new Dictionary(); + foreach (var entity in entities) + { + var basePair = verifiedActiveBase[entity]; + var verifiedRandom = new Random(HashCode.Combine(year, entity, "verified")); + var activeRandom = new Random(HashCode.Combine(year, entity, "active")); + + var verifiedData = basePair.Verified + .Select(baseValue => Math.Max(0, baseValue + verifiedRandom.Next(-60, 90) + offset * 25)) + .ToList(); + + var activeData = basePair.Active + .Select(baseValue => Math.Max(0, baseValue + activeRandom.Next(-40, 75) + offset * 20)) + .ToList(); + + entityPayloads[entity] = new VerifiedActiveChartPayload + { + Labels = new List(monthLabels), + VerifiedData = verifiedData, + ActiveData = activeData + }; + } + + verifiedActiveYearlyData[year] = entityPayloads; } return new DashboardChartViewModel { YearlyData = yearlyData, - SelectedYear = yearlyData.Keys.Max() + SelectedYear = yearlyData.Keys.Max(), + VerifiedActiveYearlyData = verifiedActiveYearlyData, + Entities = entities, + SelectedEntity = entities.FirstOrDefault() ?? string.Empty }; } } diff --git a/Models/DashboardChartViewModel.cs b/Models/DashboardChartViewModel.cs index b14c298..0adbe6a 100644 --- a/Models/DashboardChartViewModel.cs +++ b/Models/DashboardChartViewModel.cs @@ -22,6 +22,21 @@ public class DashboardChartViewModel /// Daftar tahun yang tersedia untuk filter, disortir menurun. /// public IEnumerable AvailableYears => YearlyData.Keys.OrderByDescending(x => x); + + /// + /// Data grafik verifikasi vs aktif transaksi per tahun dan entitas. + /// + public Dictionary> VerifiedActiveYearlyData { get; set; } = new(); + + /// + /// Daftar entitas yang dapat difilter. + /// + public List Entities { get; set; } = new(); + + /// + /// Entitas yang dipilih secara default. + /// + public string SelectedEntity { get; set; } = string.Empty; } /// @@ -48,3 +63,13 @@ public class DashboardChartDataset public string Label { get; set; } = string.Empty; public List Data { get; set; } = new(); } + +/// +/// Payload untuk grafik data terverifikasi & aktif transaksi. +/// +public class VerifiedActiveChartPayload +{ + public List Labels { get; set; } = new(); + public List VerifiedData { get; set; } = new(); + public List ActiveData { get; set; } = new(); +} diff --git a/Views/Main/Dashboard/Index.cshtml b/Views/Main/Dashboard/Index.cshtml index 28f5f88..0995508 100644 --- a/Views/Main/Dashboard/Index.cshtml +++ b/Views/Main/Dashboard/Index.cshtml @@ -2,10 +2,9 @@ @using System.Text.Json @{ ViewData["Title"] = "Dashboard"; - var chartJson = JsonSerializer.Serialize(Model.YearlyData, new JsonSerializerOptions - { - PropertyNamingPolicy = JsonNamingPolicy.CamelCase - }); + var serializerOptions = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; + var chartJson = JsonSerializer.Serialize(Model.YearlyData, serializerOptions); + var verificationTrendJson = JsonSerializer.Serialize(Model.VerifiedActiveYearlyData, serializerOptions); }
@@ -269,6 +268,68 @@
+
+ +
+
+
+
+ + Total Data Terverifikasi & Aktif Transaksi + +

+ Pantau tren jumlah entitas yang sudah terverifikasi dan aktif bertransaksi setiap bulan. +

+
+
+
+ + +
+
+ + +
+
+
+
+
+
+ +
+
+
+
+
+