UI_SequentMicrosystems-RPI/Components/PointsTableRTD8TMComponent....

146 lines
4.4 KiB
Plaintext

@using System.Text
@using UI_SequentMicrosystems.Constants
@using UI_SequentMicrosystems.Models
@using UI_SequentMicrosystems.Services
@using UI_SequentMicrosystems.Components
@inject PointsService _PointsService
@inject RTD8TMService _RTD8TMService
@if (TableData.Keys.Count > 0)
{
<table class="table table-striped text-white">
<thead>
<tr>
<th scope="col">Time</th>
@foreach (byte stack in _RTD8TMService.GetActualData().Keys)
{
for (byte chanel = 0; chanel < 8; chanel++)
{
if (_RTD8TMService.GetChanelName(stack, chanel) != "----------")
{
<th>
@_RTD8TMService.GetChanelName(stack, chanel)
@if (_RTD8TMService.GetValueType(stack, chanel) == RTD8TMSensorTypes.PT100)
{
@Celsius
}
else
{
@Ohm
}
</th>
}
}
}
</tr>
</thead>
<tbody>
@foreach (long time in TableData.Keys)
{
<tr class="text-white @TableBacgroundChanger() ">
<td>@(new DateTime(time).ToString("HH:mm:ss"))</td>
@foreach (byte stack in TableData[time].Keys)
{
for (byte chanel = 0; chanel < 8; chanel++)
{
if (_RTD8TMService.GetChanelName(stack, chanel) != "----------")
{
<td>@(new RTD8TMChanelComponent().RecalculateValues(TableData[time][stack][chanel], _RTD8TMService.GetValueType(stack, chanel)))</td>
}
}
}
</tr>
}
</tbody>
@if (LastDataTime != 0 && AfterHalfHour != 0)
{
<tfoot>
<tr class="text-warning">
<td>30min Change</td>
@foreach (byte stack in TableData[TableData.Keys.OrderDescending().First()].Keys)
{
for (byte chanel = 0; chanel < 8; chanel++)
{
if (_RTD8TMService.GetChanelName(stack, chanel) != "----------")
{
<td>@Math.Round(new RTD8TMChanelComponent().RecalculateValues(TableData[LastDataTime][stack][chanel], _RTD8TMService.GetValueType(stack, chanel)) - new RTD8TMChanelComponent().RecalculateValues(TableData[AfterHalfHour][stack][chanel], _RTD8TMService.GetValueType(stack, chanel)), 2)</td>
}
}
}
</tr>
</tfoot>
}
</table>
}
else
{
<h1>No data</h1>
}
@code {
private SortedList<long, SortedList<byte,List<float>>> TableData = new();
private string Ohm = " (Ω)";
private string Celsius = " (°C)";
private bool TableBackground = false;
private long LastDataTime = 0;
private long AfterHalfHour = 0;
protected override void OnInitialized()
{
TableData = _PointsService.GetPoints().RTD8TM;
_PointsService.EventPointPage += UpdateView;
if (TableData.Keys.Count > 1)
{
HalfHourTime();
}
}
private string TableBacgroundChanger()
{
if (TableBackground)
{
TableBackground = false;
return "bg-black";
}
else
{
TableBackground = true;
return "bg-dark";
}
}
private void HalfHourTime()
{
LastDataTime = TableData.Keys.OrderDescending().First();
long backhalfhour = new DateTime(LastDataTime).AddMinutes(-30).Ticks;
AfterHalfHour = TableData.Keys.OrderBy(item => Math.Abs(backhalfhour - item)).First();
}
public async Task UpdateView(object? o, bool b)
{
await InvokeAsync(() =>
{
TableBackground = false;
if (TableData.Keys.Count > 1)
{
HalfHourTime();
}
StateHasChanged();
});
}
}