77 lines
2.7 KiB
C#
77 lines
2.7 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 years = Enumerable.Range(2020, 6).ToList();
|
|
var firstYear = years.Min();
|
|
var yearlyData = new Dictionary<int, DashboardChartPayload>();
|
|
|
|
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;
|
|
}
|
|
|
|
return new DashboardChartViewModel
|
|
{
|
|
YearlyData = yearlyData,
|
|
SelectedYear = yearlyData.Keys.Max()
|
|
};
|
|
}
|
|
}
|
|
}
|