From b8bc8a4854ad30d097df81b0a8786cab8f88dfd9 Mon Sep 17 00:00:00 2001 From: "zaccaria.majid" Date: Fri, 23 Sep 2022 10:27:19 +0200 Subject: [PATCH] Demo grafico allarmi --- MP.MONO.UI/Components/Chart/Line.razor | 2 - MP.MONO.UI/Components/Chart/Line.razor.cs | 174 ----------------- MP.MONO.UI/Components/ChartAlarms.razor | 31 +++ MP.MONO.UI/Components/ChartAlarms.razor.cs | 184 ++++++++++++++++++ MP.MONO.UI/Components/ChartController.razor | 2 +- .../{Chart => ChartJS}/BarPlot.razor | 1 - MP.MONO.UI/MP - Backup (1).MONO.UI.csproj | 72 +++++++ MP.MONO.UI/MP - Backup.MONO.UI.csproj | 66 +++++++ MP.MONO.UI/MP.MONO.UI.csproj | 8 +- MP.MONO.UI/Pages/Alarms.razor | 6 - MP.MONO.UI/Pages/AlarmsAnalysis.razor | 33 ++-- MP.MONO.UI/Pages/AlarmsAnalysis.razor.cs | 122 ++++++++++-- MP.MONO.UI/Resources/ChangeLog.html | 2 +- MP.MONO.UI/Resources/VersNum.txt | 2 +- MP.MONO.UI/Resources/manifest.xml | 2 +- 15 files changed, 480 insertions(+), 227 deletions(-) delete mode 100644 MP.MONO.UI/Components/Chart/Line.razor delete mode 100644 MP.MONO.UI/Components/Chart/Line.razor.cs create mode 100644 MP.MONO.UI/Components/ChartAlarms.razor create mode 100644 MP.MONO.UI/Components/ChartAlarms.razor.cs rename MP.MONO.UI/Components/{Chart => ChartJS}/BarPlot.razor (99%) create mode 100644 MP.MONO.UI/MP - Backup (1).MONO.UI.csproj create mode 100644 MP.MONO.UI/MP - Backup.MONO.UI.csproj diff --git a/MP.MONO.UI/Components/Chart/Line.razor b/MP.MONO.UI/Components/Chart/Line.razor deleted file mode 100644 index 7da6d7e..0000000 --- a/MP.MONO.UI/Components/Chart/Line.razor +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/MP.MONO.UI/Components/Chart/Line.razor.cs b/MP.MONO.UI/Components/Chart/Line.razor.cs deleted file mode 100644 index 100baa8..0000000 --- a/MP.MONO.UI/Components/Chart/Line.razor.cs +++ /dev/null @@ -1,174 +0,0 @@ -using Microsoft.AspNetCore.Components; -using Microsoft.JSInterop; -using MP.MONO.Data; - -namespace MP.MONO.UI.Components.Chart -{ - public partial class Line - { - #region Private Properties - - private List _DataTS { get; set; } = null!; - - [Inject] - private IJSRuntime JSRuntime { get; set; } = null!; - - #endregion Private Properties - - #region Public Properties - - [Parameter] - public double AspRatio { get; set; } = 0; - - [Parameter] - public List backColor { get; set; } = new List(); - - [Parameter] - public List DataTS - { - get - { - return _DataTS; - } - - set - { - _DataTS = value; - //var pUpd = Task.Run(async () => await renderChart()); - //pUpd.Wait(); - } - } - - protected string Id { get; set; } = "CurrId"; - - [Parameter] - public string ChartId - { - get - { - return Id; - } - set - { - Id = value; - } - } - - [Parameter] - public List Labels { get; set; } = new List(); - - [Parameter] - public List lineColor { get; set; } = new List(); - - [Parameter] - public int lTens { get; set; } = 0; - - [Parameter] - public string MaxValue { get; set; } = "0"; - - [Parameter] - public string MinValue { get; set; } = "0"; - - [Parameter] - public List pointColor { get; set; } = new List(); - - [Parameter] - public string Title { get; set; } = "Demo Line"; - - #endregion Public Properties - - #region Protected Methods - - /// - /// Inizializzazione rendering componente - /// - /// partendo da qui: - /// https://www.williamleme.com/posts/2020/003-chartjs-blazor/ - /// https://www.puresourcecode.com/dotnet/blazor/using-chart-js-with-blazor/ - /// https://www.tutorialsteacher.com/csharp/csharp-anonymous-type - /// - /// - /// - protected override async Task OnAfterRenderAsync(bool firstRender) - { - await renderChart(); - } - - /// - /// Inizializzazione rendering componente - /// - /// partendo da qui: - /// https://www.williamleme.com/posts/2020/003-chartjs-blazor/ - /// https://www.puresourcecode.com/dotnet/blazor/using-chart-js-with-blazor/ - /// https://www.tutorialsteacher.com/csharp/csharp-anonymous-type - /// - /// - /// - protected async Task renderChart() - { - // creazione di un oggetto anonymous type con tutte le opzioni da passare a chart.js - var config = new - { - type = "line", - options = new - { - responsive = true, - scales = new - { - yAxes = new - { - display = true, - position = "right", - ticks = new - { - maxTicksLimit = 10 - } - - , - suggestedMin = MinValue != MaxValue ? MinValue : "auto", - suggestedMax = MinValue != MaxValue ? MaxValue : "auto" - } - - , - xAxes = new - { - type = "time", - distribution = "linear", - } - } - - , - plugins = new - { - legend = new - { - display = false - } - - , - } - - , - Animation = false, - AspectRatio = AspRatio == 0 ? "auto" : $"{AspRatio}" - } - - , - data = new - { - labels = Labels, - datasets = new[]{new - { - data = DataTS, pointBorderColor = backColor, borderColor = lineColor, backgroundColor = backColor, fill = true, PointRadius = 2, BorderWidth = 1, lineTension = lTens, stepped = false, label = Title - } - } - } - } - - ; - await JSRuntime.InvokeVoidAsync("setup", Id, config); - } - - #endregion Protected Methods - } -} \ No newline at end of file diff --git a/MP.MONO.UI/Components/ChartAlarms.razor b/MP.MONO.UI/Components/ChartAlarms.razor new file mode 100644 index 0000000..dcffcd7 --- /dev/null +++ b/MP.MONO.UI/Components/ChartAlarms.razor @@ -0,0 +1,31 @@ +@using MP.MONO.UI.Components.ChartJS + +
+ @if (RawData == null || RawData.Count == 0) + { +
+
No Chart Data
+
+ } + else + { +
+
    + @foreach (var item in @ParetoData) + { +
  • + @item.label + @item.value.ToString("N2")% +
  • + } +
+
+
+
+
+ +
+
+
+ } +
diff --git a/MP.MONO.UI/Components/ChartAlarms.razor.cs b/MP.MONO.UI/Components/ChartAlarms.razor.cs new file mode 100644 index 0000000..7caa80c --- /dev/null +++ b/MP.MONO.UI/Components/ChartAlarms.razor.cs @@ -0,0 +1,184 @@ +using Microsoft.AspNetCore.Components; +using MP.MONO.Data; +using MP.MONO.UI.Data; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace MP.MONO.UI.Components +{ + public partial class ChartAlarms + { + #region Private Properties + + private List DatiParetoOee + { + get => ParetoData.Select(x => x.value).ToList(); + } + + private List DatiTrs + { + get => TSData; + } + + private List LabelParetoOee + { + get => ParetoData.Select(x => x.label).ToList(); + } + + private List LabelTrs + { + get => TSData.Select(r => $"{r.x:yyyy-MM-dd}").ToList(); + } + + #endregion Private Properties + + #region Protected Properties + + //protected SelectData _currFilter { get; set; } = new SelectData(); + + protected List _rawData { get; set; } = new List(); + + /// + /// Genera colori sfondo 33% rosso / arancione / giallo + /// + /// + /// + protected List bgColors + { + get => semaphColors(ParetoData.Count, "0.3"); + } + +#if false + /// + /// Genera colori sfondo 33% rosso / arancione / giallo + /// + /// + /// + protected List lineColor + { + get => solidColors("1"); + } +#endif + + /// + /// Genera colori sfondo 33% rosso / arancione / giallo + /// + /// + /// + protected List lineColors + { + get => semaphColors(ParetoData.Count, "1"); + } + + //[Inject] + //protected MessageService MessageService { get; set; } + + protected List ParetoData { get; set; } = new List(); + + //[Inject] + //protected MpStatsService StatService { get; set; } + + protected List TSData { get; set; } = new List(); + + #endregion Protected Properties + + #region Public Properties + + [Parameter] + public List RawData + { + get => _rawData; + set + { + // salvo valori + _rawData = value; + if (value != null) + { + // ricalcolo charting data + recalcData(); + } + } + } + + #endregion Public Properties + + #region Private Methods + + private Dictionary calcTSData(DateTime inizio, List yData) + { + Dictionary answ = new Dictionary(); + // usando i dati ricevuti aggiunge variabile x = tempo crescente + int idx = 0; + foreach (var item in yData) + { + answ.Add(inizio.AddHours(idx), item); + idx++; + } + // restituisco! + return answ; + } + + private void recalcData() + { + if (RawData != null) + { + ParetoData = RawData + .GroupBy(x => x.MachineId) + .Select(y => new ChartKV() { label = y.First().MachineId.ToString(), value = Math.Round(y.Average(c => c.EventCount) * 100, 2) }) + .OrderByDescending(x => x.value) + .ToList(); + + TSData = RawData + .GroupBy(x => x.MachineId) + .Select(r => new chartJsData.chartJsTSerie() { x = DateTime.Now, y = Math.Round(r.Average(c => c.EventCount) * 100, 2) }) + .OrderBy(o => o.x) + .ToList(); + } + } + + #endregion Private Methods + + #region Protected Methods + + /// + /// Genera colori sfondo 33% rosso / arancione / giallo + /// + /// + /// + protected List semaphColors(int numRecords, string alpha) + { + List answ = new List(); + // verde... + for (int i = 0; i < numRecords / 3; i++) + { + answ.Add($"rgba(54, 235, 82, {alpha})"); + } + // arancione + for (int i = 0; i < numRecords / 3; i++) + { + answ.Add($"rgba(255, 206, 86, {alpha})"); + } + while (answ.Count < numRecords) + { + answ.Add($"rgba(255, 99, 132, {alpha}"); + } + + return answ; + } + + /// + /// Genera colori sfondo 33% rosso / arancione / giallo + /// + /// + /// + protected List solidColors(string alpha) + { + List answ = new List(); + answ.Add($"rgba(54, 162, 235, {alpha})"); + return answ; + } + + #endregion Protected Methods + } +} diff --git a/MP.MONO.UI/Components/ChartController.razor b/MP.MONO.UI/Components/ChartController.razor index a8e34d4..9ff139b 100644 --- a/MP.MONO.UI/Components/ChartController.razor +++ b/MP.MONO.UI/Components/ChartController.razor @@ -26,7 +26,7 @@
- +
diff --git a/MP.MONO.UI/Components/Chart/BarPlot.razor b/MP.MONO.UI/Components/ChartJS/BarPlot.razor similarity index 99% rename from MP.MONO.UI/Components/Chart/BarPlot.razor rename to MP.MONO.UI/Components/ChartJS/BarPlot.razor index 9596bab..62aa0fc 100644 --- a/MP.MONO.UI/Components/Chart/BarPlot.razor +++ b/MP.MONO.UI/Components/ChartJS/BarPlot.razor @@ -131,4 +131,3 @@ } } } - diff --git a/MP.MONO.UI/MP - Backup (1).MONO.UI.csproj b/MP.MONO.UI/MP - Backup (1).MONO.UI.csproj new file mode 100644 index 0000000..d612949 --- /dev/null +++ b/MP.MONO.UI/MP - Backup (1).MONO.UI.csproj @@ -0,0 +1,72 @@ + + + + net6.0 + enable + enable + AnyCPU;x86;x64 + 1.2.2209.2309 + + + + + + + + + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + Never + + + Never + + + + + + Never + + + Never + + + Never + + + PreserveNewest + + + Always + + + PreserveNewest + + + + + + + diff --git a/MP.MONO.UI/MP - Backup.MONO.UI.csproj b/MP.MONO.UI/MP - Backup.MONO.UI.csproj new file mode 100644 index 0000000..90a1ae4 --- /dev/null +++ b/MP.MONO.UI/MP - Backup.MONO.UI.csproj @@ -0,0 +1,66 @@ + + + + net6.0 + enable + enable + AnyCPU;x86;x64 + 1.2.2209.2309 + + + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + Never + + + Never + + + + + + Never + + + Never + + + Never + + + PreserveNewest + + + Always + + + PreserveNewest + + + + + + + diff --git a/MP.MONO.UI/MP.MONO.UI.csproj b/MP.MONO.UI/MP.MONO.UI.csproj index 7b18968..c9b2b23 100644 --- a/MP.MONO.UI/MP.MONO.UI.csproj +++ b/MP.MONO.UI/MP.MONO.UI.csproj @@ -5,11 +5,17 @@ enable enable AnyCPU;x86;x64 - 1.2.2209.2216 + 1.2.2209.2310 + + + + + + diff --git a/MP.MONO.UI/Pages/Alarms.razor b/MP.MONO.UI/Pages/Alarms.razor index 6c71389..1918967 100644 --- a/MP.MONO.UI/Pages/Alarms.razor +++ b/MP.MONO.UI/Pages/Alarms.razor @@ -184,9 +184,6 @@ @record.DtStart.ToString("yyyy.MM.dd HH:mm:ss") - - @record.DtEnd.ToString("yyyy.MM.dd HH:mm:ss") -
@record.AlarmListNav.FullValue
@@ -205,9 +202,6 @@ @record.DtStart.ToString("yyyy.MM.dd HH:mm:ss") - - @record.DtEnd.ToString("yyyy.MM.dd HH:mm:ss") -
@record.AlarmListNav.FullValue
diff --git a/MP.MONO.UI/Pages/AlarmsAnalysis.razor b/MP.MONO.UI/Pages/AlarmsAnalysis.razor index 2734e62..c42ac01 100644 --- a/MP.MONO.UI/Pages/AlarmsAnalysis.razor +++ b/MP.MONO.UI/Pages/AlarmsAnalysis.razor @@ -11,8 +11,12 @@
@if (ShowCharts == true) { - - } + + }@* + @if (currRecord != null) + { + + }*@ @if (ListRecords == null) { @@ -25,31 +29,20 @@ {
- +
- - - - + + @foreach (var record in ListRecords) { - - + - - - } @@ -60,7 +53,7 @@ } diff --git a/MP.MONO.UI/Pages/AlarmsAnalysis.razor.cs b/MP.MONO.UI/Pages/AlarmsAnalysis.razor.cs index 134f9e3..cb61719 100644 --- a/MP.MONO.UI/Pages/AlarmsAnalysis.razor.cs +++ b/MP.MONO.UI/Pages/AlarmsAnalysis.razor.cs @@ -16,6 +16,8 @@ using MP.MONO.UI.Shared; using MP.MONO.UI.Components; using MP.MONO.Data.DbModels; using MP.MONO.UI.Data; +using MP.MONO.Data.DTO; +using System.Diagnostics.Tracing; namespace MP.MONO.UI.Pages { @@ -23,11 +25,12 @@ namespace MP.MONO.UI.Pages { #region Private Fields - private AlarmRecModel currRecord = null; + private AlarmFreqDTO currRecord = null; - private string fileName = "Controlli.csv"; - private List? ListRecords = null!; - private List? SearchRecords = null!; + private string fileName = "OEE.csv"; + private List ListRecords; + + private List SearchRecords; #endregion Private Fields @@ -37,6 +40,18 @@ namespace MP.MONO.UI.Pages private int _numRecord { get; set; } = 10; + //private SelectData currFilter + //{ + // get + // { + // return MessageService.OEE_Filter; + // } + // set + // { + // MessageService.OEE_Filter = value; + // } + //} + private int currPage { get => _currPage; @@ -45,12 +60,17 @@ namespace MP.MONO.UI.Pages if (_currPage != value) { _currPage = value; - var pUpd = Task.Run(async () => await reloadData()); + var pUpd = Task.Run(async () => await ReloadData()); pUpd.Wait(); } } } + //private string fullPath + //{ + // get => $"{Directory.GetCurrentDirectory()}\\temp\\{fileName}"; + //} + private bool isLoading { get; set; } = false; private int numRecord @@ -61,18 +81,30 @@ namespace MP.MONO.UI.Pages if (_numRecord != value) { _numRecord = value; - var pUpd = Task.Run(async () => await reloadData()); + var pUpd = Task.Run(async () => await ReloadData()); pUpd.Wait(); } } } - private bool ShowCharts { get; set; } = false; + private bool ShowCharts { get; set; } = true; #endregion Private Properties #region Protected Properties + [Inject] + protected IJSRuntime JSRuntime { get; set; } + + //[Inject] + //protected MessageService MessageService { get; set; } + + [Inject] + protected NavigationManager NavManager { get; set; } + + //[Inject] + //protected MpStatsService StatService { get; set; } + protected int totalCount { get @@ -85,20 +117,29 @@ namespace MP.MONO.UI.Pages return answ; } } - //protected int machine { get; set; } = ListRecords.Select(x => x.MachineId).FirstOrDefault(); #endregion Protected Properties - #region Public Properties - - #endregion Public Properties - #region Private Methods - private async Task reloadData() + //private async void clearFile() + //{ + // await Task.Run(() => File.Delete(fullPath)); + //} + + //private async Task ExportCsv() + //{ + // isLoading = true; + // // calcolo nome file + // // salvo davvero! + // await MP.Data.Utils.SaveToCsv(SearchRecords, fullPath); + // isLoading = false; + //} + + private async Task ReloadData() { isLoading = true; - SearchRecords = MP.MONO.UI.Data.CurrentDataService.dbController.AlarmRecGetFilt(int.Parse(ListRecords.Select(x=>x.MachineId)), 0, 200); + SearchRecords = MP.MONO.UI.Data.CurrentDataService.dbController.AlarmRecGetParetoFreq(1, DateTime.Now.AddDays(-1), DateTime.Now); ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList(); isLoading = false; } @@ -107,6 +148,16 @@ namespace MP.MONO.UI.Pages #region Protected Methods + //protected async Task DoFilter(SelectData newFilter) + //{ + // clearFile(); + // currRecord = null; + // SearchRecords = null; + // ListRecords = null; + // currFilter = newFilter; + // await ReloadData(); + //} + protected void ForceReload(int newNum) { numRecord = newNum; @@ -119,42 +170,67 @@ namespace MP.MONO.UI.Pages protected override async Task OnInitializedAsync() { + //clearFile(); numRecord = 10; - await reloadData(); + //MessageService.ShowSearch = false; + //MessageService.PageName = "TRS/OEE %"; + //MessageService.PageIcon = "oi oi-monitor"; + //MessageService.EA_SearchUpdated += OnSeachUpdated; + SearchRecords = MP.MONO.UI.Data.CurrentDataService.dbController.AlarmRecGetParetoFreq(1, DateTime.Now.AddDays(-1), DateTime.Now); + ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList(); + await ReloadData(); } protected void ResetData() { + //clearFile(); + //StatService.rollBackEdit(currRecord); currRecord = null; } + //protected async Task ResetFilter(SelectData newFilter) + //{ + // clearFile(); + // currRecord = null; + // SearchRecords = null; + // ListRecords = null; + // currFilter = SelectData.Init(5, 7); + // await ReloadData(); + //} + + protected void Select(AlarmFreqDTO selRecord) + { + // applico filtro da selezione + currRecord = selRecord; + } + protected async Task ToggleChart(bool doShow) { ShowCharts = !ShowCharts; if (ShowCharts) { - await reloadData(); + await ReloadData(); } } protected async Task UpdateData() { currRecord = null; - await reloadData(); + await ReloadData(); } #endregion Protected Methods #region Public Methods - public string checkSelect(int IdxMacchina) + public string checkSelect(DateTime DtStart, double EventCount, int IdxMacchina) { string answ = ""; if (currRecord != null) { try { - answ = (currRecord.MachineId == IdxMacchina) ? "table-info" : ""; + answ = (currRecord.MachineId == IdxMacchina && currRecord.EventCount == EventCount) ? "table-info" : ""; } catch { } @@ -167,6 +243,14 @@ namespace MP.MONO.UI.Pages //MessageService.EA_SearchUpdated -= OnSeachUpdated; } + // public void OnSeachUpdated() + // { + // InvokeAsync(() => + // { + // UpdateData(); + // StateHasChanged(); + // }); + // } public async void OnSeachUpdated() { await InvokeAsync(() => diff --git a/MP.MONO.UI/Resources/ChangeLog.html b/MP.MONO.UI/Resources/ChangeLog.html index 4541d50..a7cdb01 100644 --- a/MP.MONO.UI/Resources/ChangeLog.html +++ b/MP.MONO.UI/Resources/ChangeLog.html @@ -1,6 +1,6 @@ MAPO-MONO -

Version: 1.2.2209.2216

+

Version: 1.2.2209.2310


Release Note:
  • diff --git a/MP.MONO.UI/Resources/VersNum.txt b/MP.MONO.UI/Resources/VersNum.txt index e5ec7b6..d7b2b08 100644 --- a/MP.MONO.UI/Resources/VersNum.txt +++ b/MP.MONO.UI/Resources/VersNum.txt @@ -1 +1 @@ -1.2.2209.2216 +1.2.2209.2310 diff --git a/MP.MONO.UI/Resources/manifest.xml b/MP.MONO.UI/Resources/manifest.xml index d4e91b6..a80e3c0 100644 --- a/MP.MONO.UI/Resources/manifest.xml +++ b/MP.MONO.UI/Resources/manifest.xml @@ -1,6 +1,6 @@ - 1.2.2209.2216 + 1.2.2209.2310 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
DateTime start
Error
Status
Duration
MacchinaDurata
- @record.DtStart.ToString("yyyy.MM.dd HH:mm:ss") -
-
@record.AlarmListNav.FullValue
-
-
Fixing...
-
-
@TimeSpan.FromMinutes(@record.Duration)
+
@record.MachineId
+
@record.EventCount