Files
gpw_next/GPW.CORE6.Smart/Components/CheckTemp.razor.cs
T
Samuele Locatelli 848b6537d2 Update x nuovo proj 8
2024-08-22 16:03:31 +02:00

152 lines
4.3 KiB
C#

using EgwCoreLib.Razor.Data;
using GPW.CORE.Data.DbModels;
using GPW.CORE6.Smart.Data;
using Microsoft.AspNetCore.Components;
namespace GPW.CORE6.Smart.Components
{
public partial class CheckTemp
{
#region Public Properties
[Parameter]
public EventCallback<bool> CloseReq { get; set; }
[Parameter]
public int IdxDipendente { get; set; } = -1;
[Parameter]
public DateTime TargetDate
{
get
{
return _targetDate;
}
set
{
_targetDate = value;
}
}
#endregion Public Properties
#region Protected Fields
protected int _numDays = 30;
#endregion Protected Fields
#region Protected Properties
protected DateTime _targetDate { get; set; } = DateTime.Today;
protected RilievoTempModel? currRecord { get; set; } = null;
protected string[]? histData { get; set; } = null;
protected string[]? histLabel { get; set; } = null;
protected List<chartJsData.chartJsTSerie>? listRilTemp { get; set; } = null;
protected List<CheckVc19Model>? listVC19 { get; set; } = null;
#endregion Protected Properties
#region Protected Methods
protected async Task addDays(int numDay)
{
TargetDate = TargetDate.AddDays(numDay);
await ReloadData();
await InvokeAsync(StateHasChanged);
}
/// <summary>
/// Indico CurrItem selezionato
/// </summary>
protected async void DoClose()
{
await CloseReq.InvokeAsync(true);
}
/// <summary>
/// Effettua salvataggio misurazione temperatura
/// </summary>
protected async void DoSave()
{
// chiamo classe gestione che salva e resetta cache dati...
if (currRecord != null)
{
await CDService.RilTempUpdate(currRecord);
}
// chiamo chiusura!
await CloseReq.InvokeAsync(true);
}
protected override async Task OnParametersSetAsync()
{
await ReloadData();
await InvokeAsync(StateHasChanged);
}
protected async Task ReloadData()
{
DateTime inizio = TargetDate.AddDays(1 - numDays);
DateTime fine = TargetDate.AddDays(1);
// recupero dati completi...
var rawVC19 = await CDService.CheckVC19List(IdxDipendente, fine.AddDays(-15), fine);
var rawData = await CDService.RilTempList(IdxDipendente, inizio, fine);
// calcolo dati derivati
listVC19 = rawVC19.OrderByDescending(x => x.DtCheck).ToList();
listRilTemp = rawData.Select(r => new chartJsData.chartJsTSerie()
{ x = r.DtRilievo, y = r.TempRil }).ToList();
// calcolo hist frequenza con EFCore: https://entityframeworkcore.com/knowledge-base/60871048/group-by-and-to-dictionary-in-ef-core-3-1
var histDict = rawData.GroupBy(r => r.TempRil.ToString("N1")).Select(g => new
{
g.Key,
Count = g.Count()
}).OrderBy(d => d.Key).ToDictionary(x => x.Key, x => x.Count.ToString());
histData = histDict.Values.ToArray();
histLabel = histDict.Keys.ToArray();
// cerco se c' dato odierno della temperatura...
currRecord = rawData.Where(x => x.DtRilievo == TargetDate).FirstOrDefault();
if (currRecord == null)
{
currRecord = new RilievoTempModel()
{
IdxDipendente = IdxDipendente,
DtRilievo = TargetDate,
TempRil = 0
};
}
}
#endregion Protected Methods
#region Private Properties
[Inject]
private CoreSmartDataService CDService { get; set; } = null!;
private int numDays
{
get
{
return _numDays;
}
set
{
_numDays = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
#endregion Private Properties
}
}