184 lines
4.6 KiB
C#
184 lines
4.6 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using MP.MONO.Data.DTO;
|
|
using MP.MONO.UI.Data;
|
|
|
|
namespace MP.MONO.UI.Components
|
|
{
|
|
public partial class ListDurAlarms
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public selectChartParams selFilter { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public EventCallback<int> TotRecordChanged { get; set; }
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Properties
|
|
|
|
public static string FormDurata(double durataMinuti)
|
|
{
|
|
string answ = "";
|
|
TimeSpan tsDurata = TimeSpan.FromMinutes(durataMinuti);
|
|
if (tsDurata.TotalDays < 1)
|
|
{
|
|
answ = $"{tsDurata.Hours:00}:{tsDurata.Minutes:00}:{tsDurata.Seconds:00}";
|
|
}
|
|
else
|
|
{
|
|
answ = $"{tsDurata.Days}d {tsDurata.Hours:00}:{tsDurata.Minutes:00}";
|
|
}
|
|
return answ;
|
|
}
|
|
protected int currPage
|
|
{
|
|
get => selFilter.CurrPage;
|
|
}
|
|
|
|
protected DateTime dtEnd
|
|
{
|
|
get => selFilter.dtMax;
|
|
}
|
|
|
|
protected DateTime dtStart
|
|
{
|
|
get => selFilter.dtMin;
|
|
}
|
|
|
|
protected List<AlarmDurationDTO>? ListRecordsDur { get; set; } = null;
|
|
protected List<AlarmDurationDTO>? SearchRecordsDur { get; set; } = null;
|
|
protected double 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 calcolaSoglieDur()
|
|
{
|
|
int numRecord = totalCount;
|
|
if (SearchRecordsDur != null)
|
|
{
|
|
|
|
var firstRecord = SearchRecordsDur.Skip((int)(numRecord * 0.2)).FirstOrDefault();
|
|
var lastRecord = SearchRecordsDur.Skip((int)(numRecord * 0.8)).FirstOrDefault();
|
|
if (firstRecord != null)
|
|
{
|
|
sogliaGreen = (double)firstRecord.Duration / totalVar;
|
|
}
|
|
if (lastRecord != null)
|
|
{
|
|
sogliaRed = (double)lastRecord.Duration / totalVar;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected string calcPercDur(double duration)
|
|
{
|
|
string ans = $"{duration / totalVar:P2}";
|
|
|
|
return ans;
|
|
}
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
SearchRecordsDur = CurrentDataService.dbController.AlarmRecGetParetoDur(1, dtStart, dtEnd);
|
|
ListRecordsDur = SearchRecordsDur.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList();
|
|
totalCount = SearchRecordsDur.Count;
|
|
totalVar = SearchRecordsDur.Sum(x => x.Duration);
|
|
//calcolaSoglieDur();
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
protected string styleColourPBarDur(double duration)
|
|
{
|
|
string ans = "";
|
|
//var source = ListRecordsDur;
|
|
|
|
calcolaSoglieDur();
|
|
|
|
if (duration >= sogliaGreen)
|
|
{
|
|
ans = "bg-danger";
|
|
}
|
|
else if (duration <= sogliaRed)
|
|
{
|
|
ans = "bg-success";
|
|
}
|
|
else
|
|
{
|
|
ans = "bg-warning";
|
|
}
|
|
|
|
return ans;
|
|
}
|
|
|
|
protected string valDur(double duration)
|
|
{
|
|
string ans = "";
|
|
if (SearchRecordsDur != null)
|
|
{
|
|
|
|
double max = SearchRecordsDur.Max(a => a.Duration);
|
|
|
|
double divisione = duration / max;
|
|
|
|
int percentage = (int)(divisione * 100);
|
|
|
|
ans = $"width: {percentage}%";
|
|
}
|
|
|
|
return ans;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
}
|