using EgwCoreLib.Razor.Data; using GPW.CORE.Data.DbModels; using GPW.CORE.Smart.Data; using Microsoft.AspNetCore.Components; namespace GPW.CORE.Smart.Components.Compo { public partial class CheckTemp { #region Public Properties [Parameter] public EventCallback 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? listRilTemp { get; set; } = null; protected List? 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); } /// /// Indico CurrItem 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 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 } }