Files
GPW/GPW.CORE.UI/Components/DayCheckEditor.razor.cs
T
2022-01-15 10:57:47 +01:00

129 lines
3.8 KiB
C#

using GPW.CORE.Data.DbModels;
using Microsoft.AspNetCore.Components;
namespace GPW.CORE.UI.Components
{
public partial class DayCheckEditor
{
#region Protected Fields
protected int _numDays = 30;
#endregion Protected Fields
#region Private Properties
private int numDays
{
get
{
return _numDays;
}
set
{
_numDays = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
#endregion Private Properties
#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 Public Properties
[Parameter]
public EventCallback<bool> CloseReq { get; set; }
[Parameter]
public DateTime TargetDate
{
get
{
return _targetDate;
}
set
{
_targetDate = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
#endregion Public Properties
#region Protected Methods
/// <summary>
/// Indico item 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 GDataServ.RilTempUpdate(currRecord);
}
// chiamo chiusura!
await CloseReq.InvokeAsync(true);
}
protected async Task ReloadData()
{
DateTime inizio = TargetDate.AddDays(1 - numDays);
DateTime fine = TargetDate.AddDays(1);
// recupero dati completi...
var rawVC19 = await GDataServ.CheckVC19List(AppMServ.IdxDipendente, fine.AddDays(-15), fine);
var rawData = await GDataServ.RilTempList(AppMServ.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 = AppMServ.IdxDipendente, DtRilievo = DateTime.Today, TempRil = 0 };
}
}
#endregion Protected Methods
}
}