Add function trace

This commit is contained in:
Иван Ивашкин
2024-12-20 15:24:03 +05:00
parent 7996bd7a3d
commit ceefe3dbca
12 changed files with 80 additions and 40 deletions

View File

@@ -52,5 +52,9 @@ namespace StructureHelperCommon.Infrastructures.Interfaces
{
return function.GetGraphSettings();
}
public virtual string GetTrace()
{
return function.GetTrace();
}
}
}

View File

@@ -30,5 +30,6 @@ namespace StructureHelperCommon.Infrastructures.Interfaces
public bool Check();
public double GetByX(double xValue);
public GraphSettings GetGraphSettings();
public string GetTrace();
}
}

View File

@@ -1,4 +1,5 @@
using LiveCharts;
using FunctionParser;
using LiveCharts;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Services;
using System;
@@ -25,11 +26,15 @@ namespace StructureHelperCommon.Models.Functions.Decorator
}
public override double GetByX(double xValue)
{
double yValue = 0;
if (xValue >= leftBound && xValue <= rightBound)
{
return base.GetByX(xValue);
yValue = base.GetByX(xValue);
}
return 0;
Trace = string.Empty;
Trace += $"Lim X: {Name}, Input: {xValue}, Output: {xValue};\n";
Trace += base.GetTrace();
return yValue;
}
public override GraphSettings GetGraphSettings()
{
@@ -49,5 +54,9 @@ namespace StructureHelperCommon.Models.Functions.Decorator
graphSettings.GraphPoints = graphLimitGraphPoint;
return graphSettings;
}
public override string GetTrace()
{
return Trace;
}
}
}

View File

@@ -25,19 +25,24 @@ namespace StructureHelperCommon.Models.Functions.Decorator
}
public override double GetByX(double xValue)
{
double retValue = 0;
var y = base.GetByX(xValue);
if (y > downBound && y < upBound)
{
return y;
retValue = y;
}
else if (y <= downBound)
{
return downBound;
retValue = downBound;
}
else
{
return upBound;
retValue = upBound;
}
Trace = string.Empty;
Trace += base.GetTrace();
Trace += $"Lim Y: {Name}, Input: {y}, Output: {retValue};\n";
return retValue;
}
public override GraphSettings GetGraphSettings()
{
@@ -65,5 +70,9 @@ namespace StructureHelperCommon.Models.Functions.Decorator
graphSettings.GraphPoints = graphLimitGraphPoint;
return graphSettings;
}
public override string GetTrace()
{
return Trace;
}
}
}

View File

@@ -23,7 +23,12 @@ namespace StructureHelperCommon.Models.Functions.Decorator
}
public override double GetByX(double xValue)
{
return base.GetByX(factor * xValue);
double yValue = base.GetByX(factor * xValue);
Trace = string.Empty;
Trace += $"Scale X: {Name}, Input: {xValue}, Output: {factor * xValue};\n";
Trace += base.GetTrace();
return yValue;
}
public override GraphSettings GetGraphSettings()
{
@@ -34,5 +39,9 @@ namespace StructureHelperCommon.Models.Functions.Decorator
}
return graphSettings;
}
public override string GetTrace()
{
return Trace;
}
}
}

View File

@@ -23,7 +23,13 @@ namespace StructureHelperCommon.Models.Functions.Decorator
}
public override double GetByX(double xValue)
{
return factor * base.GetByX(xValue);
double functionValue = base.GetByX(xValue);
double yValue = factor * functionValue;
Trace = string.Empty;
Trace += base.GetTrace();
Trace += $"Scale Y: {Name}, Input: {functionValue}, Output: {yValue};\n";
return yValue;
}
public override GraphSettings GetGraphSettings()
{
@@ -34,5 +40,9 @@ namespace StructureHelperCommon.Models.Functions.Decorator
}
return graphSettings;
}
public override string GetTrace()
{
return Trace;
}
}
}

View File

@@ -85,8 +85,6 @@ namespace StructureHelperCommon.Models.Functions
public object Clone()
{
var formulaFunction = new FormulaFunction();
//Здесь будет стратегия
formulaFunction.Type = Type;
formulaFunction.Name = $"{Name} {COPY}";
formulaFunction.Description = Description;
@@ -104,6 +102,8 @@ namespace StructureHelperCommon.Models.Functions
double yValue = 0;
current_xValue = xValue;
yValue = Math.Round(Expression.CalculateValue(new double[] { xValue }), 2);
Trace = string.Empty;
Trace += $"Function: {Formula}, Input: {xValue}, Output: {yValue};\n";
return yValue;
}
public GraphSettings GetGraphSettings()
@@ -117,5 +117,9 @@ namespace StructureHelperCommon.Models.Functions
}
return graphSettings;
}
public string GetTrace()
{
return Trace;
}
}
}

View File

@@ -59,7 +59,6 @@ namespace StructureHelperCommon.Models.Functions
public object Clone()
{
var tableFunction = new TableFunction();
//Здесь будет стратегия
tableFunction.Type = Type;
tableFunction.Name = $"{Name} {COPY}";
tableFunction.Description = Description;
@@ -73,6 +72,7 @@ namespace StructureHelperCommon.Models.Functions
public double GetByX(double xValue)
{
double yValue = 0;
GraphPoint leftBound = null;
GraphPoint rightBound = null;
for (int i = 0; i < Table.Count - 1; i++)
@@ -81,18 +81,20 @@ namespace StructureHelperCommon.Models.Functions
rightBound = Table[i + 1];
if (xValue == leftBound.X)
{
return leftBound.Y;
yValue = leftBound.Y;
}
else if (xValue == rightBound.X)
{
return rightBound.Y;
yValue = rightBound.Y;
}
else
{
return MathUtils.Interpolation(xValue, leftBound.X, rightBound.X, leftBound.Y, rightBound.Y);
yValue = MathUtils.Interpolation(xValue, leftBound.X, rightBound.X, leftBound.Y, rightBound.Y);
}
}
return 0;
Trace = string.Empty;
Trace += $"From table, Input: {xValue}, Output: {yValue};\n";
return yValue;
}
public GraphSettings GetGraphSettings()
{
@@ -104,5 +106,9 @@ namespace StructureHelperCommon.Models.Functions
}
return graphSettings;
}
public string GetTrace()
{
return Trace;
}
}
}

View File

@@ -44,18 +44,5 @@ namespace StructureHelperCommon.Services
_lineSeries.Fill = Brushes.Transparent;
return _lineSeries;
}
/*public SeriesCollection GetSeriesCollection()
{
foreach (GraphPoint point in GraphPoints)
{
_chartValues.Add(Math.Round(point.Y, 2));
}
_lineSeries.Values = _chartValues;
_lineSeries.Stroke = new SolidColorBrush(_strokeColor);
_lineSeries.Fill = Brushes.Transparent;
_seriesCollection.Add(_lineSeries);
return _seriesCollection;
}*/
}
}