From ceefe3dbca064a7e063d14ded7f78dc7e2623ec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=20=D0=98=D0=B2=D0=B0=D1=88=D0=BA?= =?UTF-8?q?=D0=B8=D0=BD?= Date: Fri, 20 Dec 2024 15:24:03 +0500 Subject: [PATCH] Add function trace --- .../Windows/TreeGraph/GetValueView.xaml | 4 ++-- .../Windows/TreeGraph/GetValueViewModel.cs | 5 +++-- .../Windows/TreeGraph/TreeGraphViewModel.cs | 16 ++++++++-------- .../Interfaces/FunctionDecorator.cs | 4 ++++ .../Interfaces/IOneVariableFunction.cs | 1 + .../Models/Functions/Decorator/LimXDecorator.cs | 15 ++++++++++++--- .../Models/Functions/Decorator/LimYDecorator.cs | 15 ++++++++++++--- .../Functions/Decorator/ScaleXDecorator.cs | 11 ++++++++++- .../Functions/Decorator/ScaleYDecorator.cs | 12 +++++++++++- .../Models/Functions/FormulaFunction.cs | 8 ++++++-- .../Models/Functions/TableFunction.cs | 16 +++++++++++----- StructureHelperCommon/Services/GraphSettings.cs | 13 ------------- 12 files changed, 80 insertions(+), 40 deletions(-) diff --git a/StructureHelper/Windows/TreeGraph/GetValueView.xaml b/StructureHelper/Windows/TreeGraph/GetValueView.xaml index 2bb0642..b64c685 100644 --- a/StructureHelper/Windows/TreeGraph/GetValueView.xaml +++ b/StructureHelper/Windows/TreeGraph/GetValueView.xaml @@ -43,8 +43,8 @@ diff --git a/StructureHelper/Windows/TreeGraph/GetValueViewModel.cs b/StructureHelper/Windows/TreeGraph/GetValueViewModel.cs index 54e932a..770fc23 100644 --- a/StructureHelper/Windows/TreeGraph/GetValueViewModel.cs +++ b/StructureHelper/Windows/TreeGraph/GetValueViewModel.cs @@ -14,7 +14,7 @@ namespace StructureHelper.Windows.TreeGraph public IOneVariableFunction function; private double argument; private double value; - private string trace = "Будет логика расчёта"; + private string trace = "Press \"Get value\" to calculation...\n\n\n"; public IOneVariableFunction Function { get => function; @@ -55,7 +55,8 @@ namespace StructureHelper.Windows.TreeGraph private void GetValue() { Value = Function.GetByX(Argument); - Trace = "трасса"; + Trace += Function.GetTrace(); + Trace += "\n\n"; } } } diff --git a/StructureHelper/Windows/TreeGraph/TreeGraphViewModel.cs b/StructureHelper/Windows/TreeGraph/TreeGraphViewModel.cs index 5850979..84cf084 100644 --- a/StructureHelper/Windows/TreeGraph/TreeGraphViewModel.cs +++ b/StructureHelper/Windows/TreeGraph/TreeGraphViewModel.cs @@ -137,8 +137,8 @@ namespace StructureHelper.Windows.TreeGraph v.DataContext = vm; if (v.ShowDialog() == true) { - SelectedFuntion = new ScaleXDecorator(SelectedFuntion, vm.ScaleFactor); - var child = new TreeViewItemViewModel(SelectedFuntion, selectedTreeViewItem, this); + var newFunction = new ScaleXDecorator(SelectedFuntion, vm.ScaleFactor); + var child = new TreeViewItemViewModel(newFunction, selectedTreeViewItem, this); selectedTreeViewItem.Children.Add(child); selectedTreeViewItem.IsExpanded = true; } @@ -149,8 +149,8 @@ namespace StructureHelper.Windows.TreeGraph v.DataContext = vm; if (v.ShowDialog() == true) { - SelectedFuntion = new ScaleYDecorator(SelectedFuntion, vm.ScaleFactor); - var child = new TreeViewItemViewModel(SelectedFuntion, selectedTreeViewItem, this); + var newFunction = new ScaleYDecorator(SelectedFuntion, vm.ScaleFactor); + var child = new TreeViewItemViewModel(newFunction, selectedTreeViewItem, this); selectedTreeViewItem.Children.Add(child); selectedTreeViewItem.IsExpanded = true; } @@ -176,8 +176,8 @@ namespace StructureHelper.Windows.TreeGraph v.DataContext = vm; if (v.ShowDialog() == true) { - SelectedFuntion = new LimXDecorator(SelectedFuntion, vm.LeftBound, vm.RightBound); - var child = new TreeViewItemViewModel(SelectedFuntion, selectedTreeViewItem, this); + var newFunction = new LimXDecorator(SelectedFuntion, vm.LeftBound, vm.RightBound); + var child = new TreeViewItemViewModel(newFunction, selectedTreeViewItem, this); selectedTreeViewItem.Children.Add(child); selectedTreeViewItem.IsExpanded = true; } @@ -188,8 +188,8 @@ namespace StructureHelper.Windows.TreeGraph v.DataContext = vm; if (v.ShowDialog() == true) { - SelectedFuntion = new LimYDecorator(SelectedFuntion, vm.LeftBound, vm.RightBound); - var child = new TreeViewItemViewModel(SelectedFuntion, selectedTreeViewItem, this); + var newFunction = new LimYDecorator(SelectedFuntion, vm.LeftBound, vm.RightBound); + var child = new TreeViewItemViewModel(newFunction, selectedTreeViewItem, this); selectedTreeViewItem.Children.Add(child); selectedTreeViewItem.IsExpanded = true; } diff --git a/StructureHelperCommon/Infrastructures/Interfaces/FunctionDecorator.cs b/StructureHelperCommon/Infrastructures/Interfaces/FunctionDecorator.cs index 84f1124..b137421 100644 --- a/StructureHelperCommon/Infrastructures/Interfaces/FunctionDecorator.cs +++ b/StructureHelperCommon/Infrastructures/Interfaces/FunctionDecorator.cs @@ -52,5 +52,9 @@ namespace StructureHelperCommon.Infrastructures.Interfaces { return function.GetGraphSettings(); } + public virtual string GetTrace() + { + return function.GetTrace(); + } } } diff --git a/StructureHelperCommon/Infrastructures/Interfaces/IOneVariableFunction.cs b/StructureHelperCommon/Infrastructures/Interfaces/IOneVariableFunction.cs index f132c82..804e8b0 100644 --- a/StructureHelperCommon/Infrastructures/Interfaces/IOneVariableFunction.cs +++ b/StructureHelperCommon/Infrastructures/Interfaces/IOneVariableFunction.cs @@ -30,5 +30,6 @@ namespace StructureHelperCommon.Infrastructures.Interfaces public bool Check(); public double GetByX(double xValue); public GraphSettings GetGraphSettings(); + public string GetTrace(); } } diff --git a/StructureHelperCommon/Models/Functions/Decorator/LimXDecorator.cs b/StructureHelperCommon/Models/Functions/Decorator/LimXDecorator.cs index bbcde04..c30873d 100644 --- a/StructureHelperCommon/Models/Functions/Decorator/LimXDecorator.cs +++ b/StructureHelperCommon/Models/Functions/Decorator/LimXDecorator.cs @@ -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; + } } } diff --git a/StructureHelperCommon/Models/Functions/Decorator/LimYDecorator.cs b/StructureHelperCommon/Models/Functions/Decorator/LimYDecorator.cs index 6b29fd6..4dd3b96 100644 --- a/StructureHelperCommon/Models/Functions/Decorator/LimYDecorator.cs +++ b/StructureHelperCommon/Models/Functions/Decorator/LimYDecorator.cs @@ -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; + } } } diff --git a/StructureHelperCommon/Models/Functions/Decorator/ScaleXDecorator.cs b/StructureHelperCommon/Models/Functions/Decorator/ScaleXDecorator.cs index 169001e..cc86197 100644 --- a/StructureHelperCommon/Models/Functions/Decorator/ScaleXDecorator.cs +++ b/StructureHelperCommon/Models/Functions/Decorator/ScaleXDecorator.cs @@ -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; + } } } diff --git a/StructureHelperCommon/Models/Functions/Decorator/ScaleYDecorator.cs b/StructureHelperCommon/Models/Functions/Decorator/ScaleYDecorator.cs index c885997..feb6034 100644 --- a/StructureHelperCommon/Models/Functions/Decorator/ScaleYDecorator.cs +++ b/StructureHelperCommon/Models/Functions/Decorator/ScaleYDecorator.cs @@ -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; + } } } diff --git a/StructureHelperCommon/Models/Functions/FormulaFunction.cs b/StructureHelperCommon/Models/Functions/FormulaFunction.cs index 27eb451..be66584 100644 --- a/StructureHelperCommon/Models/Functions/FormulaFunction.cs +++ b/StructureHelperCommon/Models/Functions/FormulaFunction.cs @@ -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; + } } } diff --git a/StructureHelperCommon/Models/Functions/TableFunction.cs b/StructureHelperCommon/Models/Functions/TableFunction.cs index 1d010e1..f639d58 100644 --- a/StructureHelperCommon/Models/Functions/TableFunction.cs +++ b/StructureHelperCommon/Models/Functions/TableFunction.cs @@ -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; + } } } diff --git a/StructureHelperCommon/Services/GraphSettings.cs b/StructureHelperCommon/Services/GraphSettings.cs index d571e14..4d71a4a 100644 --- a/StructureHelperCommon/Services/GraphSettings.cs +++ b/StructureHelperCommon/Services/GraphSettings.cs @@ -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; - }*/ } }