163 lines
4.1 KiB
C#
163 lines
4.1 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using MP.MONO.Data.DTO;
|
|
using MP.MONO.UI.Data;
|
|
|
|
namespace MP.MONO.UI.Components
|
|
{
|
|
public partial class ListFreqAlarms
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public selectChartParams selFilter { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public EventCallback<int> TotRecordChanged { get; set; }
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Properties
|
|
|
|
protected int currPage
|
|
{
|
|
get => selFilter.CurrPage;
|
|
}
|
|
|
|
protected DateTime dtEnd
|
|
{
|
|
get => selFilter.dtMax;
|
|
}
|
|
|
|
protected DateTime dtStart
|
|
{
|
|
get => selFilter.dtMin;
|
|
}
|
|
|
|
protected List<AlarmFreqDTO>? ListRecordsFreq { get; set; } = null;
|
|
protected List<AlarmFreqDTO>? SearchRecordsFreq { get; set; } = null;
|
|
protected int totalVar { get; set; } = 0;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
await ReloadData();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private double sogliaGreen = 0;
|
|
|
|
private double sogliaRed = 1;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private int _totalCount { get; set; } = 0;
|
|
|
|
private int numRecord
|
|
{
|
|
get => selFilter.NumRecord;
|
|
}
|
|
|
|
private int totalCount
|
|
{
|
|
get => _totalCount;
|
|
set
|
|
{
|
|
if (_totalCount != value)
|
|
{
|
|
_totalCount = value;
|
|
TotRecordChanged.InvokeAsync(value);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private void calcolaSoglieFreq()
|
|
{
|
|
int numRecord = totalCount;
|
|
if (SearchRecordsFreq != null)
|
|
{
|
|
var firstRecord = SearchRecordsFreq.Skip((int)(numRecord * 0.2)).FirstOrDefault();
|
|
var lastRecord = SearchRecordsFreq.Skip((int)(numRecord * 0.8)).FirstOrDefault();
|
|
if (firstRecord != null)
|
|
{
|
|
sogliaGreen = (double)firstRecord.EventCount / totalVar;
|
|
}
|
|
if (lastRecord != null)
|
|
{
|
|
sogliaRed = (double)lastRecord.EventCount / totalVar;
|
|
}
|
|
}
|
|
}
|
|
|
|
private string calcPercFreq(double numEvent)
|
|
{
|
|
string ans = $"{numEvent / totalVar:P2}";
|
|
|
|
return ans;
|
|
}
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
SearchRecordsFreq = CurrentDataService.dbController.AlarmRecGetParetoFreq(1, dtStart, dtEnd);
|
|
ListRecordsFreq = SearchRecordsFreq.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList();
|
|
totalCount = SearchRecordsFreq.Count;
|
|
totalVar = SearchRecordsFreq.Sum(x => x.EventCount);
|
|
calcolaSoglieFreq();
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
private string styleColourPBarFreq(double eventFreq)
|
|
{
|
|
string ans = "";
|
|
var source = ListRecordsFreq;
|
|
|
|
calcolaSoglieFreq();
|
|
|
|
if (eventFreq >= sogliaGreen)
|
|
{
|
|
ans = "bg-danger";
|
|
}
|
|
else if (eventFreq <= sogliaRed)
|
|
{
|
|
ans = "bg-success";
|
|
}
|
|
else
|
|
{
|
|
ans = "bg-warning";
|
|
}
|
|
|
|
return ans;
|
|
}
|
|
|
|
private string valFreq(double eventCount)
|
|
{
|
|
string ans = "";
|
|
if (SearchRecordsFreq != null)
|
|
{
|
|
int max = SearchRecordsFreq.Max(a => a.EventCount);
|
|
double divisione = eventCount / max;
|
|
int percentage = (int)(divisione * 100);
|
|
ans = $"width: {percentage}%";
|
|
}
|
|
return ans;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |