2018-05-22 10:11:50 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Core.Main;
|
|
|
|
|
using Core.Helper;
|
2024-01-23 19:05:28 +01:00
|
|
|
|
using Core.Main.DataObjects;
|
2018-05-22 10:11:50 +02:00
|
|
|
|
using Core.Main.DataObjects.PTMagicData;
|
|
|
|
|
|
2018-12-15 22:07:29 +01:00
|
|
|
|
namespace Monitor.Pages
|
|
|
|
|
{
|
|
|
|
|
public class StatusSummaryModel : _Internal.BasePageModelSecure
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
public List<string> MarketsWithSingleSettings = new List<string>();
|
|
|
|
|
public string SettingsDistribution24hChartDataJSON = "";
|
|
|
|
|
public string SettingsDistribution3dChartDataJSON = "";
|
|
|
|
|
private Dictionary<string, string> settingsChartColors = new Dictionary<string, string>();
|
2024-01-23 19:05:28 +01:00
|
|
|
|
public ProfitTrailerData PTData = null;
|
|
|
|
|
public MiscData MiscData { get; set; }
|
2018-05-22 10:11:50 +02:00
|
|
|
|
|
2018-12-15 22:07:29 +01:00
|
|
|
|
public void OnGet()
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
base.Init();
|
2018-12-15 22:07:29 +01:00
|
|
|
|
|
2018-05-22 10:11:50 +02:00
|
|
|
|
BindData();
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-15 22:07:29 +01:00
|
|
|
|
private void BindData()
|
|
|
|
|
{
|
2024-01-23 19:05:28 +01:00
|
|
|
|
PTData = this.PtDataObject;
|
|
|
|
|
MiscData = this.PTData.Misc;
|
2018-05-22 10:11:50 +02:00
|
|
|
|
BuildMarketsWithSingleSettings();
|
|
|
|
|
BuildChartColors();
|
|
|
|
|
Build24hChartData();
|
|
|
|
|
Build3dChartData();
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-15 22:07:29 +01:00
|
|
|
|
private void BuildMarketsWithSingleSettings()
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
// Get markets with active single settings
|
2018-12-15 22:07:29 +01:00
|
|
|
|
foreach (string key in Summary.MarketSummary.Keys)
|
|
|
|
|
{
|
|
|
|
|
if (Summary.MarketSummary[key].ActiveSingleSettings != null)
|
|
|
|
|
{
|
|
|
|
|
if (Summary.MarketSummary[key].ActiveSingleSettings.Count > 0)
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
MarketsWithSingleSettings.Add(key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
MarketsWithSingleSettings.Sort();
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-15 22:07:29 +01:00
|
|
|
|
private void BuildChartColors()
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
int settingIndex = 0;
|
2018-12-15 22:07:29 +01:00
|
|
|
|
foreach (GlobalSetting globalSetting in PTMagicConfiguration.AnalyzerSettings.GlobalSettings)
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
string chartColor = "";
|
2018-12-15 22:07:29 +01:00
|
|
|
|
if (settingIndex < Constants.ChartLineColors.Length)
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
chartColor = Constants.ChartLineColors[settingIndex];
|
2018-12-15 22:07:29 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
chartColor = Constants.ChartLineColors[settingIndex - 20];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
settingsChartColors.Add(globalSetting.SettingName, chartColor);
|
|
|
|
|
|
|
|
|
|
settingIndex++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-15 22:07:29 +01:00
|
|
|
|
private void Build24hChartData()
|
|
|
|
|
{
|
|
|
|
|
if (Summary.GlobalSettingSummary.Count > 0)
|
|
|
|
|
{
|
2019-02-04 01:17:38 +01:00
|
|
|
|
DateTime dateTime24hAgo = DateTime.UtcNow.AddHours(-24);
|
2018-05-22 10:11:50 +02:00
|
|
|
|
List<GlobalSettingSummary> gsSummaries24h = Summary.GlobalSettingSummary.FindAll(gss => gss.SwitchDateTime >= dateTime24hAgo);
|
|
|
|
|
IEnumerable<GlobalSettingSummary> gsNames24h = gsSummaries24h.GroupBy(gss => gss.SettingName).Select(group => group.First());
|
|
|
|
|
|
2018-12-15 22:07:29 +01:00
|
|
|
|
if (Summary.GlobalSettingSummary.FindAll(gss => gss.SwitchDateTime <= dateTime24hAgo).Count > 0)
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
GlobalSettingSummary gsBefore24h = Summary.GlobalSettingSummary.FindAll(gss => gss.SwitchDateTime <= dateTime24hAgo).OrderByDescending(gss => gss.SwitchDateTime).First();
|
2018-12-15 22:07:29 +01:00
|
|
|
|
if (gsBefore24h != null)
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
DateTime gsSwitchedOffDateTime = gsBefore24h.SwitchDateTime.AddSeconds(gsBefore24h.ActiveSeconds);
|
2018-12-15 22:07:29 +01:00
|
|
|
|
if (gsSwitchedOffDateTime > dateTime24hAgo)
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
gsBefore24h.ActiveSeconds = (int)Math.Floor(gsSwitchedOffDateTime.Subtract(dateTime24hAgo).TotalSeconds);
|
|
|
|
|
|
|
|
|
|
gsSummaries24h.Add(gsBefore24h);
|
|
|
|
|
|
2018-12-15 22:07:29 +01:00
|
|
|
|
if (gsNames24h.Select(gss => gss.SettingName.Equals(gsBefore24h.SettingName)) == null)
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
gsNames24h.Append(gsBefore24h);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-15 22:07:29 +01:00
|
|
|
|
if (gsNames24h.Count() > 0)
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
SettingsDistribution24hChartDataJSON = "[";
|
|
|
|
|
int gssIndex = 0;
|
|
|
|
|
double totalCoveredSeconds = gsSummaries24h.Sum(gs => gs.ActiveSeconds);
|
2018-12-15 22:07:29 +01:00
|
|
|
|
foreach (GlobalSettingSummary gss in gsNames24h)
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
string lineColor = "";
|
2018-12-15 22:07:29 +01:00
|
|
|
|
if (settingsChartColors.ContainsKey(gss.SettingName))
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
lineColor = settingsChartColors[gss.SettingName];
|
2018-12-15 22:07:29 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (gssIndex < Constants.ChartLineColors.Length)
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
lineColor = Constants.ChartLineColors[gssIndex];
|
2018-12-15 22:07:29 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
lineColor = Constants.ChartLineColors[gssIndex - 20];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!SettingsDistribution24hChartDataJSON.Equals("[")) SettingsDistribution24hChartDataJSON += ",";
|
|
|
|
|
|
|
|
|
|
double gsActiveSeconds = gsSummaries24h.FindAll(gs => gs.SettingName.Equals(gss.SettingName)).Sum(gs => gs.ActiveSeconds);
|
|
|
|
|
double chartValue = gsActiveSeconds / totalCoveredSeconds * 100;
|
|
|
|
|
|
|
|
|
|
SettingsDistribution24hChartDataJSON += "{";
|
|
|
|
|
SettingsDistribution24hChartDataJSON += "label: '" + SystemHelper.SplitCamelCase(gss.SettingName) + "',";
|
|
|
|
|
SettingsDistribution24hChartDataJSON += "color: '" + lineColor + "',";
|
|
|
|
|
SettingsDistribution24hChartDataJSON += "value: " + chartValue.ToString("0.00", new System.Globalization.CultureInfo("en-US")) + "";
|
|
|
|
|
SettingsDistribution24hChartDataJSON += "}";
|
|
|
|
|
|
|
|
|
|
gssIndex++;
|
|
|
|
|
}
|
|
|
|
|
SettingsDistribution24hChartDataJSON += "]";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-15 22:07:29 +01:00
|
|
|
|
private void Build3dChartData()
|
|
|
|
|
{
|
|
|
|
|
if (Summary.GlobalSettingSummary.Count > 0)
|
|
|
|
|
{
|
2019-02-04 01:17:38 +01:00
|
|
|
|
DateTime dateTime3dAgo = DateTime.UtcNow.AddHours(-72);
|
2018-05-22 10:11:50 +02:00
|
|
|
|
List<GlobalSettingSummary> gsSummaries3d = Summary.GlobalSettingSummary.FindAll(gss => gss.SwitchDateTime >= dateTime3dAgo);
|
|
|
|
|
IEnumerable<GlobalSettingSummary> gsNames3d = gsSummaries3d.GroupBy(gss => gss.SettingName).Select(group => group.First());
|
|
|
|
|
|
2018-12-15 22:07:29 +01:00
|
|
|
|
if (Summary.GlobalSettingSummary.FindAll(gss => gss.SwitchDateTime <= dateTime3dAgo).Count > 0)
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
GlobalSettingSummary gsBefore3d = Summary.GlobalSettingSummary.FindAll(gss => gss.SwitchDateTime <= dateTime3dAgo).OrderByDescending(gss => gss.SwitchDateTime).First();
|
2018-12-15 22:07:29 +01:00
|
|
|
|
if (gsBefore3d != null)
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
DateTime gsSwitchedOffDateTime = gsBefore3d.SwitchDateTime.AddSeconds(gsBefore3d.ActiveSeconds);
|
2018-12-15 22:07:29 +01:00
|
|
|
|
if (gsSwitchedOffDateTime > dateTime3dAgo)
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
gsBefore3d.ActiveSeconds = (int)Math.Floor(gsSwitchedOffDateTime.Subtract(dateTime3dAgo).TotalSeconds);
|
|
|
|
|
|
|
|
|
|
gsSummaries3d.Add(gsBefore3d);
|
|
|
|
|
|
2018-12-15 22:07:29 +01:00
|
|
|
|
if (gsNames3d.Select(gss => gss.SettingName.Equals(gsBefore3d.SettingName)) == null)
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
gsNames3d.Append(gsBefore3d);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-15 22:07:29 +01:00
|
|
|
|
if (gsNames3d.Count() > 0)
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
SettingsDistribution3dChartDataJSON = "[";
|
|
|
|
|
int gssIndex = 0;
|
|
|
|
|
double totalCoveredSeconds = gsSummaries3d.Sum(gs => gs.ActiveSeconds);
|
2018-12-15 22:07:29 +01:00
|
|
|
|
foreach (GlobalSettingSummary gss in gsNames3d)
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
string lineColor = "";
|
2018-12-15 22:07:29 +01:00
|
|
|
|
if (settingsChartColors.ContainsKey(gss.SettingName))
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
lineColor = settingsChartColors[gss.SettingName];
|
2018-12-15 22:07:29 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (gssIndex < Constants.ChartLineColors.Length)
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
lineColor = Constants.ChartLineColors[gssIndex];
|
2018-12-15 22:07:29 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-05-22 10:11:50 +02:00
|
|
|
|
lineColor = Constants.ChartLineColors[gssIndex - 20];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!SettingsDistribution3dChartDataJSON.Equals("[")) SettingsDistribution3dChartDataJSON += ",";
|
|
|
|
|
|
|
|
|
|
double gsActiveSeconds = gsSummaries3d.FindAll(gs => gs.SettingName.Equals(gss.SettingName)).Sum(gs => gs.ActiveSeconds);
|
|
|
|
|
double chartValue = gsActiveSeconds / totalCoveredSeconds * 100;
|
|
|
|
|
|
|
|
|
|
SettingsDistribution3dChartDataJSON += "{";
|
|
|
|
|
SettingsDistribution3dChartDataJSON += "label: '" + SystemHelper.SplitCamelCase(gss.SettingName) + "',";
|
|
|
|
|
SettingsDistribution3dChartDataJSON += "color: '" + lineColor + "',";
|
|
|
|
|
SettingsDistribution3dChartDataJSON += "value: " + chartValue.ToString("0.00", new System.Globalization.CultureInfo("en-US")) + "";
|
|
|
|
|
SettingsDistribution3dChartDataJSON += "}";
|
|
|
|
|
|
|
|
|
|
gssIndex++;
|
|
|
|
|
}
|
|
|
|
|
SettingsDistribution3dChartDataJSON += "]";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|