|
|
@@ -75,6 +75,28 @@ namespace economy.Controllers.Price.Global
|
|
|
return exchangeValue;
|
|
|
}
|
|
|
|
|
|
+ // 국제 시세 응답을 차트 데이터로 변환 (최신 60개, 오름차순)
|
|
|
+ private static ChartData BuildChart(string name, IEnumerable<(string Date, string Value)> rows)
|
|
|
+ {
|
|
|
+ var points = rows
|
|
|
+ .Select(r => (r.Date, Parsed: decimal.TryParse(r.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out decimal value) ? value : (decimal?)null))
|
|
|
+ .Where(p => p.Parsed.HasValue)
|
|
|
+ .Take(60)
|
|
|
+ .Reverse()
|
|
|
+ .ToList();
|
|
|
+
|
|
|
+ if (points.Count < 2)
|
|
|
+ {
|
|
|
+ return new ChartData();
|
|
|
+ }
|
|
|
+
|
|
|
+ return new ChartData
|
|
|
+ {
|
|
|
+ Labels = points.Select(p => p.Date).ToList(),
|
|
|
+ Series = [new ChartSeries { Name = name, Values = points.Select(p => p.Parsed).ToList() }]
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
[HttpGet("Price/Global/NaturalGas")]
|
|
|
public async Task<IActionResult> NaturalGas(NaturalGas.Request request)
|
|
|
{
|
|
|
@@ -93,10 +115,13 @@ namespace economy.Controllers.Price.Global
|
|
|
GlobalModel globalModel = new GlobalModel(_alphaAPI, _cache);
|
|
|
NaturalGas.Response itemList = await globalModel.GetNaturalGasPriceInfo(request);
|
|
|
|
|
|
+ ChartData? chart = null;
|
|
|
int total = 0;
|
|
|
|
|
|
if (itemList.Data != null && itemList.Data.Any())
|
|
|
{
|
|
|
+ chart = BuildChart("천연가스", itemList.Data.Select(d => (d.Date, d.Value)));
|
|
|
+
|
|
|
total = itemList.Data.Count;
|
|
|
int listNum = Common.CalcListNumber(total, request.PageNo, request.NumOfRows);
|
|
|
|
|
|
@@ -126,6 +151,7 @@ namespace economy.Controllers.Price.Global
|
|
|
viewModel.SelectedListPerPage = request.NumOfRows;
|
|
|
viewModel.Request = request;
|
|
|
viewModel.Response = itemList;
|
|
|
+ viewModel.Chart = chart;
|
|
|
|
|
|
var queryString = new
|
|
|
{
|
|
|
@@ -163,10 +189,13 @@ namespace economy.Controllers.Price.Global
|
|
|
GlobalModel globalModel = new GlobalModel(_alphaAPI, _cache);
|
|
|
Commodity.Response itemList = await globalModel.GetCommodityPriceInfo(meta.Function, request.Interval);
|
|
|
|
|
|
+ ChartData? chart = null;
|
|
|
int total = 0;
|
|
|
|
|
|
if (itemList.Data != null && itemList.Data.Any())
|
|
|
{
|
|
|
+ chart = BuildChart(meta.Title, itemList.Data.Select(d => (d.Date, d.Value)));
|
|
|
+
|
|
|
total = itemList.Data.Count;
|
|
|
int listNum = Common.CalcListNumber(total, request.PageNo, request.NumOfRows);
|
|
|
|
|
|
@@ -201,6 +230,7 @@ namespace economy.Controllers.Price.Global
|
|
|
viewModel.SelectedListPerPage = request.NumOfRows;
|
|
|
viewModel.Request = request;
|
|
|
viewModel.Response = itemList;
|
|
|
+ viewModel.Chart = chart;
|
|
|
|
|
|
var queryString = new
|
|
|
{
|