diff --git a/MP.MONO.UI/Components/ToolsPlot.razor.cs b/MP.MONO.UI/Components/ToolsPlot.razor.cs index d89593b..ab8aac0 100644 --- a/MP.MONO.UI/Components/ToolsPlot.razor.cs +++ b/MP.MONO.UI/Components/ToolsPlot.razor.cs @@ -1,41 +1,55 @@ using Microsoft.AspNetCore.Components; using MP.MONO.Core.DTO; using MP.MONO.Data; +using MP.MONO.Data.DTO; +using MP.MONO.UI.Data; using Newtonsoft.Json; +using static MP.MONO.Core.Enums; namespace MP.MONO.UI.Components { public partial class ToolsPlot { + #region Public Properties + + [Parameter] + public int MachineId { get; set; } = 1; + + public string ToolId + { + get => _selTool.Replace(" ", "_"); + } + + [Parameter] + public string SelectedTool + { + get => _selTool; + set => _selTool = value; + } + + [Parameter] + public DataLogFilter SelFilter + { + get => _SelFilter; + set { _SelFilter = value; } + } + + #endregion Public Properties + #region Protected Fields protected DateTime lastRec = DateTime.Now.AddMinutes(-1); - + protected List LevelVal = new List(); protected Dictionary listMaxVal = new Dictionary(); - protected Dictionary listMinVal = new Dictionary(); - protected Dictionary> plotData = new Dictionary>(); - #endregion Protected Fields #region Protected Properties + protected DataLogFilter _SelFilter { get; set; } = new DataLogFilter(); protected string _selTool { get; set; } = ""; - protected List LevelVal - { - get - { - List answ = new List(); - if (plotData.ContainsKey(SelectedTool)) - { - answ = plotData[SelectedTool]; - } - return answ; - } - } - protected string? MaxVal { get @@ -66,148 +80,77 @@ namespace MP.MONO.UI.Components #endregion Protected Properties - #region Public Properties - - [Parameter] - public int maxRecord { get; set; } = 120; - - public string ToolId - { - get => _selTool.Replace(" ", "_"); - } - - [Parameter] - public double sampleSecMin { get; set; } = 1; - - [Parameter] - public string SelectedTool - { - get - { - return _selTool; - } - set - { - // controllo se è variato - if (_selTool != value) - { - // salvo - _selTool = value; - // cerco se ho in dictionary... - if (!plotData.ContainsKey(value)) - { - DateTime adesso = DateTime.Now; - // creo un oggetto della lunghezza desiderata... - var emptyData = new List(); - 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 ToolsPipe_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>(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()); - // creo un oggetto della lunghezza desiderata... - var emptyData = new List(); - 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(); - }); - } - - #endregion Private Methods - #region Protected Methods protected List getFillColors(string alpha) { List answ = new List(); - answ.Add($"rgba(108, 164, 254, {alpha})"); + answ.Add($"rgba(108, 214, 164, {alpha})"); return answ; } protected List getLineColors(string alpha) { List answ = new List(); - answ.Add($"rgba(54, 82, 254, {alpha})"); + answ.Add($"rgba(54, 204, 82, {alpha})"); return answ; } protected List getPointColors(string alpha) { List answ = new List(); - answ.Add($"rgba(108, 118, 158, {alpha})"); + answ.Add($"rgba(108, 158, 118, {alpha})"); return answ; } protected override async Task OnInitializedAsync() { - //await ReloadData(); + await ReloadData(); await Task.Delay(1); - MMDataService.toolsPipe.EA_NewMessage += ToolsPipe_EA_NewMessage; + } + + protected override async Task OnParametersSetAsync() + { + isLoading = true; + await ReloadData(); + await Task.Delay(1); + } + + protected async Task ReloadData() + { + isLoading = true; + ListRecords = null; + await Task.Delay(1); + ListRecords = await MMDataService.DataLogDtoGetFilt(MachineId, DataLogType.Tools, SelectedTool, StartDate, EndDate); + await Task.Delay(1); + // converto in plotdata + LevelVal = ListRecords.Select(l => new chartJsData.chartJsTSerie() { x = l.DtRif, y = l.ValNum }).ToList(); + await Task.Delay(1); + isLoading = false; } #endregion Protected Methods + + #region Private Fields + + private List? ListRecords = null; + + #endregion Private Fields + + #region Private Properties + + private DateTime EndDate + { + get => _SelFilter.DtEnd; + } + + private bool isLoading { get; set; } = false; + + private DateTime StartDate + { + get => _SelFilter.DtStart; + } + + #endregion Private Properties } } \ No newline at end of file diff --git a/MP.MONO.UI/Components/ToolsPlotRT.razor b/MP.MONO.UI/Components/ToolsPlotRT.razor new file mode 100644 index 0000000..3fd9e64 --- /dev/null +++ b/MP.MONO.UI/Components/ToolsPlotRT.razor @@ -0,0 +1,29 @@ +@using MP.MONO.UI.Components +@using MP.MONO.Core.DTO +@using MP.MONO.UI.Data +@using Microsoft.Extensions.Configuration; + +@inject IConfiguration Configuration; + +@inject CurrentDataService MMDataService + +@if (!string.IsNullOrEmpty(@SelectedTool)) +{ +
+
+ @SelectedTool +
+
+
+
+ @if (LevelVal == null || LevelVal.Count == 0) + { + + } + else + { + + } +
+
+} diff --git a/MP.MONO.UI/Components/ToolsPlotRT.razor.cs b/MP.MONO.UI/Components/ToolsPlotRT.razor.cs new file mode 100644 index 0000000..2fee97a --- /dev/null +++ b/MP.MONO.UI/Components/ToolsPlotRT.razor.cs @@ -0,0 +1,213 @@ +using Microsoft.AspNetCore.Components; +using MP.MONO.Core.DTO; +using MP.MONO.Data; +using Newtonsoft.Json; + +namespace MP.MONO.UI.Components +{ + public partial class ToolsPlotRT + { + #region Protected Fields + + protected DateTime lastRec = DateTime.Now.AddMinutes(-1); + + protected Dictionary listMaxVal = new Dictionary(); + + protected Dictionary listMinVal = new Dictionary(); + + protected Dictionary> plotData = new Dictionary>(); + + #endregion Protected Fields + + #region Protected Properties + + protected string _selTool { get; set; } = ""; + + protected List LevelVal + { + get + { + List answ = new List(); + if (plotData.ContainsKey(SelectedTool)) + { + answ = plotData[SelectedTool]; + } + return answ; + } + } + + protected string? MaxVal + { + get + { + string answ = "0"; + if (listMaxVal != null && listMaxVal.Count > 0) + { + answ = listMaxVal[SelectedTool] ?? "0"; + } + + return answ; + } + } + + protected string? MinVal + { + get + { + string answ = "0"; + if (listMinVal != null && listMinVal.Count > 0) + { + answ = listMinVal[SelectedTool] ?? "0"; + } + + return answ; + } + } + + #endregion Protected Properties + + #region Public Properties + + [Parameter] + public int maxRecord { get; set; } = 120; + + public string ToolId + { + get => _selTool.Replace(" ", "_"); + } + + [Parameter] + public double sampleSecMin { get; set; } = 1; + + [Parameter] + public string SelectedTool + { + get + { + return _selTool; + } + set + { + // controllo se è variato + if (_selTool != value) + { + // salvo + _selTool = value; + // cerco se ho in dictionary... + if (!plotData.ContainsKey(value)) + { + DateTime adesso = DateTime.Now; + // creo un oggetto della lunghezza desiderata... + var emptyData = new List(); + 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 ToolsPipe_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>(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()); + // creo un oggetto della lunghezza desiderata... + var emptyData = new List(); + 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(); + }); + } + + #endregion Private Methods + + #region Protected Methods + + protected List getFillColors(string alpha) + { + List answ = new List(); + answ.Add($"rgba(108, 164, 254, {alpha})"); + return answ; + } + + protected List getLineColors(string alpha) + { + List answ = new List(); + answ.Add($"rgba(54, 82, 254, {alpha})"); + return answ; + } + + protected List getPointColors(string alpha) + { + List answ = new List(); + answ.Add($"rgba(108, 118, 158, {alpha})"); + return answ; + } + + protected override async Task OnInitializedAsync() + { + //await ReloadData(); + await Task.Delay(1); + MMDataService.toolsPipe.EA_NewMessage += ToolsPipe_EA_NewMessage; + } + + #endregion Protected Methods + } +} \ No newline at end of file diff --git a/MP.MONO.UI/Data/DataFilter.cs b/MP.MONO.UI/Data/DataFilter.cs index d8039d2..c1e3a5e 100644 --- a/MP.MONO.UI/Data/DataFilter.cs +++ b/MP.MONO.UI/Data/DataFilter.cs @@ -3,8 +3,8 @@ public class DataLogFilter { - public DateTime DtStart { get; set; } = DateTime.Today.AddDays(-1); - public DateTime DtEnd { get; set; } = DateTime.Today.AddDays(1); + public DateTime DtStart { get; set; } = DateTime.Today.AddDays(-3); + public DateTime DtEnd { get; set; } = DateTime.Today.AddDays(3); public override bool Equals(object obj) { diff --git a/MP.MONO.UI/MP.MONO.UI.csproj b/MP.MONO.UI/MP.MONO.UI.csproj index b5c970d..d5f0ff0 100644 --- a/MP.MONO.UI/MP.MONO.UI.csproj +++ b/MP.MONO.UI/MP.MONO.UI.csproj @@ -5,7 +5,7 @@ enable enable AnyCPU;x86;x64 - 1.2.2210.314 + 1.2.2210.315 diff --git a/MP.MONO.UI/Pages/Tools.razor b/MP.MONO.UI/Pages/Tools.razor index b86a299..14955d9 100644 --- a/MP.MONO.UI/Pages/Tools.razor +++ b/MP.MONO.UI/Pages/Tools.razor @@ -2,23 +2,51 @@
-
-

Tools

-
-
-
- +

Tools

+
-
- @foreach (var item in selTools) - { -
- +
+
+
+
+
+
+ + +
- } +
+
+
+
+
+
+ +
+
+ @if (isRT) + { + + @foreach (var item in selTools) + { +
+ +
+ } + } + else + { + @foreach (var item in selTools) + { +
+ +
+ } + } +
-
\ No newline at end of file +
diff --git a/MP.MONO.UI/Resources/ChangeLog.html b/MP.MONO.UI/Resources/ChangeLog.html index 961c3ac..b0482f7 100644 --- a/MP.MONO.UI/Resources/ChangeLog.html +++ b/MP.MONO.UI/Resources/ChangeLog.html @@ -1,6 +1,6 @@ MAPO-MONO -

Version: 1.2.2210.314

+

Version: 1.2.2210.315


Release Note:
  • diff --git a/MP.MONO.UI/Resources/VersNum.txt b/MP.MONO.UI/Resources/VersNum.txt index a53de99..06fee29 100644 --- a/MP.MONO.UI/Resources/VersNum.txt +++ b/MP.MONO.UI/Resources/VersNum.txt @@ -1 +1 @@ -1.2.2210.314 +1.2.2210.315 diff --git a/MP.MONO.UI/Resources/manifest.xml b/MP.MONO.UI/Resources/manifest.xml index 130018f..0aa4a57 100644 --- a/MP.MONO.UI/Resources/manifest.xml +++ b/MP.MONO.UI/Resources/manifest.xml @@ -1,6 +1,6 @@ - 1.2.2210.314 + 1.2.2210.315 http://nexus.steamware.net/repository/SWS/MP.MONO.UI/stable/LAST/MP.Mon.zip http://nexus.steamware.net/repository/SWS/MP.MONO.UI/stable/LAST/ChangeLog.html false