Update to version 1.0 - first production build

master
Jan Beníček 2024-01-12 09:30:42 +01:00
parent 1ecb5a545f
commit f97ec1847b
15 changed files with 601 additions and 23 deletions

View File

@ -0,0 +1,65 @@
@using UI_SequentMicrosystems.Services
@inject PointsService _PointsService
@inject IJSRuntime _JSRuntime
<div class="row text-center">
<div class="col">
<button class="btn btn-dark text-white no-border" @onclick="(() => _PointsService.SavePoint())">Save Point (@_PointsService.GetPointsCount())</button>
</div>
<div class="col row">
<div class="col-md-3 col">
<button class="btn btn-dark text-white no-border" @onclick="(() => DownloadFile())">Export as CSV</button>
</div>
<div class="col-md-3 col text-start align-self-center">
<div class="form-check form-switch">
@if (RecalculateValues)
{
<input class="form-check-input" type="checkbox" role="switch" id="flexSwitchCheckDefault" @onclick="(() =>
{
RecalculateValues = false;
})" checked>
}
else
{
<input class="form-check-input" type="checkbox" role="switch" id="flexSwitchCheckDefault" @onclick="(() => RecalculateValues = true)">
}
<label class="form-check-label" for="flexSwitchCheckDefault">Recalculate Values?</label>
</div>
</div>
</div>
</div>
@code {
private bool RecalculateValues = false;
private async void DownloadFile()
{
// Název souboru
string fileName = "TESDevice1.csv";
// Vytvoření a spuštění odkazu ke stažení
await _JSRuntime.InvokeVoidAsync("DownloadFile", fileName, await _PointsService.CreatePointsFileLines(RecalculateValues));
}
}

View File

@ -0,0 +1,101 @@
@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
<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>
</table>
@code {
private SortedList<long, SortedList<byte,List<float>>> TableData = new();
private string Ohm = " (Ω)";
private string Celsius = " (°C)";
private bool TableBackground = false;
protected override void OnInitialized()
{
TableData = _PointsService.GetPoints().RTD8TM;
}
private string TableBacgroundChanger()
{
if (TableBackground)
{
TableBackground = false;
return "bg-black";
}
else
{
TableBackground = true;
return "bg-dark";
}
}
}

View File

@ -4,8 +4,7 @@
@using UI_SequentMicrosystems.Models
@inject RTD8TMService _RTD8TMService
<ApexChart TItem="RTD8TMGraphPointModel"
<ApexChart TItem="RTD8TMPointModel"
Title="Temperature"
Options="chartOptions"
@ref="chart">
@ -16,7 +15,7 @@
{
if (_RTD8TMService.GetChanelName(stack, chanel) != "----------")
{
<ApexPointSeries TItem="RTD8TMGraphPointModel"
<ApexPointSeries TItem="RTD8TMPointModel"
Items="@_RTD8TMService.GetChartData(stack, chanel)"
Name="@(_RTD8TMService.GetChanelName(stack, chanel))"
SeriesType="SeriesType.Line"
@ -29,8 +28,8 @@
</ApexChart>
@code {
private ApexChart<RTD8TMGraphPointModel> chart;
private ApexChartOptions<RTD8TMGraphPointModel> chartOptions;
private ApexChart<RTD8TMPointModel> chart;
private ApexChartOptions<RTD8TMPointModel> chartOptions;
protected override void OnInitialized()
@ -38,7 +37,7 @@
_RTD8TMService.EventUpdateGraph += UpdateChart;
chartOptions = new ApexChartOptions<RTD8TMGraphPointModel>
chartOptions = new ApexChartOptions<RTD8TMPointModel>
{
Theme = new Theme
{

View File

@ -1,12 +1,29 @@
@inherits LayoutComponentBase
@using UI_SequentMicrosystems.Components
@inherits LayoutComponentBase
<div class="page maincolor">
<div>
<NavMenu />
</div>
<main>
<MainLayoutPointsTopBar />
<article class="content px-4">
@Body
</article>
</main>
</div>
@code{
}

View File

@ -20,8 +20,8 @@
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="weather">
<span class="bi bi-list-nested-nav-menu" aria-hidden="true"></span> Weather
<NavLink class="nav-link" href="Points">
<span class="bi bi-list-nested-nav-menu" aria-hidden="true"></span> Saved Points
</NavLink>
</div>
</nav>

13
Models/PointsModel.cs Normal file
View File

@ -0,0 +1,13 @@
namespace UI_SequentMicrosystems.Models
{
public class PointsModel
{
/// <summary>
/// RTD8TM data holder
/// </summary>
public SortedList<long, SortedList<byte, List<float>>> RTD8TM = new();
}
}

View File

@ -1,6 +1,6 @@
namespace UI_SequentMicrosystems.Models
{
public class RTD8TMGraphPointModel
public class RTD8TMPointModel
{
public float Value { get; set; }
public DateTime Time { get; set; }

40
Pages/PointsPage.razor Normal file
View File

@ -0,0 +1,40 @@
@page "/Points"
@using UI_SequentMicrosystems.Components
@using UI_SequentMicrosystems.Services
@using UI_SequentMicrosystems.Models
<PageTitle>Saved Points</PageTitle>
<PointsTableRTD8TMComponent />
@code {
}

View File

@ -7,12 +7,13 @@
@inject NavigationManager Navigator
@inject RTD8TMService _RTD8TMService
@inject PointsService _PointsService
<PageTitle>Temperature</PageTitle>
<div class="row text-center">
<div class="col">Device Address: @_RTD8TMService.GetAddress() | DataUpdate: @_UpdateCounter | </div>
<div class="col-6">Device Address: @_RTD8TMService.GetAddress() | DataUpdate: @_UpdateCounter | Chart Points: @_RTD8TMService.CountChartData() / @_RTD8TMService.CountFilteredChartData() </div>
<div class="col text-start">
<div class="form-check form-switch">
@if (EditName)
@ -40,6 +41,7 @@
<button class="btn btn-dark text-white no-border" @onclick="(() => _RTD8TMService.ClearValueTypes())">Reset Value Types</button>
</div>
}
</div>
<div class="row">
@ -75,7 +77,8 @@
protected override void OnInitialized()
{
_RTD8TMService.SetAddress("http://10.1.20.5/");//Navigator.BaseUri);
//_RTD8TMService.SetAddress("http://10.250.251.131/");
_RTD8TMService.SetAddress(Navigator.BaseUri);
_RTD8TMService.EventUpdateValues += UpdateView;
}

View File

@ -4,11 +4,11 @@
@inject NavigationManager Navigator
@inject RTD8TMService _RTD8TMService
<PageTitle>Home</PageTitle>
<PageTitle>Welcome</PageTitle>
<h1>TesDevice App V1.0</h1>
<h1>Hello, world!</h1>
Welcome to your new app.
@ -17,7 +17,8 @@ Welcome to your new app.
protected override void OnInitialized()
{
_RTD8TMService.SetAddress("http://10.1.20.5/");// Navigator.BaseUri);
//_RTD8TMService.SetAddress("http://10.250.251.131/");
_RTD8TMService.SetAddress(Navigator.BaseUri);

View File

@ -17,6 +17,7 @@ namespace UI_SequentMicrosystems
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddSingleton<RTD8TMService>();
builder.Services.AddSingleton<PointsService>();
await builder.Build().RunAsync();
}

187
Services/PointsService.cs Normal file
View File

@ -0,0 +1,187 @@
using UI_SequentMicrosystems.Components;
using UI_SequentMicrosystems.Constants;
using UI_SequentMicrosystems.Models;
namespace UI_SequentMicrosystems.Services
{
public class PointsService
{
private RTD8TMService _RTD8TMService { get; set; }
private PointsModel _PointsModel = new();
private int PointsCount = 0;
public PointsService(RTD8TMService RTD8TM)
{
_RTD8TMService = RTD8TM;
}
/// <summary>
/// Save actual data point
/// </summary>
public void SavePoint()
{
long time = DateTime.Now.Ticks;
_PointsModel.RTD8TM.Add(time, new());
PointsCount++;
//Read RTD8TM actual data to point
SortedList<byte, float[]> RTD8TMActual = _RTD8TMService.GetActualData();
foreach (byte stack in RTD8TMActual.Keys)
{
if (!_PointsModel.RTD8TM[time].ContainsKey(stack))
{
_PointsModel.RTD8TM[time].Add(stack, new());
}
for (byte chanel = 0; chanel < 8; chanel++)
{
_PointsModel.RTD8TM[time][stack].Add(RTD8TMActual[stack][chanel]);
}
}
//other card types points saving
}
/// <summary>
/// Read points
/// </summary>
/// <returns></returns>
public PointsModel GetPoints()
{
return _PointsModel;
}
/// <summary>
/// Get points Count
/// </summary>
/// <returns></returns>
public int GetPointsCount()
{
return PointsCount;
}
/// <summary>
/// Create Points Lines for CSV File
/// </summary>
/// <returns></returns>
#pragma warning disable CS1998 // V této asynchronní metodě chybí operátory await a spustí se synchronně.
public async Task<string> CreatePointsFileLines(bool recalculate)
#pragma warning restore CS1998 // V této asynchronní metodě chybí operátory await a spustí se synchronně.
{
List<string> Lines = new List<string>();
Lines.Add(CreateTitleLine(recalculate));
Lines.AddRange(CreateDataLines(recalculate));
return string.Join(Environment.NewLine, Lines);
}
/// <summary>
/// Create Title Line of CSV File
/// </summary>
/// <returns></returns>
private string CreateTitleLine(bool Recalculate)
{
string Line = "Time";
//RTD8TM
foreach (long time in _PointsModel.RTD8TM.Keys)
{
foreach (byte stack in _RTD8TMService.GetActualData().Keys)
{
for (byte chanel = 0; chanel < 8; chanel++)
{
if (_RTD8TMService.GetChanelName(stack, chanel) != "----------")
{
if (!Line.EndsWith(";"))
Line += ";";
if (Recalculate && _RTD8TMService.GetValueType(stack, chanel) == RTD8TMSensorTypes.PT100)
{
Line += $"{_RTD8TMService.GetChanelName(stack, chanel)} °C";
}
else
{
Line += $"{_RTD8TMService.GetChanelName(stack, chanel)} Ω";
}
}
}
}
break;
}
//other types
return Line;
}
/// <summary>
/// Create Data Lines of CSV File
/// </summary>
/// <returns></returns>
private List<string> CreateDataLines(bool Recalculate)
{
Console.WriteLine("Creting Data Lines");
List<string> Lines = new();
//RTD8TM
foreach (long time in _PointsModel.RTD8TM.Keys)
{
Console.WriteLine($"DataLine Time: {new DateTime(time).ToString("HH:mm:ss")}");
string Line = new DateTime(time).ToString("HH:mm:ss");
foreach (byte stack in _PointsModel.RTD8TM[time].Keys)
{
Console.WriteLine($"DataLine Stack: {stack}");
for (byte chanel = 0; chanel < 8; chanel++)
{
Console.WriteLine($"DataLine Chanel: {chanel}");
if (_RTD8TMService.GetChanelName(stack, chanel) != "----------")
{
Console.WriteLine($"DataLine No default Name");
if (!Line.EndsWith(";"))
Line += ";";
if (Recalculate)
{
Line += new RTD8TMChanelComponent().RecalculateValues(_PointsModel.RTD8TM[time][stack][chanel], _RTD8TMService.GetValueType(stack, chanel)).ToString();
}
else
{
Line += _PointsModel.RTD8TM[time][stack][chanel].ToString();
}
}
}
}
//Other Types
Lines.Add(Line);
}
return Lines;
}
}
}

View File

@ -1,4 +1,5 @@
using System.Timers;
using System.Threading.Channels;
using System.Timers;
using UI_SequentMicrosystems.Components;
using UI_SequentMicrosystems.Models;
using Wrapper_Api_SequentMicrosystems.RTD8TM;
@ -10,7 +11,8 @@ namespace UI_SequentMicrosystems.Services
private SortedList<byte, string[]> ChanelNames = new SortedList<byte, string[]>();
private SortedList<byte, float[]> ActualValues = new SortedList<byte, float[]>();
private SortedList<byte, byte[]> ValuesType = new SortedList<byte, byte[]>();
public SortedList<byte, List<List<RTD8TMGraphPointModel>>> GraphData = new();
public SortedList<byte, List<List<RTD8TMPointModel>>> GraphData = new();
public SortedList<byte, List<List<RTD8TMPointModel>>> GraphFiltered = new();
private byte GraphDataCounterCount = 10;
private byte GraphDataCounter = 9;
@ -256,23 +258,36 @@ namespace UI_SequentMicrosystems.Services
for (byte chanel = 0; chanel < 8; chanel++)
{
GraphData[stack][chanel].Add(new RTD8TMGraphPointModel() { Value = new RTD8TMChanelComponent().RecalculateValues(ActualValues[stack][chanel], GetValueType(stack, chanel)), Time = time });
GraphData[stack][chanel].Add(new RTD8TMPointModel() { Value = ActualValues[stack][chanel], Time = time });
}
}
GetFilteredChartData();
}
/// <summary>
/// Get data for graph visualize
/// </summary>
/// <returns>saved chart chanel Data</returns>
public List<RTD8TMGraphPointModel> GetChartData(byte StackID, byte Chanel)
public List<RTD8TMPointModel> GetChartData(byte StackID, byte Chanel)
{
if (!GraphData.ContainsKey(StackID))
if (!GraphFiltered.ContainsKey(StackID))
{
return new List<RTD8TMGraphPointModel>();
return new List<RTD8TMPointModel>();
}
return GraphData[StackID][Chanel];
List<RTD8TMPointModel> RecalculatedData = new();
byte chanelRecalcTo = GetValueType(StackID, Chanel);
foreach (RTD8TMPointModel point in GraphFiltered[StackID][Chanel])
{
RTD8TMPointModel recalculated = new() { Time = point.Time, Value = new RTD8TMChanelComponent().RecalculateValues(point.Value, chanelRecalcTo) };
RecalculatedData.Add(recalculated);
}
return RecalculatedData;
}
/// <summary>
@ -283,7 +298,128 @@ namespace UI_SequentMicrosystems.Services
GraphData.Clear();
}
private void GetFilteredChartData()
{
foreach ( byte stack in GraphData.Keys)
{
int pointsCount = GraphData[stack][0].Count;
int counter = 0;
if (pointsCount < 100)
{
GraphFiltered = GraphData;
}
else if (pointsCount > 100 && pointsCount < 500) // one from five
{
GraphFiltered = new();
GraphFiltered.Add(stack, new());
for (int chanel = 0; chanel < 8; chanel++)
{
GraphFiltered[stack].Add(new());
foreach (RTD8TMPointModel GraphPoint in GraphData[stack][chanel])
{
if (counter > 3)
{
GraphFiltered[stack][chanel].Add(GraphPoint);
counter = 0;
}
else
{
counter++;
}
}
}
}
else if (pointsCount > 500 && pointsCount < 1000) // one from ten
{
GraphFiltered = new();
GraphFiltered.Add(stack, new());
for (int chanel = 0; chanel < 8; chanel++)
{
GraphFiltered[stack].Add(new());
foreach (RTD8TMPointModel GraphPoint in GraphData[stack][chanel])
{
if (counter > 8)
{
GraphFiltered[stack][chanel].Add(GraphPoint);
counter = 0;
}
else
{
counter++;
}
}
}
}
else if (pointsCount > 1000 && pointsCount < 1500) // one from fifteen
{
GraphFiltered = new();
GraphFiltered.Add(stack, new());
for (int chanel = 0; chanel < 8; chanel++)
{
GraphFiltered[stack].Add(new());
foreach (RTD8TMPointModel GraphPoint in GraphData[stack][chanel])
{
if (counter > 13)
{
GraphFiltered[stack][chanel].Add(GraphPoint);
counter = 0;
}
else
{
counter++;
}
}
}
}
else if (pointsCount > 1500) // one from twenty
{
GraphFiltered = new();
GraphFiltered.Add(stack, new());
for (int chanel = 0; chanel < 8; chanel++)
{
GraphFiltered[stack].Add(new());
foreach (RTD8TMPointModel GraphPoint in GraphData[stack][chanel])
{
if (counter > 18)
{
GraphFiltered[stack][chanel].Add(GraphPoint);
counter = 0;
}
else
{
counter++;
}
}
}
}
//případně další
}
}
public int CountFilteredChartData()
{
foreach (byte stack in GraphFiltered.Keys)
{
return GraphFiltered[stack][0].Count;
}
return 0;
}
public int CountChartData()
{
foreach (byte stack in GraphData.Keys)
{
return GraphData[stack][0].Count;
}
return 0;
}
//Values Types

14
wwwroot/DownloadFile.js Normal file
View File

@ -0,0 +1,14 @@
window.DownloadFile = function (fileName, content) {
const blob = new Blob([content], { type: "text/plain;charset=utf-8" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = fileName;
document.body.appendChild(a);
a.click();
// Po stisknutí tlačítka, odstraníme element a URL objekt
document.body.removeChild(a);
URL.revokeObjectURL(url);
};

View File

@ -33,6 +33,7 @@
</div>
<script src="_framework/blazor.webassembly.js"></script>
<script>navigator.serviceWorker.register('service-worker.js');</script>
<script src="DownloadFile.js"></script>
</body>
</html>