bugfixing

master
Jan Beníček 2024-02-01 08:33:05 +01:00
parent 8b62c82a15
commit 03413fb499
4 changed files with 164 additions and 65 deletions

View File

@ -135,11 +135,11 @@ else
await InvokeAsync(() => await InvokeAsync(() =>
{ {
TableBackground = false; TableBackground = false;
StateHasChanged();
if (TableData.Keys.Count > 1) if (TableData.Keys.Count > 1)
{ {
HalfHourTime(); HalfHourTime();
} }
StateHasChanged();
}); });
} }
} }

View File

@ -6,7 +6,7 @@
<div class="row"> <div class="row">
<div class="col-2 col-sm-4 col-md-4 col-xl-4 h5 text-end align-self-center"><strong>@(RecalculateValues(RTD8tmService.GetActualData(StackID, ChanelID), RTD8tmService.GetValueType(StackID, ChanelID)))</strong></div> <div class="col-2 col-sm-4 col-md-4 col-xl-4 h5 text-end align-self-center"><strong>@(Math.Round(RecalculateValues(RTD8tmService.GetActualData(StackID, ChanelID), RTD8tmService.GetValueType(StackID, ChanelID)), 2))</strong></div>
@if (Edit) @if (Edit)
{ {
@ -70,8 +70,13 @@
RTD8tmService.SetChanelNames(StackID, ChanelID, NewName); RTD8tmService.SetChanelNames(StackID, ChanelID, NewName);
} }
private void CalibrationChanged(string NewCalibration) private void CalibrationChanged(string? NewCalibration)
{ {
if (NewCalibration == null || NewCalibration == "")
{
NewCalibration = "0";
}
NewCalibration = NewCalibration.Replace(".", ","); NewCalibration = NewCalibration.Replace(".", ",");
RTD8tmService.SetCalibration(StackID, ChanelID, float.Parse(NewCalibration)); RTD8tmService.SetCalibration(StackID, ChanelID, float.Parse(NewCalibration));
} }

View File

@ -1,10 +1,21 @@
@using ApexCharts @using ApexCharts
@using Newtonsoft.Json
@using UI_SequentMicrosystems.Components @using UI_SequentMicrosystems.Components
@using UI_SequentMicrosystems.Services @using UI_SequentMicrosystems.Services
@using UI_SequentMicrosystems.Models @using UI_SequentMicrosystems.Models
@inject RTD8TMService _RTD8TMService @inject RTD8TMService _RTD8TMService
<ApexChart TItem="RTD8TMPointModel"
@if (_RTD8TMService.GetActualData().Keys.Count > 0)
{
if (false)
{
<div>
<input type="text" class="form-control form-control-sm bg-black text-white no-border" placeholder="Json syntax with Chart Points" @onchange="((x) => ChartPointsAdd(x.Value.ToString()))">
</div>
}
<ApexChart TItem="RTD8TMPointModel"
Title="Temperature" Title="Temperature"
Options="chartOptions" Options="chartOptions"
@ref="chart"> @ref="chart">
@ -15,6 +26,8 @@
{ {
if (_RTD8TMService.GetChanelName(stack, chanel) != "----------") if (_RTD8TMService.GetChanelName(stack, chanel) != "----------")
{ {
//Console.WriteLine($"Chart Data: Stack: {stack} | Chanel: {chanel} | {JsonConvert.SerializeObject(_RTD8TMService.GetChartData(stack, chanel))}");
<ApexPointSeries TItem="RTD8TMPointModel" <ApexPointSeries TItem="RTD8TMPointModel"
Items="@_RTD8TMService.GetChartData(stack, chanel)" Items="@_RTD8TMService.GetChartData(stack, chanel)"
Name="@(_RTD8TMService.GetChanelName(stack, chanel))" Name="@(_RTD8TMService.GetChanelName(stack, chanel))"
@ -22,10 +35,13 @@
XValue="@(e => e.Time.ToString("HH:mm:ss"))" XValue="@(e => e.Time.ToString("HH:mm:ss"))"
YValue="@(e => (decimal)e.Value)" YValue="@(e => (decimal)e.Value)"
OrderBy="e=>e.X" /> OrderBy="e=>e.X" />
} }
} }
} }
</ApexChart> </ApexChart>
}
@code { @code {
private ApexChart<RTD8TMPointModel> chart; private ApexChart<RTD8TMPointModel> chart;
@ -36,7 +52,6 @@
{ {
_RTD8TMService.EventUpdateGraph += UpdateChart; _RTD8TMService.EventUpdateGraph += UpdateChart;
chartOptions = new ApexChartOptions<RTD8TMPointModel> chartOptions = new ApexChartOptions<RTD8TMPointModel>
{ {
Theme = new Theme Theme = new Theme
@ -46,10 +61,11 @@
Legend = new Legend Legend = new Legend
{ {
Position = LegendPosition.Bottom, Position = LegendPosition.Bottom,
FontSize = "20px", FontSize = "15px",
HorizontalAlign = Align.Center HorizontalAlign = Align.Center
} }
}; };
} }
public async Task UpdateChart(object? o, bool b) public async Task UpdateChart(object? o, bool b)
@ -63,7 +79,10 @@
}); });
} }
public void ChartPointsAdd(string points)
{
_RTD8TMService.SetChartData(JsonConvert.DeserializeObject<SortedList<byte, List<List<RTD8TMPointModel>>>>(points));
}

View File

@ -1,4 +1,6 @@
using System.Threading.Channels; using Newtonsoft.Json;
using System.Diagnostics.Metrics;
using System.Threading.Channels;
using System.Timers; using System.Timers;
using UI_SequentMicrosystems.Components; using UI_SequentMicrosystems.Components;
using UI_SequentMicrosystems.Models; using UI_SequentMicrosystems.Models;
@ -14,13 +16,14 @@ namespace UI_SequentMicrosystems.Services
private SortedList<byte, float[]> Calibrations = new SortedList<byte, float[]>(); private SortedList<byte, float[]> Calibrations = new SortedList<byte, float[]>();
public SortedList<byte, List<List<RTD8TMPointModel>>> GraphData = new(); public SortedList<byte, List<List<RTD8TMPointModel>>> GraphData = new();
public SortedList<byte, List<List<RTD8TMPointModel>>> GraphFiltered = new(); public SortedList<byte, List<List<RTD8TMPointModel>>> GraphFiltered = new();
private int GraphFilteredCountPoint { get; set; }
private byte GraphDataCounterCount = 10; private byte GraphDataCounterCount = 10;
private byte GraphDataCounter = 9; private byte GraphDataCounter = 9;
private string? Address { get; set; } private string? Address { get; set; }
private RTD8TM _RTD8TM = new RTD8TM(); private RTD8TM _RTD8TM = new RTD8TM();
private System.Timers.Timer _timer = new(1000); private System.Timers.Timer _timer = new(1000); //update timer
public delegate Task AsyncEventHandler<TEventArgs>(object? sender, TEventArgs? e); public delegate Task AsyncEventHandler<TEventArgs>(object? sender, TEventArgs? e);
public event AsyncEventHandler<bool>? EventUpdateValues; public event AsyncEventHandler<bool>? EventUpdateValues;
@ -76,6 +79,8 @@ namespace UI_SequentMicrosystems.Services
{ {
if (Address == null) { return; } if (Address == null) { return; }
try
{
ActualValues = await _RTD8TM.Get(Address); ActualValues = await _RTD8TM.Get(Address);
foreach (byte stack in ActualValues.Keys) foreach (byte stack in ActualValues.Keys)
@ -95,17 +100,17 @@ namespace UI_SequentMicrosystems.Services
GraphDataCounter = 0; GraphDataCounter = 0;
ReadChartData(); ReadChartData();
if (EventUpdateGraph != null)
{
await EventUpdateGraph.Invoke(this, true);
}
} }
else else
{ {
GraphDataCounter++; GraphDataCounter++;
} }
} }
catch (Exception ex)
{
Console.WriteLine($"Reading actual Data fail with message: {ex.Message}");
}
}
/// <summary> /// <summary>
/// Request for actual data /// Request for actual data
@ -288,21 +293,38 @@ namespace UI_SequentMicrosystems.Services
/// <returns>saved chart chanel Data</returns> /// <returns>saved chart chanel Data</returns>
public List<RTD8TMPointModel> GetChartData(byte StackID, byte Chanel) public List<RTD8TMPointModel> GetChartData(byte StackID, byte Chanel)
{ {
Console.WriteLine($"RTD8TMService:GetChartData({StackID}, {Chanel}) - start reading");
if (!GraphFiltered.ContainsKey(StackID)) if (!GraphFiltered.ContainsKey(StackID))
{ {
Console.WriteLine($"RTD8TMService:GetChartData({StackID}, {Chanel}) - Return new() - Unknow StackID - Stack_Keys: {JsonConvert.SerializeObject(GraphFiltered.Keys)}");
return new List<RTD8TMPointModel>(); return new List<RTD8TMPointModel>();
} }
List<RTD8TMPointModel> RecalculatedData = new(); List<RTD8TMPointModel> RecalculatedData = new();
byte chanelRecalcTo = GetValueType(StackID, Chanel); byte chanelRecalcTo = GetValueType(StackID, Chanel);
RTD8TMChanelComponent _RTD8TMChanelComponent = new RTD8TMChanelComponent();
float LastValue = -1;
int CountErrors = 0;
foreach (RTD8TMPointModel point in GraphFiltered[StackID][Chanel]) foreach (RTD8TMPointModel point in GraphFiltered[StackID][Chanel])
{ {
RTD8TMPointModel recalculated = new() { Time = point.Time, Value = new RTD8TMChanelComponent().RecalculateValues(point.Value, chanelRecalcTo) }; RTD8TMPointModel recalculated = new() { Time = point.Time, Value = _RTD8TMChanelComponent.RecalculateValues(point.Value, chanelRecalcTo) };
if (LastValue == -1 || CountErrors > 1 || (recalculated.Value >= (LastValue - 10) && recalculated.Value <= (LastValue + 10)))
{
RecalculatedData.Add(recalculated); RecalculatedData.Add(recalculated);
LastValue = recalculated.Value;
CountErrors = 0;
}
else
{
CountErrors++;
}
} }
Console.WriteLine($"RTD8TMService:GetChartData({StackID}, {Chanel})");
return RecalculatedData; return RecalculatedData;
} }
@ -315,21 +337,24 @@ namespace UI_SequentMicrosystems.Services
GraphData.Clear(); GraphData.Clear();
} }
private void GetFilteredChartData() private async void GetFilteredChartData()
{ {
foreach ( byte stack in GraphData.Keys) GraphFiltered = new SortedList<byte, List<List<RTD8TMPointModel>>>();
foreach (byte stack in GraphData.Keys)
{ {
int pointsCount = GraphData[stack][0].Count; int pointsCount = GraphData[stack][0].Count;
int counter = 0; int counter = 0;
Console.WriteLine($"RTD8TMService:GetFilteredChartData - Stack: {stack} | PointsCount: {pointsCount} | counter: {counter} | GraphData_Keys: {JsonConvert.SerializeObject(GraphData.Keys)}");
if (pointsCount < 100) if (pointsCount < 100)
{ {
GraphFiltered = GraphData; GraphFiltered = GraphData;
} }
else if (pointsCount > 100 && pointsCount < 500) // one from five else if (pointsCount >= 100 && pointsCount < 500) // one from five
{ {
GraphFiltered = new(); GraphFiltered.Add(stack, new List<List<RTD8TMPointModel>>());
GraphFiltered.Add(stack, new());
for (int chanel = 0; chanel < 8; chanel++) for (int chanel = 0; chanel < 8; chanel++)
{ {
@ -348,9 +373,8 @@ namespace UI_SequentMicrosystems.Services
} }
} }
} }
else if (pointsCount > 500 && pointsCount < 1000) // one from ten else if (pointsCount >= 500 && pointsCount < 1000) // one from ten
{ {
GraphFiltered = new();
GraphFiltered.Add(stack, new()); GraphFiltered.Add(stack, new());
for (int chanel = 0; chanel < 8; chanel++) for (int chanel = 0; chanel < 8; chanel++)
@ -370,9 +394,8 @@ namespace UI_SequentMicrosystems.Services
} }
} }
} }
else if (pointsCount > 1000 && pointsCount < 1500) // one from fifteen else if (pointsCount >= 1000 && pointsCount < 1500) // one from fifteen
{ {
GraphFiltered = new();
GraphFiltered.Add(stack, new()); GraphFiltered.Add(stack, new());
for (int chanel = 0; chanel < 8; chanel++) for (int chanel = 0; chanel < 8; chanel++)
@ -392,9 +415,8 @@ namespace UI_SequentMicrosystems.Services
} }
} }
} }
else if (pointsCount > 1500) // one from twenty else if (pointsCount >= 1500 && pointsCount < 2000) // one from twenty
{ {
GraphFiltered = new();
GraphFiltered.Add(stack, new()); GraphFiltered.Add(stack, new());
for (int chanel = 0; chanel < 8; chanel++) for (int chanel = 0; chanel < 8; chanel++)
@ -414,9 +436,61 @@ namespace UI_SequentMicrosystems.Services
} }
} }
} }
else if (pointsCount >= 2000 && pointsCount < 3500) // one from TwentyFive
{
GraphFiltered.Add(stack, new());
for (int chanel = 0; chanel < 8; chanel++)
{
GraphFiltered[stack].Add(new());
foreach (RTD8TMPointModel GraphPoint in GraphData[stack][chanel])
{
if (counter > 23)
{
GraphFiltered[stack][chanel].Add(GraphPoint);
counter = 0;
}
else
{
counter++;
}
}
}
}
else if (pointsCount >= 3500) // one from twenty
{
GraphFiltered.Add(stack, new());
for (int chanel = 0; chanel < 8; chanel++)
{
GraphFiltered[stack].Add(new());
foreach (RTD8TMPointModel GraphPoint in GraphData[stack][chanel])
{
if (counter > 28)
{
GraphFiltered[stack][chanel].Add(GraphPoint);
counter = 0;
}
else
{
counter++;
}
}
}
}
//případně další //případně další
} }
if (EventUpdateGraph != null)
{
if (CountFilteredChartData() != GraphFilteredCountPoint)
{
GraphFilteredCountPoint = CountFilteredChartData();
await EventUpdateGraph.Invoke(this, true);
}
}
Console.WriteLine($"RTD8TMService:GetFilteredChartData - GraphFiltered_Keys: {JsonConvert.SerializeObject(GraphFiltered.Keys)}");
} }
public int CountFilteredChartData() public int CountFilteredChartData()
@ -453,6 +527,7 @@ namespace UI_SequentMicrosystems.Services
/// <param name="data"></param> /// <param name="data"></param>
public void SetChartData(SortedList<byte, List<List<RTD8TMPointModel>>> data) public void SetChartData(SortedList<byte, List<List<RTD8TMPointModel>>> data)
{ {
Console.WriteLine($"RTD8TMService:SetChartData - {JsonConvert.SerializeObject(data)}");
GraphData = data; GraphData = data;
} }