188 lines
5.5 KiB
C#
188 lines
5.5 KiB
C#
|
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;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|