Force crack calculator was fixed
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Infrastructures.Interfaces
|
||||
{
|
||||
public interface ICheckEntityLogic<TEntity> : ICheckLogic
|
||||
{
|
||||
TEntity Entity { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,19 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Infrastructures.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Logic for checking entities
|
||||
/// </summary>
|
||||
public interface ICheckLogic : ILogic
|
||||
{
|
||||
/// <summary>
|
||||
/// Text result of checking
|
||||
/// </summary>
|
||||
string CheckResult { get; }
|
||||
/// <summary>
|
||||
/// Start checking process
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
bool Check();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Calculators
|
||||
{
|
||||
public class CheckAccuracyLogic : ICheckEntityLogic<IAccuracy>
|
||||
{
|
||||
private string checkResult;
|
||||
private bool result;
|
||||
|
||||
public IAccuracy Entity { get; set; }
|
||||
|
||||
public string CheckResult => checkResult;
|
||||
|
||||
public IShiftTraceLogger? TraceLogger { get; set; }
|
||||
|
||||
public CheckAccuracyLogic(IShiftTraceLogger traceLogger)
|
||||
{
|
||||
TraceLogger = traceLogger;
|
||||
}
|
||||
|
||||
public CheckAccuracyLogic() : this (null)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public bool Check()
|
||||
{
|
||||
result = true;
|
||||
if (Entity is null)
|
||||
{
|
||||
result = false;
|
||||
string errorString = "\nAccuracy requirements is not assigned";
|
||||
TraceMessage(errorString);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Entity.IterationAccuracy <= 0)
|
||||
{
|
||||
result = false;
|
||||
TraceMessage($"\nValue of accuracy {Entity.IterationAccuracy} must be grater than zero");
|
||||
}
|
||||
if (Entity.MaxIterationCount <= 0)
|
||||
{
|
||||
result = false;
|
||||
TraceMessage($"\nMax number of iteration {Entity.MaxIterationCount} must be grater than zero");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void TraceMessage(string errorString)
|
||||
{
|
||||
checkResult += errorString;
|
||||
TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,14 +10,12 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Calculators
|
||||
{
|
||||
public class FindParameterCalculator : ICalculator, IHasActionByResult
|
||||
public class FindParameterCalculator : IFindParameterCalculator
|
||||
{
|
||||
FindParameterResult result;
|
||||
public string Name { get; set; }
|
||||
public double StartValue { get; set; }
|
||||
public double EndValue { get; set; }
|
||||
public Predicate<double> Predicate { get; set; }
|
||||
public IAccuracy Accuracy {get;set;}
|
||||
public IFindParameterCalculatorInputData InputData { get; set; }
|
||||
public IAccuracy Accuracy { get; set; }
|
||||
public IResult Result => result;
|
||||
|
||||
public Action<IResult> ActionToOutputResults { get; set; }
|
||||
@@ -25,18 +23,21 @@ namespace StructureHelperCommon.Models.Calculators
|
||||
|
||||
public FindParameterCalculator()
|
||||
{
|
||||
StartValue = 0d;
|
||||
EndValue = 1d;
|
||||
Accuracy = new Accuracy() { IterationAccuracy = 0.001d, MaxIterationCount = 1000 };
|
||||
InputData = new FindParameterCalculatorInputData();
|
||||
Accuracy = new Accuracy()
|
||||
{
|
||||
IterationAccuracy = 0.001d,
|
||||
MaxIterationCount = 1000
|
||||
};
|
||||
}
|
||||
public void Run()
|
||||
{
|
||||
result = new();
|
||||
try
|
||||
{
|
||||
FindMinimumValue(StartValue, EndValue, Predicate);
|
||||
FindMinimumValue(InputData.StartValue, InputData.EndValue, InputData.Predicate);
|
||||
}
|
||||
catch(Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.IsValid = false;
|
||||
result.Description += ex;
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Calculators
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public class FindParameterCalculatorInputData : IFindParameterCalculatorInputData
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public double StartValue { get; set; }
|
||||
/// <inheritdoc/>
|
||||
public double EndValue { get; set; }
|
||||
/// <inheritdoc/>
|
||||
public Predicate<double> Predicate { get; set; }
|
||||
public FindParameterCalculatorInputData()
|
||||
{
|
||||
StartValue = 0d;
|
||||
EndValue = 1d;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace StructureHelperCommon.Models.Calculators
|
||||
{
|
||||
public interface IFindParameterCalculator : ICalculator, IHasActionByResult
|
||||
{
|
||||
IAccuracy Accuracy { get; set; }
|
||||
IFindParameterCalculatorInputData InputData { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
|
||||
namespace StructureHelperCommon.Models.Calculators
|
||||
{
|
||||
/// <summary>
|
||||
/// Input data for calculators of finding parameters
|
||||
/// </summary>
|
||||
public interface IFindParameterCalculatorInputData : IInputData
|
||||
{
|
||||
/// <summary>
|
||||
/// Start value of range where parameter looking for
|
||||
/// </summary>
|
||||
double StartValue { get; set; }
|
||||
/// <summary>
|
||||
/// End value of range where parameter looking for
|
||||
/// </summary>
|
||||
double EndValue { get; set; }
|
||||
/// <summary>
|
||||
/// Predicate for checking parameter for true;
|
||||
/// </summary>
|
||||
Predicate<double> Predicate { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,8 @@ namespace StructureHelperCommon.Models
|
||||
public interface ITraceLogger
|
||||
{
|
||||
List<ITraceLoggerEntry> TraceLoggerEntries { get; }
|
||||
void AddMessage(string message, TraceLogStatuses status = TraceLogStatuses.Info, int shiftPriority = 0);
|
||||
void AddMessage(string message, TraceLogStatuses status, int shiftPriority = 0);
|
||||
void AddMessage(string message);
|
||||
void AddMessage(string message, int priority);
|
||||
bool KeepErrorStatus { get; set; }
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace StructureHelperCommon.Models
|
||||
KeepErrorStatus = true;
|
||||
}
|
||||
public ShiftTraceLogger() : this(new TraceLogger()) { }
|
||||
public void AddMessage(string message, TraceLogStatuses status = TraceLogStatuses.Info, int shiftPrioriry = 0)
|
||||
public void AddMessage(string message, TraceLogStatuses status, int shiftPrioriry = 0)
|
||||
{
|
||||
// if status in (fatal, error, warning) they must be kept as they are
|
||||
if (status <= TraceLogStatuses.Warning & KeepErrorStatus == true)
|
||||
@@ -57,5 +57,10 @@ namespace StructureHelperCommon.Models
|
||||
}
|
||||
Logger.TraceLoggerEntries.Add(loggerEntry);
|
||||
}
|
||||
|
||||
public void AddMessage(string message)
|
||||
{
|
||||
AddMessage(message, TraceLogStatuses.Info,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace StructureHelperCommon.Models
|
||||
KeepErrorStatus = true;
|
||||
}
|
||||
|
||||
public void AddMessage(string message, TraceLogStatuses status = TraceLogStatuses.Info, int shiftPrioriry = 0)
|
||||
public void AddMessage(string message, TraceLogStatuses status, int shiftPrioriry = 0)
|
||||
{
|
||||
if (status == TraceLogStatuses.Fatal) { message = $"Fatal error! {message}"; }
|
||||
if (status == TraceLogStatuses.Error) { message = $"Error! {message}"; }
|
||||
@@ -38,5 +38,10 @@ namespace StructureHelperCommon.Models
|
||||
Priority = priority
|
||||
});
|
||||
}
|
||||
|
||||
public void AddMessage(string message)
|
||||
{
|
||||
AddMessage(message, TraceLogStatuses.Info,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user