4fda312aac
- altri metodi tracciati - modifica json x prod - aggiunta Async vari
233 lines
6.7 KiB
C#
233 lines
6.7 KiB
C#
using GWMS.Data;
|
|
using GWMS.Data.DTO;
|
|
using GWMS.UI.Data;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.Extensions.Configuration;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace GWMS.UI.Components
|
|
{
|
|
public partial class PlantOverview
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public PlantDTO currItem
|
|
{
|
|
get
|
|
{
|
|
return _currItem;
|
|
}
|
|
set
|
|
{
|
|
_currItem = value;
|
|
if (value != null)
|
|
{
|
|
var dataReload = Task.Run(async () =>
|
|
{
|
|
// legge i valori di plantLog ultimi 2 gg...
|
|
SelectOrderData plantLevFilt = new SelectOrderData()
|
|
{
|
|
PlantId = value.PlantId,
|
|
DateEnd = DateTime.Today.AddDays(1),
|
|
DateStart = DateTime.Today.AddDays(-1),
|
|
ShowClosed = false
|
|
};
|
|
PlantLevelDto = await DataService.PlantsAnalisysByFiltAsync(plantLevFilt);
|
|
|
|
// aggiunta delay o non riesce a disegnare
|
|
int ChartWaitDelay = 150;
|
|
int.TryParse(Configuration["ChartWaitDelay"], out ChartWaitDelay);
|
|
await Task.Delay(ChartWaitDelay);
|
|
await HandleRedraw();
|
|
});
|
|
dataReload.Wait();
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Fields
|
|
|
|
protected PlantDTO _currItem = new PlantDTO();
|
|
|
|
protected string checkRTime;
|
|
protected string headerStatus;
|
|
protected List<chartJsData.chartJsTSerie> LevelVal = new List<chartJsData.chartJsTSerie>();
|
|
|
|
protected string playCss = "";
|
|
|
|
/// <summary>
|
|
/// fattore di riduzione x visualizzare meno punti (in base alla numerosità...
|
|
/// </summary>
|
|
protected int redFact = 1;
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected MessageService AppMService { get; set; }
|
|
|
|
[Inject]
|
|
protected GWMSDataService DataService { get; set; }
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// Genera colori sfondo
|
|
/// </summary>
|
|
/// <param name="numRecords"></param>
|
|
/// <returns></returns>
|
|
protected List<string> getFillColors(string alpha)
|
|
{
|
|
List<string> answ = new List<string>();
|
|
answ.Add($"rgba(108, 164, 254, {alpha})");
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Genera colori linea
|
|
/// </summary>
|
|
/// <param name="numRecords"></param>
|
|
/// <returns></returns>
|
|
protected List<string> getLineColors(string alpha)
|
|
{
|
|
List<string> answ = new List<string>();
|
|
answ.Add($"rgba(54, 82, 254, {alpha})");
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Genera colori punti
|
|
/// </summary>
|
|
/// <param name="numRecords"></param>
|
|
/// <returns></returns>
|
|
protected List<string> getPointColors(string alpha)
|
|
{
|
|
List<string> answ = new List<string>();
|
|
answ.Add($"rgba(108, 118, 158, {alpha})");
|
|
return answ;
|
|
}
|
|
|
|
protected string getPressData(string valore, string formato)
|
|
{
|
|
string answ = "";
|
|
if (currItem.PressAct.ContainsKey(valore))
|
|
{
|
|
answ = currItem.PressAct[valore].ToString(formato);
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
protected async Task HandleRedraw()
|
|
{
|
|
checkRt();
|
|
fixRedFactor();
|
|
await Task.Delay(1);
|
|
LevelVal = _currItem.LevelTS.OrderByDescending(x => x.DtEvent).Where((cat, index) => index % redFact == 0).OrderBy(x => x.DtEvent).Select(r => new chartJsData.chartJsTSerie() { x = r.DtEvent, y = r.ValDouble }).ToList();
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
if (firstRender)
|
|
{
|
|
await HandleRedraw();
|
|
}
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await HandleRedraw();
|
|
}
|
|
|
|
protected void ShowDetail(int currPlantId)
|
|
{
|
|
SelPlantId = currPlantId;
|
|
// rimando...
|
|
NavManager.NavigateTo($"PlantAnalisys");
|
|
}
|
|
|
|
protected void ShowOrders(int currPlantId)
|
|
{
|
|
SelPlantId = currPlantId;
|
|
// rimando...
|
|
NavManager.NavigateTo($"Orders");
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Properties
|
|
|
|
[Inject]
|
|
private IConfiguration Configuration { get; set; }
|
|
|
|
private bool dataIsRT { get; set; } = false;
|
|
private bool deviceOnline { get; set; } = false;
|
|
|
|
[Inject]
|
|
private NavigationManager NavManager { get; set; }
|
|
|
|
private List<PlantLevSumDTO>? PlantLevelDto { get; set; } = null;
|
|
|
|
private int SelPlantId
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
if (AppMService.Order_Filter != null)
|
|
{
|
|
answ = AppMService.Order_Filter.PlantId;
|
|
}
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
if (!AppMService.Order_Filter.PlantId.Equals(value))
|
|
{
|
|
AppMService.Order_Filter.PlantId = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private void checkRt()
|
|
{
|
|
DateTime adesso = DateTime.Now;
|
|
int TimeoutOffline = 5;
|
|
int.TryParse(Configuration["TimeoutOffline"], out TimeoutOffline);
|
|
deviceOnline = adesso.Subtract(_currItem.LastUpdate).TotalMinutes <= TimeoutOffline;
|
|
dataIsRT = adesso.Subtract(_currItem.LastUpdate).TotalMinutes <= 2;
|
|
}
|
|
|
|
private void fixRedFactor()
|
|
{
|
|
int answ = 1;
|
|
int numCount = _currItem.LevelTS.Count;
|
|
// passo a 2h se > 3 gg
|
|
if (numCount > 240)
|
|
answ = 5;
|
|
// passo a 3h se > 5 gg
|
|
else if (numCount > 120)
|
|
answ = 4;
|
|
// passo a 4h se > 10 gg
|
|
else if (numCount > 72)
|
|
answ = 3;
|
|
redFact = answ;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |