diff --git a/Components/MainLayoutPointsTopBar.razor b/Components/MainLayoutPointsTopBar.razor new file mode 100644 index 0000000..3dd781b --- /dev/null +++ b/Components/MainLayoutPointsTopBar.razor @@ -0,0 +1,65 @@ +@using UI_SequentMicrosystems.Services + +@inject PointsService _PointsService +@inject IJSRuntime _JSRuntime + + + +
+
+ +
+ +
+
+ +
+ +
+
+ @if (RecalculateValues) + { + + } + else + { + + } + +
+
+
+
+ + + + + + + + + + +@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)); + } + + + + + + + +} diff --git a/Components/PointsTableRTD8TMComponent.razor b/Components/PointsTableRTD8TMComponent.razor new file mode 100644 index 0000000..650165b --- /dev/null +++ b/Components/PointsTableRTD8TMComponent.razor @@ -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 + + + + + + + + + + @foreach (byte stack in _RTD8TMService.GetActualData().Keys) + { + for (byte chanel = 0; chanel < 8; chanel++) + { + if (_RTD8TMService.GetChanelName(stack, chanel) != "----------") + { + + } + } + } + + + + @foreach (long time in TableData.Keys) + { + + + + @foreach (byte stack in TableData[time].Keys) + { + for (byte chanel = 0; chanel < 8; chanel++) + { + if (_RTD8TMService.GetChanelName(stack, chanel) != "----------") + { + + } + } + } + + } + +
Time + @_RTD8TMService.GetChanelName(stack, chanel) + + @if (_RTD8TMService.GetValueType(stack, chanel) == RTD8TMSensorTypes.PT100) + { + @Celsius + } + else + { + @Ohm + } +
@(new DateTime(time).ToString("HH:mm:ss"))@(new RTD8TMChanelComponent().RecalculateValues(TableData[time][stack][chanel], _RTD8TMService.GetValueType(stack, chanel)))
+ + + +@code { + private SortedList>> 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"; + } + } + + + + + + + + + + + +} diff --git a/Components/RTD8TMGraphComponent.razor b/Components/RTD8TMGraphComponent.razor index 87368cb..5943618 100644 --- a/Components/RTD8TMGraphComponent.razor +++ b/Components/RTD8TMGraphComponent.razor @@ -4,8 +4,7 @@ @using UI_SequentMicrosystems.Models @inject RTD8TMService _RTD8TMService - - @@ -16,7 +15,7 @@ { if (_RTD8TMService.GetChanelName(stack, chanel) != "----------") { - @code { - private ApexChart chart; - private ApexChartOptions chartOptions; + private ApexChart chart; + private ApexChartOptions chartOptions; protected override void OnInitialized() @@ -38,7 +37,7 @@ _RTD8TMService.EventUpdateGraph += UpdateChart; - chartOptions = new ApexChartOptions + chartOptions = new ApexChartOptions { Theme = new Theme { diff --git a/Layout/MainLayout.razor b/Layout/MainLayout.razor index b9eef2f..8095b90 100644 --- a/Layout/MainLayout.razor +++ b/Layout/MainLayout.razor @@ -1,12 +1,29 @@ -@inherits LayoutComponentBase +@using UI_SequentMicrosystems.Components + +@inherits LayoutComponentBase +
+ +
@Body
+ + +@code{ + + + + + + + + +} \ No newline at end of file diff --git a/Layout/NavMenu.razor b/Layout/NavMenu.razor index 716cc77..8bf5a5b 100644 --- a/Layout/NavMenu.razor +++ b/Layout/NavMenu.razor @@ -20,8 +20,8 @@ diff --git a/Models/PointsModel.cs b/Models/PointsModel.cs new file mode 100644 index 0000000..3ca7e8b --- /dev/null +++ b/Models/PointsModel.cs @@ -0,0 +1,13 @@ +namespace UI_SequentMicrosystems.Models +{ + public class PointsModel + { + /// + /// RTD8TM data holder + /// + public SortedList>> RTD8TM = new(); + + + + } +} diff --git a/Models/RTD8TMGraphPointModel.cs b/Models/RTD8TMPointModel.cs similarity index 78% rename from Models/RTD8TMGraphPointModel.cs rename to Models/RTD8TMPointModel.cs index 68f9022..295e88b 100644 --- a/Models/RTD8TMGraphPointModel.cs +++ b/Models/RTD8TMPointModel.cs @@ -1,6 +1,6 @@ namespace UI_SequentMicrosystems.Models { - public class RTD8TMGraphPointModel + public class RTD8TMPointModel { public float Value { get; set; } public DateTime Time { get; set; } diff --git a/Pages/PointsPage.razor b/Pages/PointsPage.razor new file mode 100644 index 0000000..f6ee40d --- /dev/null +++ b/Pages/PointsPage.razor @@ -0,0 +1,40 @@ +@page "/Points" + +@using UI_SequentMicrosystems.Components +@using UI_SequentMicrosystems.Services +@using UI_SequentMicrosystems.Models + + +Saved Points + + + + + + + + + + + + +@code { + + + + + + + + + + + + + + + + + + +} diff --git a/Pages/RTD8TMPage.razor b/Pages/RTD8TMPage.razor index 1d5d82d..c83c1ef 100644 --- a/Pages/RTD8TMPage.razor +++ b/Pages/RTD8TMPage.razor @@ -7,12 +7,13 @@ @inject NavigationManager Navigator @inject RTD8TMService _RTD8TMService +@inject PointsService _PointsService Temperature
-
Device Address: @_RTD8TMService.GetAddress() | DataUpdate: @_UpdateCounter |
+
Device Address: @_RTD8TMService.GetAddress() | DataUpdate: @_UpdateCounter | Chart Points: @_RTD8TMService.CountChartData() / @_RTD8TMService.CountFilteredChartData()
@if (EditName) @@ -40,6 +41,7 @@
} +
@@ -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; } diff --git a/Pages/Start.razor b/Pages/Start.razor index fc2f45e..bf1512b 100644 --- a/Pages/Start.razor +++ b/Pages/Start.razor @@ -4,11 +4,11 @@ @inject NavigationManager Navigator @inject RTD8TMService _RTD8TMService -Home +Welcome + +

TesDevice App V1.0

-

Hello, world!

-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); diff --git a/Program.cs b/Program.cs index 40445fa..0b4a6c2 100644 --- a/Program.cs +++ b/Program.cs @@ -17,6 +17,7 @@ namespace UI_SequentMicrosystems builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); builder.Services.AddSingleton(); + builder.Services.AddSingleton(); await builder.Build().RunAsync(); } diff --git a/Services/PointsService.cs b/Services/PointsService.cs new file mode 100644 index 0000000..836ba5f --- /dev/null +++ b/Services/PointsService.cs @@ -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; + } + + + /// + /// Save actual data point + /// + public void SavePoint() + { + long time = DateTime.Now.Ticks; + _PointsModel.RTD8TM.Add(time, new()); + PointsCount++; + + //Read RTD8TM actual data to point + SortedList 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 + + } + + /// + /// Read points + /// + /// + public PointsModel GetPoints() + { + return _PointsModel; + } + + /// + /// Get points Count + /// + /// + public int GetPointsCount() + { + return PointsCount; + } + + + /// + /// Create Points Lines for CSV File + /// + /// + #pragma warning disable CS1998 // V této asynchronní metodě chybí operátory await a spustí se synchronně. + public async Task CreatePointsFileLines(bool recalculate) + #pragma warning restore CS1998 // V této asynchronní metodě chybí operátory await a spustí se synchronně. + { + List Lines = new List(); + + Lines.Add(CreateTitleLine(recalculate)); + + Lines.AddRange(CreateDataLines(recalculate)); + + return string.Join(Environment.NewLine, Lines); + } + + + /// + /// Create Title Line of CSV File + /// + /// + 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; + } + + /// + /// Create Data Lines of CSV File + /// + /// + private List CreateDataLines(bool Recalculate) + { + Console.WriteLine("Creting Data Lines"); + + List 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; + } + + + + + + + + } +} diff --git a/Services/RTD8TMService.cs b/Services/RTD8TMService.cs index f6d7f35..6a7c266 100644 --- a/Services/RTD8TMService.cs +++ b/Services/RTD8TMService.cs @@ -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 ChanelNames = new SortedList(); private SortedList ActualValues = new SortedList(); private SortedList ValuesType = new SortedList(); - public SortedList>> GraphData = new(); + public SortedList>> GraphData = new(); + public SortedList>> 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(); } /// /// Get data for graph visualize /// /// saved chart chanel Data - public List GetChartData(byte StackID, byte Chanel) + public List GetChartData(byte StackID, byte Chanel) { - if (!GraphData.ContainsKey(StackID)) + if (!GraphFiltered.ContainsKey(StackID)) { - return new List(); + return new List(); } - return GraphData[StackID][Chanel]; + List 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; } /// @@ -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 diff --git a/wwwroot/DownloadFile.js b/wwwroot/DownloadFile.js new file mode 100644 index 0000000..a6472e0 --- /dev/null +++ b/wwwroot/DownloadFile.js @@ -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); +}; \ No newline at end of file diff --git a/wwwroot/index.html b/wwwroot/index.html index 0c3620c..c6de9fa 100644 --- a/wwwroot/index.html +++ b/wwwroot/index.html @@ -33,6 +33,7 @@
+