Table log Entry was added
This commit is contained in:
@@ -20,7 +20,7 @@ namespace StructureHelperCommon.Models.Calculators
|
||||
public IResult Result => result;
|
||||
|
||||
public Action<IResult> ActionToOutputResults { get; set; }
|
||||
public ITraceLogger? TraceLogger { get; set; }
|
||||
public IShiftTraceLogger? TraceLogger { get; set; }
|
||||
|
||||
public FindParameterCalculator()
|
||||
{
|
||||
@@ -48,10 +48,11 @@ namespace StructureHelperCommon.Models.Calculators
|
||||
|
||||
private void FindMinimumValue(double start, double end, Predicate<double> predicate)
|
||||
{
|
||||
TraceLogger?.AddMessage($"Calculating parameter by iterations is started,\nrequired precision {Accuracy.IterationAccuracy}");
|
||||
if (predicate(end) == false)
|
||||
{
|
||||
TraceLogger?.AddMessage($"Predicate for end value must be true", TraceLoggerStatuses.Error);
|
||||
throw new StructureHelperException(ErrorStrings.DataIsInCorrect + ": predicate for end value must be true");
|
||||
|
||||
}
|
||||
double precision = Accuracy.IterationAccuracy;
|
||||
int maxIterationCount = Accuracy.MaxIterationCount;
|
||||
@@ -60,18 +61,21 @@ namespace StructureHelperCommon.Models.Calculators
|
||||
int iterationNum = 0;
|
||||
while (step > precision)
|
||||
{
|
||||
TraceLogger?.AddMessage($"Iteration number {iterationNum}", TraceLoggerStatuses.Debug);
|
||||
TraceLogger?.AddMessage($"Iteration number {iterationNum} is started", TraceLoggerStatuses.Debug);
|
||||
if (predicate(current) == true)
|
||||
{
|
||||
TraceLogger?.AddMessage($"Predicate value in {current} is true", TraceLoggerStatuses.Debug, 50);
|
||||
end = current;
|
||||
}
|
||||
else
|
||||
{
|
||||
TraceLogger?.AddMessage($"Predicate value in {current} is false", TraceLoggerStatuses.Debug, 50);
|
||||
start = current;
|
||||
}
|
||||
current = (start + end) / 2;
|
||||
TraceLogger?.AddMessage($"Current value {current}", TraceLoggerStatuses.Debug);
|
||||
step = (end - start) / 2;
|
||||
TraceLogger?.AddMessage($"New current value Cur=({start}+{end})/2={current}", TraceLoggerStatuses.Debug);
|
||||
current = (start + end) / 2d;
|
||||
step = (end - start) / 2d;
|
||||
TraceLogger?.AddMessage($"New step S={current}", TraceLoggerStatuses.Debug, 50);
|
||||
iterationNum++;
|
||||
|
||||
result.IsValid = false;
|
||||
@@ -86,7 +90,7 @@ namespace StructureHelperCommon.Models.Calculators
|
||||
throw new StructureHelperException(ErrorStrings.DataIsInCorrect + ": violation of iteration count");
|
||||
}
|
||||
}
|
||||
TraceLogger?.AddMessage($"Parameter value {current} was obtained");
|
||||
TraceLogger?.AddMessage($"Parameter value Cur={current} was found,\nCalculation has finished succefully");
|
||||
result.Parameter = current;
|
||||
result.Description = "Parameter was found succefully";
|
||||
result.IsValid = true;
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace StructureHelperCommon.Models.Calculators
|
||||
{
|
||||
public interface ICalculator : ICloneable
|
||||
{
|
||||
ITraceLogger? TraceLogger { get; set; }
|
||||
IShiftTraceLogger? TraceLogger { get; set; }
|
||||
string Name { get; set; }
|
||||
/// <summary>
|
||||
/// Method for calculating
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
using StructureHelperCommon.Models.Tables;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Loggers
|
||||
{
|
||||
public static class TraceLoggerTableByPointsFactory
|
||||
{
|
||||
public static TableLoggerEntry GetTableByPoint2D(IPoint2D point2D)
|
||||
{
|
||||
var table = new TableLoggerEntry(2);
|
||||
table.Table.AddRow(GetHeaderRow());
|
||||
table.Table.AddRow(GetPointRow(point2D));
|
||||
return table;
|
||||
}
|
||||
public static TableLoggerEntry GetTableByPoint2D(IEnumerable<IPoint2D> points)
|
||||
{
|
||||
var table = new TableLoggerEntry(2);
|
||||
table.Table.AddRow(GetHeaderRow());
|
||||
foreach (var item in points)
|
||||
{
|
||||
table.Table.AddRow(GetPointRow(item));
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
||||
private static ShTableRow<ITraceLoggerEntry> GetHeaderRow()
|
||||
{
|
||||
var headerRow = new ShTableRow<ITraceLoggerEntry>(2);
|
||||
headerRow.Elements[0] = new StringLoggerEntry()
|
||||
{
|
||||
Message = "X",
|
||||
Priority = LoggerService.GetPriorityByStatus(TraceLoggerStatuses.Info)
|
||||
};
|
||||
headerRow.Elements[1] = new StringLoggerEntry()
|
||||
{
|
||||
Message = "Y",
|
||||
Priority = LoggerService.GetPriorityByStatus(TraceLoggerStatuses.Info)
|
||||
};
|
||||
return headerRow;
|
||||
}
|
||||
private static ShTableRow<ITraceLoggerEntry> GetPointRow(IPoint2D point2D)
|
||||
{
|
||||
var pointRow = new ShTableRow<ITraceLoggerEntry>(2);
|
||||
pointRow.Elements[0] = new StringLoggerEntry()
|
||||
{
|
||||
Message = Convert.ToString(point2D.X),
|
||||
Priority = LoggerService.GetPriorityByStatus(TraceLoggerStatuses.Info)
|
||||
};
|
||||
pointRow.Elements[1] = new StringLoggerEntry()
|
||||
{
|
||||
Message = Convert.ToString(point2D.Y),
|
||||
Priority = LoggerService.GetPriorityByStatus(TraceLoggerStatuses.Info)
|
||||
};
|
||||
return pointRow;
|
||||
}
|
||||
}
|
||||
}
|
||||
16
StructureHelperCommon/Models/Loggers/IShiftTraceLogger.cs
Normal file
16
StructureHelperCommon/Models/Loggers/IShiftTraceLogger.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Loggers
|
||||
{
|
||||
public interface IShiftTraceLogger : ITraceLogger
|
||||
{
|
||||
ITraceLogger Logger { get; set; }
|
||||
int ShiftPriority { get; set; }
|
||||
void AddEntry(ITraceLoggerEntry loggerEntry);
|
||||
IShiftTraceLogger GetSimilarTraceLogger(int shftPriority = 0);
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ namespace StructureHelperCommon.Models.Loggers
|
||||
public interface ITraceLogger
|
||||
{
|
||||
List<ITraceLoggerEntry> TraceLoggerEntries { get; }
|
||||
void AddMessage(string message, TraceLoggerStatuses status = TraceLoggerStatuses.Info);
|
||||
void AddMessage(string message, TraceLoggerStatuses status = TraceLoggerStatuses.Info, int shiftPriority = 0);
|
||||
void AddMessage(string message, int priority);
|
||||
}
|
||||
}
|
||||
|
||||
33
StructureHelperCommon/Models/Loggers/LoggerService.cs
Normal file
33
StructureHelperCommon/Models/Loggers/LoggerService.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Loggers
|
||||
{
|
||||
public static class LoggerService
|
||||
{
|
||||
const int fatal = 0;
|
||||
const int error = 100;
|
||||
const int warning = 200;
|
||||
const int info = 300;
|
||||
const int service = 400;
|
||||
const int debug = 500;
|
||||
public static int GetPriorityByStatus(TraceLoggerStatuses status)
|
||||
{
|
||||
if (status == TraceLoggerStatuses.Fatal) { return fatal; }
|
||||
else if (status == TraceLoggerStatuses.Error) { return error; }
|
||||
else if (status == TraceLoggerStatuses.Warning) { return warning; }
|
||||
else if (status == TraceLoggerStatuses.Info) { return info; }
|
||||
else if (status == TraceLoggerStatuses.Service) { return service; }
|
||||
else if (status == TraceLoggerStatuses.Debug) { return debug; }
|
||||
else
|
||||
{
|
||||
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(status));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
55
StructureHelperCommon/Models/Loggers/ShiftTraceLogger.cs
Normal file
55
StructureHelperCommon/Models/Loggers/ShiftTraceLogger.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Loggers
|
||||
{
|
||||
public class ShiftTraceLogger : IShiftTraceLogger
|
||||
{
|
||||
public ITraceLogger Logger { get; set; }
|
||||
public int ShiftPriority { get; set; }
|
||||
|
||||
public List<ITraceLoggerEntry> TraceLoggerEntries => Logger.TraceLoggerEntries;
|
||||
public ShiftTraceLogger(ITraceLogger logger)
|
||||
{
|
||||
Logger = logger;
|
||||
}
|
||||
public ShiftTraceLogger() : this(new TraceLogger()) { }
|
||||
public void AddMessage(string message, TraceLoggerStatuses status = TraceLoggerStatuses.Info, int shiftPrioriry = 0)
|
||||
{
|
||||
// if status in (fatal, error, warning) they must be kept as they are
|
||||
if (status <= TraceLoggerStatuses.Warning)
|
||||
{
|
||||
Logger.AddMessage(message, status);
|
||||
}
|
||||
else
|
||||
{
|
||||
var priority = LoggerService.GetPriorityByStatus(status) + shiftPrioriry;
|
||||
this.AddMessage(message, priority);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddMessage(string message, int priority)
|
||||
{
|
||||
priority += ShiftPriority;
|
||||
Logger.AddMessage(message, priority);
|
||||
}
|
||||
|
||||
public IShiftTraceLogger GetSimilarTraceLogger(int shiftPriority = 0)
|
||||
{
|
||||
var newLogger = new ShiftTraceLogger(Logger)
|
||||
{
|
||||
ShiftPriority = shiftPriority
|
||||
};
|
||||
return newLogger;
|
||||
}
|
||||
|
||||
public void AddEntry(ITraceLoggerEntry loggerEntry)
|
||||
{
|
||||
loggerEntry.Priority += ShiftPriority;
|
||||
Logger.TraceLoggerEntries.Add(loggerEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
27
StructureHelperCommon/Models/Loggers/TableLoggerEntry.cs
Normal file
27
StructureHelperCommon/Models/Loggers/TableLoggerEntry.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using StructureHelperCommon.Models.Tables;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Loggers
|
||||
{
|
||||
public class TableLoggerEntry : ITraceLoggerEntry
|
||||
{
|
||||
private ListTable<ITraceLoggerEntry> table;
|
||||
public ListTable<ITraceLoggerEntry> Table {get => table;}
|
||||
public DateTime TimeStamp { get; }
|
||||
|
||||
public int Priority { get; set; }
|
||||
public TableLoggerEntry(int rowSize)
|
||||
{
|
||||
if (rowSize <= 0)
|
||||
{
|
||||
throw new ArgumentException("Row size must be greater than 0.", nameof(rowSize));
|
||||
}
|
||||
table = new(rowSize);
|
||||
TimeStamp = DateTime.Now;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,18 +4,12 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace StructureHelperCommon.Models.Loggers
|
||||
{
|
||||
public class TraceLogger : ITraceLogger
|
||||
{
|
||||
const int fatal = 0;
|
||||
const int error = 1000;
|
||||
const int warning = 200;
|
||||
const int info = 300;
|
||||
const int service = 400;
|
||||
const int debug = 500;
|
||||
|
||||
{
|
||||
public List<ITraceLoggerEntry> TraceLoggerEntries { get; }
|
||||
|
||||
public TraceLogger()
|
||||
@@ -23,12 +17,15 @@ namespace StructureHelperCommon.Models.Loggers
|
||||
TraceLoggerEntries = new();
|
||||
}
|
||||
|
||||
public void AddMessage(string message, TraceLoggerStatuses status = TraceLoggerStatuses.Info)
|
||||
public void AddMessage(string message, TraceLoggerStatuses status = TraceLoggerStatuses.Info, int shiftPrioriry = 0)
|
||||
{
|
||||
if (status == TraceLoggerStatuses.Fatal) { message = $"Fatal error! {message}"; }
|
||||
if (status == TraceLoggerStatuses.Error) { message = $"Error! {message}"; }
|
||||
if (status == TraceLoggerStatuses.Warning) { message = $"Warning! {message}"; }
|
||||
TraceLoggerEntries.Add(new StringLoggerEntry()
|
||||
{
|
||||
Message = message,
|
||||
Priority = GetPriorityByStatus(status)
|
||||
Priority = LoggerService.GetPriorityByStatus(status)
|
||||
});
|
||||
}
|
||||
public void AddMessage(string message, int priority)
|
||||
@@ -39,19 +36,5 @@ namespace StructureHelperCommon.Models.Loggers
|
||||
Priority = priority
|
||||
});
|
||||
}
|
||||
|
||||
public static int GetPriorityByStatus(TraceLoggerStatuses status)
|
||||
{
|
||||
if (status == TraceLoggerStatuses.Fatal) { return fatal; }
|
||||
else if (status == TraceLoggerStatuses.Error) { return error; }
|
||||
else if (status == TraceLoggerStatuses.Warning) { return warning; }
|
||||
else if (status == TraceLoggerStatuses.Info) { return info; }
|
||||
else if (status == TraceLoggerStatuses.Service) { return service; }
|
||||
else if (status == TraceLoggerStatuses.Debug) { return debug; }
|
||||
else
|
||||
{
|
||||
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(status));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace StructureHelperCommon.Models.Soils
|
||||
public IResult Result => result;
|
||||
|
||||
public Action<IResult> ActionToOutputResults { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public ITraceLogger? TraceLogger { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public IShiftTraceLogger? TraceLogger { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
|
||||
public AnchorCalculator(SoilAnchor soilAnchor, IAnchorSoilProperties anchorSoilProperties)
|
||||
{
|
||||
|
||||
10
StructureHelperCommon/Models/Tables/IShTableRow.cs
Normal file
10
StructureHelperCommon/Models/Tables/IShTableRow.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace StructureHelperCommon.Models.Tables
|
||||
{
|
||||
public interface IShTableRow<T>
|
||||
{
|
||||
List<T> Elements { get; }
|
||||
int RowSize { get; }
|
||||
}
|
||||
}
|
||||
77
StructureHelperCommon/Models/Tables/ListTable.cs
Normal file
77
StructureHelperCommon/Models/Tables/ListTable.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Tables
|
||||
{
|
||||
public class ListTable<T>
|
||||
{
|
||||
private List<IShTableRow<T>> table;
|
||||
|
||||
public int RowSize { get; }
|
||||
|
||||
public ListTable(int rowSize)
|
||||
{
|
||||
if (rowSize <= 0)
|
||||
{
|
||||
throw new ArgumentException("Row size must be greater than 0.", nameof(rowSize));
|
||||
}
|
||||
|
||||
RowSize = rowSize;
|
||||
table = new List<IShTableRow<T>>();
|
||||
}
|
||||
|
||||
// Add a new row to the table
|
||||
public void AddRow(IShTableRow<T> tableRow)
|
||||
{
|
||||
table.Add(tableRow);
|
||||
}
|
||||
public void AddRow()
|
||||
{
|
||||
table.Add(new ShTableRow<T>(RowSize));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all rows in the table
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<IShTableRow<T>> GetAllRows()
|
||||
{
|
||||
return table;
|
||||
}
|
||||
|
||||
public List<T> GetElementsFromRow(int rowIndex)
|
||||
{
|
||||
if (rowIndex >= 0 && rowIndex < table.Count)
|
||||
{
|
||||
return table[rowIndex].Elements;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IndexOutOfRangeException("Row index is out of range.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set a value at the specified column and row index
|
||||
/// </summary>
|
||||
/// <param name="columnIndex"></param>
|
||||
/// <param name="rowIndex"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <exception cref="IndexOutOfRangeException"></exception>
|
||||
public void SetValue(int columnIndex, int rowIndex, T value)
|
||||
{
|
||||
if (columnIndex >= 0 && columnIndex < RowSize &&
|
||||
rowIndex >= 0 && rowIndex < table.Count)
|
||||
{
|
||||
table[rowIndex].Elements[columnIndex] = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IndexOutOfRangeException("Column or row index is out of range.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
38
StructureHelperCommon/Models/Tables/ShTableRow.cs
Normal file
38
StructureHelperCommon/Models/Tables/ShTableRow.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Tables
|
||||
{
|
||||
public class ShTableRow<T> : IShTableRow<T>
|
||||
{
|
||||
private List<T> elements;
|
||||
|
||||
public int RowSize { get; }
|
||||
|
||||
public ShTableRow(int rowSize)
|
||||
{
|
||||
if (rowSize <= 0)
|
||||
{
|
||||
throw new ArgumentException("Row size must be greater than 0.", nameof(rowSize));
|
||||
}
|
||||
|
||||
RowSize = rowSize;
|
||||
elements = new List<T>(rowSize);
|
||||
for (int i = 0; i < rowSize; i++)
|
||||
{
|
||||
elements.Add(default);
|
||||
}
|
||||
}
|
||||
|
||||
// Property to access elements in the row
|
||||
public List<T> Elements => elements;
|
||||
|
||||
internal void Add(object value)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user