using Microsoft.AspNetCore.Components; using MP.MONO.Data; using MP.MONO.Data.DbModels; namespace MP.MONO.UI.Components { public partial class ParamPlot { #region Private Fields private List? ListRecords = null; #endregion Private Fields #region Protected Fields protected DateTime lastRec = DateTime.Now.AddMinutes(-1); protected List LevelVal = new List(); protected Dictionary listMaxVal = new Dictionary(); protected Dictionary listMinVal = new Dictionary(); #endregion Protected Fields #region Private Properties private bool isLoading { get; set; } = false; #endregion Private Properties #region Protected Properties protected string _selParam { get; set; } = ""; protected DateTime DateFrom { get; set; } = DateTime.Today.AddDays(-1); protected DateTime DateTo { get; set; } = DateTime.Today.AddDays(1); protected string? MaxVal { get { string answ = "0"; if (listMaxVal != null && listMaxVal.Count > 0) { answ = listMaxVal[SelectedParam] ?? "0"; } return answ; } } protected string? MinVal { get { string answ = "0"; if (listMinVal != null && listMinVal.Count > 0) { answ = listMinVal[SelectedParam] ?? "0"; } return answ; } } #endregion Protected Properties #region Public Properties [Parameter] public DateTime EndDate { get { return DateTo; } set { DateTo = value; var pUpd = Task.Run(async () => await ReloadData()); pUpd.Wait(); } } [Parameter] public int MachineId { get; set; } = 1; public string ParamId { get => _selParam.Replace(" ", "_"); } [Parameter] public string SelectedParam { get { return _selParam; } set { // controllo se è variato if (_selParam != value) { // salvo _selParam = value; var pUpd = Task.Run(async () => await ReloadData()); pUpd.Wait(); } } } [Parameter] public DateTime StartDate { get { return DateFrom; } set { DateFrom = value; var pUpd = Task.Run(async () => await ReloadData()); pUpd.Wait(); } } #endregion Public Properties #region Protected Methods protected List getFillColors(string alpha) { List answ = new List(); answ.Add($"rgba(108, 214, 164, {alpha})"); return answ; } protected List getLineColors(string alpha) { List answ = new List(); answ.Add($"rgba(54, 204, 82, {alpha})"); return answ; } protected List getPointColors(string alpha) { List answ = new List(); answ.Add($"rgba(108, 158, 118, {alpha})"); return answ; } protected override async Task OnInitializedAsync() { await ReloadData(); await Task.Delay(1); } protected async Task ReloadData() { isLoading = true; ListRecords = null; await Task.Delay(1); ListRecords = await MMDataService.DataLogGetFilt(MachineId, SelectedParam, StartDate, EndDate); // converto in plotdata LevelVal = ListRecords.Select(l => new chartJsData.chartJsTSerie() { x = l.DtRif, y = l.ValNum }).ToList(); await Task.Delay(1); isLoading = false; } #endregion Protected Methods } }