123 lines
5.0 KiB
C#
123 lines
5.0 KiB
C#
using BankSampahApp.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace BankSampahApp.Controllers.Main
|
|
{
|
|
[Route("Main/[controller]/[action]")]
|
|
public class DashboardController : Controller
|
|
{
|
|
public IActionResult Index()
|
|
{
|
|
var model = BuildDashboardChartModel();
|
|
return View("~/Views/Main/Dashboard/Index.cshtml", model);
|
|
}
|
|
|
|
public IActionResult Bsu()
|
|
{
|
|
return View("~/Views/Main/Dashboard/Bsu.cshtml");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Dummy chart data agar view dapat menampilkan grafik tanpa ketergantungan pada API.
|
|
/// </summary>
|
|
private static DashboardChartViewModel BuildDashboardChartModel()
|
|
{
|
|
var monthLabels = new List<string>
|
|
{
|
|
"Januari", "Februari", "Maret", "April", "Mei", "Juni",
|
|
"Juli", "Agustus", "September", "Oktober", "November", "Desember"
|
|
};
|
|
|
|
var baseDatasets = new Dictionary<string, List<int>>
|
|
{
|
|
["BSI"] = new() { 520, 540, 560, 590, 620, 650, 680, 710, 740, 770, 800, 830 },
|
|
["BSU"] = new() { 610, 630, 640, 670, 690, 720, 760, 780, 810, 830, 860, 890 },
|
|
["Offtaker"] = new() { 1050, 1080, 1100, 1140, 1180, 1220, 1260, 1300, 1340, 1380, 1420, 1480 }
|
|
};
|
|
|
|
var entities = new List<string> { "BSI", "BSU", "Offtaker" };
|
|
var verifiedActiveBase = new Dictionary<string, (List<int> Verified, List<int> Active)>
|
|
{
|
|
["BSI"] = (
|
|
new List<int> { 400, 420, 460, 500, 520, 560, 580, 600, 640, 660, 700, 720 },
|
|
new List<int> { 300, 320, 350, 370, 390, 420, 440, 460, 500, 520, 550, 580 }
|
|
),
|
|
["BSU"] = (
|
|
new List<int> { 380, 400, 420, 450, 470, 500, 520, 550, 580, 600, 640, 670 },
|
|
new List<int> { 250, 270, 300, 330, 350, 380, 400, 420, 450, 480, 500, 530 }
|
|
),
|
|
["Offtaker"] = (
|
|
new List<int> { 600, 620, 640, 660, 700, 720, 750, 780, 820, 850, 880, 910 },
|
|
new List<int> { 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<int, DashboardChartPayload>();
|
|
var verifiedActiveYearlyData = new Dictionary<int, Dictionary<string, VerifiedActiveChartPayload>>();
|
|
|
|
foreach (var year in years)
|
|
{
|
|
var offset = year - firstYear;
|
|
var payload = new DashboardChartPayload
|
|
{
|
|
Labels = new List<string>(monthLabels)
|
|
};
|
|
|
|
foreach (var dataset in baseDatasets)
|
|
{
|
|
var random = new Random(HashCode.Combine(year, dataset.Key));
|
|
payload.Datasets.Add(new DashboardChartDataset
|
|
{
|
|
Label = dataset.Key,
|
|
Data = dataset.Value
|
|
.Select(baseValue =>
|
|
{
|
|
var variation = random.Next(-100, 120) + offset * 30;
|
|
return Math.Max(0, baseValue + variation);
|
|
})
|
|
.ToList()
|
|
});
|
|
}
|
|
|
|
yearlyData[year] = payload;
|
|
|
|
var entityPayloads = new Dictionary<string, VerifiedActiveChartPayload>();
|
|
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<string>(monthLabels),
|
|
VerifiedData = verifiedData,
|
|
ActiveData = activeData
|
|
};
|
|
}
|
|
|
|
verifiedActiveYearlyData[year] = entityPayloads;
|
|
}
|
|
|
|
return new DashboardChartViewModel
|
|
{
|
|
YearlyData = yearlyData,
|
|
SelectedYear = yearlyData.Keys.Max(),
|
|
VerifiedActiveYearlyData = verifiedActiveYearlyData,
|
|
Entities = entities,
|
|
SelectedEntity = entities.FirstOrDefault() ?? string.Empty
|
|
};
|
|
}
|
|
}
|
|
}
|