216 lines
7.2 KiB
C#
216 lines
7.2 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using MP.MONO.Core.DTO;
|
|
using MP.MONO.Data;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace MP.MONO.UI.Components
|
|
{
|
|
public partial class ParamPlot
|
|
{
|
|
#region Private Fields
|
|
|
|
private int maxRecord = 120;
|
|
private bool showParam = false;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Protected Fields
|
|
|
|
protected DateTime lastRec = DateTime.Now.AddMinutes(-1);
|
|
|
|
protected Dictionary<string, string> listMaxVal = new Dictionary<string, string>();
|
|
protected Dictionary<string, string> listMinVal = new Dictionary<string, string>();
|
|
protected Dictionary<string, List<chartJsData.chartJsTSerie>> plotData = new Dictionary<string, List<chartJsData.chartJsTSerie>>();
|
|
|
|
protected double sampleSecMin = 1;
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
protected string _selParam { get; set; } = "";
|
|
|
|
protected List<chartJsData.chartJsTSerie> LevelVal
|
|
{
|
|
get
|
|
{
|
|
List<chartJsData.chartJsTSerie> answ = new List<chartJsData.chartJsTSerie>();
|
|
if (plotData.ContainsKey(SelectedParam))
|
|
{
|
|
answ = plotData[SelectedParam];
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
protected string? MaxVal
|
|
{
|
|
get
|
|
{
|
|
string answ = "0";
|
|
if (listMaxVal != null && listMaxVal.Count > 0)
|
|
{
|
|
answ = listMaxVal[SelectedParam] ?? "0";
|
|
}
|
|
|
|
return answ;
|
|
|
|
}
|
|
}
|
|
|
|
protected string? MinVal
|
|
{
|
|
get
|
|
{
|
|
string answ = "0";
|
|
if (listMinVal != null && listMinVal.Count > 0)
|
|
{
|
|
answ = listMinVal[SelectedParam] ?? "0";
|
|
}
|
|
|
|
return answ;
|
|
|
|
}
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public string SelectedParam
|
|
{
|
|
get
|
|
{
|
|
return _selParam;
|
|
}
|
|
set
|
|
{
|
|
// controllo se è variato
|
|
if (_selParam != value)
|
|
{
|
|
// salvo
|
|
_selParam = value;
|
|
// cerco se ho in dictionary...
|
|
if (!plotData.ContainsKey(value))
|
|
{
|
|
DateTime adesso = DateTime.Now;
|
|
// creo un oggetto della lunghezza desiderata...
|
|
var emptyData = new List<chartJsData.chartJsTSerie>();
|
|
for (int i = -maxRecord; i < 0; i++)
|
|
{
|
|
emptyData.Add(new chartJsData.chartJsTSerie() { x = adesso.AddSeconds(i), y = 0 });
|
|
}
|
|
plotData.Add(value, emptyData);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Private Methods
|
|
|
|
//private int inputValue = 123;
|
|
private void ParametersPipe_EA_NewMessage(object? sender, EventArgs e)
|
|
{
|
|
DateTime adesso = DateTime.Now;
|
|
if (lastRec.AddSeconds(sampleSecMin) < adesso)
|
|
{
|
|
PubSubEventArgs currArgs = (PubSubEventArgs)e;
|
|
if (!string.IsNullOrEmpty(currArgs.newMessage))
|
|
{
|
|
try
|
|
{
|
|
var ListRecords = JsonConvert.DeserializeObject<List<DisplayDataDTO>>(currArgs.newMessage);
|
|
// prendo SOLO il dato della TS richiesta
|
|
if (ListRecords != null)
|
|
{
|
|
// accodo in blocco tutti i valori...
|
|
foreach (var item in ListRecords)
|
|
{
|
|
// cerco se ci sono min/max del valore indicato...
|
|
if (!listMinVal.ContainsKey(item.Title))
|
|
{
|
|
listMinVal.Add(item.Title, $"{item.MinVal:N0}");
|
|
}
|
|
if (!listMaxVal.ContainsKey(item.Title))
|
|
{
|
|
listMaxVal.Add(item.Title, $"{item.MaxVal:N0}");
|
|
}
|
|
// verifico dictionary se mancasse...
|
|
if (!plotData.ContainsKey(item.Title))
|
|
{
|
|
//plotData.Add(item.Title, new List<chartJsData.chartJsTSerie>());
|
|
// creo un oggetto della lunghezza desiderata...
|
|
var emptyData = new List<chartJsData.chartJsTSerie>();
|
|
for (int i = -maxRecord; i < 0; i++)
|
|
{
|
|
emptyData.Add(new chartJsData.chartJsTSerie() { x = adesso.AddSeconds(i), y = 0 });
|
|
}
|
|
plotData.Add(item.Title, emptyData);
|
|
}
|
|
// ora accodo il valore
|
|
if (plotData.ContainsKey(item.Title))
|
|
{
|
|
plotData[item.Title].Add(new chartJsData.chartJsTSerie() { x = adesso, y = item.ValueNum });
|
|
// verifico limite visualizzazione
|
|
if (plotData[item.Title].Count > maxRecord)
|
|
{
|
|
plotData[item.Title].RemoveRange(0, plotData[item.Title].Count - maxRecord);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
lastRec = adesso;
|
|
}
|
|
InvokeAsync(() =>
|
|
{
|
|
StateHasChanged();
|
|
});
|
|
}
|
|
|
|
private void toggleParam()
|
|
{
|
|
showParam = !showParam;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
|
|
#region Protected Methods
|
|
|
|
protected List<string> getFillColors(string alpha)
|
|
{
|
|
List<string> answ = new List<string>();
|
|
answ.Add($"rgba(108, 164, 254, {alpha})");
|
|
return answ;
|
|
}
|
|
|
|
protected List<string> getLineColors(string alpha)
|
|
{
|
|
List<string> answ = new List<string>();
|
|
answ.Add($"rgba(54, 82, 254, {alpha})");
|
|
return answ;
|
|
}
|
|
|
|
protected List<string> getPointColors(string alpha)
|
|
{
|
|
List<string> answ = new List<string>();
|
|
answ.Add($"rgba(108, 118, 158, {alpha})");
|
|
return answ;
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
//await ReloadData();
|
|
await Task.Delay(1);
|
|
MMDataService.parametersPipe.EA_NewMessage += ParametersPipe_EA_NewMessage;
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
}
|
|
} |