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? listRilTemp { get; set; } = null; protected List? listVC19 { get; set; } = null; #endregion Protected Properties #region Public Properties [Parameter] public EventCallback 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 /// /// Indico item selezionato /// protected async void DoClose() { await CloseReq.InvokeAsync(true); } /// /// Effettua salvataggio misurazione temperatura /// 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 } }