From 5ce3fb31c5755be25dd4ac95da99c5e11bef3e1c Mon Sep 17 00:00:00 2001 From: Anatoliy Siryi Date: Thu, 14 Mar 2024 16:16:23 +0200 Subject: [PATCH] Update references due to recent refactoring in TALib --- src/TaTooIne.Benchmark/IndicatorsBenchmark.cs | 47 ++++++++----------- src/TaTooIne.Benchmark/Program.cs | 13 ++++- .../DemoIndicators/IndicatorsIndex.razor.cs | 2 +- src/TaTooIne.Demo/Models/Line.cs | 7 +-- src/TaTooIne.Demo/Pages/Demo.razor.cs | 2 +- 5 files changed, 33 insertions(+), 38 deletions(-) diff --git a/src/TaTooIne.Benchmark/IndicatorsBenchmark.cs b/src/TaTooIne.Benchmark/IndicatorsBenchmark.cs index 338afc3..c3dfe5e 100644 --- a/src/TaTooIne.Benchmark/IndicatorsBenchmark.cs +++ b/src/TaTooIne.Benchmark/IndicatorsBenchmark.cs @@ -41,8 +41,7 @@ public void TulipIterationSetup() _tulipPeriodOption++; var currentIndicator = - (Indicator) GetType().GetField("__argField0", BindingFlags.NonPublic | BindingFlags.Instance)! - .GetValue(this)!; + (Indicator) GetType().GetField("__argField0", BindingFlags.NonPublic | BindingFlags.Instance)!.GetValue(this)!; var currentIndicatorIndex = (int) GetType().GetField("__argField1", BindingFlags.NonPublic | BindingFlags.Instance)!.GetValue(this)!; var currentIndicatorOptions = _tulipOptions[currentIndicatorIndex]; @@ -106,8 +105,7 @@ public void Tulip(Indicator Indicator, int order) } } - public static IEnumerable TulipSource() => - Indicators.All.Select((indicator, index) => new object[] { indicator, index }); + public static IEnumerable TulipSource() => Indicators.All.Select((indicator, index) => new object[] { indicator, index }); [GlobalCleanup(Target = "Tulip")] public void GlobalTulipCleanup() => _inputsMemoryPool.Dispose(); @@ -126,8 +124,7 @@ public void TALibIterationSetup() _talibPeriodOption++; var currentFunction = - (Function) GetType().GetField("__argField0", BindingFlags.NonPublic | BindingFlags.Instance)! - .GetValue(this)!; + (Function) GetType().GetField("__argField0", BindingFlags.NonPublic | BindingFlags.Instance)!.GetValue(this)!; var currentFunctionIndex = (int) GetType().GetField("__argField1", BindingFlags.NonPublic | BindingFlags.Instance)!.GetValue(this)!; var currentFunctionOptions = _talibOptions[currentFunctionIndex]; @@ -207,8 +204,7 @@ public void TALib(Function Indicator, int order) } } - public static IEnumerable TALibSource() => - Functions.All.Select((function, index) => new object[] { function, index }); + public static IEnumerable TALibSource() => Abstract.All.Select((function, index) => new object[] { function, index }); [GlobalCleanup(Target = "TALib")] public void GlobalTALibCleanup() => _inputsMemoryPool.Dispose(); @@ -309,34 +305,28 @@ private void SetupTALib() Near = 0.3 }; - Core.SetCandleSettings( - Core.CandleSettingType.BodyDoji, Core.RangeType.HighLow, candleDefaultConfig.Period, - candleDefaultConfig.BodyNone); + Core.CandleSettings.Set(Core.CandleSettingType.BodyDoji, + new Core.CandleSetting(Core.CandleRangeType.HighLow, candleDefaultConfig.Period, candleDefaultConfig.BodyNone)); - Core.SetCandleSettings( - Core.CandleSettingType.BodyShort, Core.RangeType.RealBody, candleDefaultConfig.Period, - candleDefaultConfig.BodyShort); + Core.CandleSettings.Set(Core.CandleSettingType.BodyShort, + new Core.CandleSetting(Core.CandleRangeType.RealBody, candleDefaultConfig.Period, candleDefaultConfig.BodyShort)); - Core.SetCandleSettings( - Core.CandleSettingType.BodyLong, Core.RangeType.RealBody, candleDefaultConfig.Period, - candleDefaultConfig.BodyLong); + Core.CandleSettings.Set(Core.CandleSettingType.BodyLong, + new Core.CandleSetting(Core.CandleRangeType.RealBody, candleDefaultConfig.Period, candleDefaultConfig.BodyLong)); - Core.SetCandleSettings( - Core.CandleSettingType.ShadowVeryShort, Core.RangeType.HighLow, candleDefaultConfig.Period, - candleDefaultConfig.WickNone); + Core.CandleSettings.Set(Core.CandleSettingType.ShadowVeryShort, + new Core.CandleSetting(Core.CandleRangeType.HighLow, candleDefaultConfig.Period, candleDefaultConfig.WickNone)); - Core.SetCandleSettings( - Core.CandleSettingType.ShadowLong, Core.RangeType.RealBody, candleDefaultConfig.Period, - candleDefaultConfig.WickLong); + Core.CandleSettings.Set(Core.CandleSettingType.ShadowLong, + new Core.CandleSetting(Core.CandleRangeType.RealBody, candleDefaultConfig.Period, candleDefaultConfig.WickLong)); - Core.SetCandleSettings( - Core.CandleSettingType.Near, Core.RangeType.HighLow, candleDefaultConfig.Period, - candleDefaultConfig.Near); + Core.CandleSettings.Set(Core.CandleSettingType.Near, + new Core.CandleSetting(Core.CandleRangeType.HighLow, candleDefaultConfig.Period, candleDefaultConfig.Near)); } private void SetupTALibInputs() { - var functionsCount = Functions.All.Count(); + var functionsCount = Abstract.All.Count(); _talibInputs = new Dictionary(functionsCount); _talibOptions = new Dictionary(functionsCount); @@ -344,7 +334,7 @@ private void SetupTALibInputs() for (var i = 0; i < functionsCount; i++) { - var function = Functions.All.ElementAt(i); + var function = Abstract.All.ElementAt(i); var (inputs, options, outputs) = PrepareParams(function); _talibInputs.Add(i, inputs); @@ -419,6 +409,7 @@ private void SetupTALibInputs() { inputData[i] = random.Next(30); } + inputs[j] = inputData; break; } diff --git a/src/TaTooIne.Benchmark/Program.cs b/src/TaTooIne.Benchmark/Program.cs index d074661..c93cea2 100644 --- a/src/TaTooIne.Benchmark/Program.cs +++ b/src/TaTooIne.Benchmark/Program.cs @@ -1,8 +1,10 @@ +using System.Globalization; using BenchmarkDotNet.Columns; using BenchmarkDotNet.Configs; using BenchmarkDotNet.Diagnosers; using BenchmarkDotNet.Environments; using BenchmarkDotNet.Exporters; +using BenchmarkDotNet.Exporters.Csv; using BenchmarkDotNet.Jobs; using BenchmarkDotNet.Loggers; using BenchmarkDotNet.Reports; @@ -14,11 +16,18 @@ .AddDiagnoser(MemoryDiagnoser.Default) .AddLogicalGroupRules(BenchmarkLogicalGroupRule.ByParams) .WithOrderer(BenchmarkOrderer.Instance) - .WithSummaryStyle(SummaryStyle.Default.WithTimeUnit(TimeUnit.Millisecond)) + .WithSummaryStyle(new SummaryStyle( + cultureInfo: CultureInfo.CurrentCulture, + printUnitsInHeader: true, + printUnitsInContent: false, + timeUnit: TimeUnit.Millisecond, + sizeUnit: SizeUnit.KB + )) .WithUnionRule(ConfigUnionRule.Union); #if DEBUG config = ManualConfig.Union(new DebugInProcessConfig(), config); #else + config = ManualConfig.Union(config, ManualConfig.CreateEmpty() .AddLogger(ConsoleLogger.Default) .AddJob(Job.Default.WithRuntime(CoreRuntime.Core80)) @@ -29,7 +38,7 @@ BenchmarkParamsColumnProvider.Instance, DefaultColumnProviders.Metrics ]) - .AddExporter(HtmlExporter.Default)); + .AddExporter(HtmlExporter.Default, CsvExporter.Default, MarkdownExporter.Console)); #endif BenchmarkRunner.Run(config); diff --git a/src/TaTooIne.Demo/DemoIndicators/IndicatorsIndex.razor.cs b/src/TaTooIne.Demo/DemoIndicators/IndicatorsIndex.razor.cs index 9fd5ba0..93f5ce6 100644 --- a/src/TaTooIne.Demo/DemoIndicators/IndicatorsIndex.razor.cs +++ b/src/TaTooIne.Demo/DemoIndicators/IndicatorsIndex.razor.cs @@ -16,7 +16,7 @@ public partial class IndicatorsIndex protected override void OnInitialized() { - _groups = Functions.All.Where(g => g.Group != "Math Transform").GroupBy(f => f.Group).ToList(); + _groups = Abstract.All.Where(g => g.Group != "Math Transform").GroupBy(f => f.Group).ToList(); } private string? NavMenuCssClass(int groupId) => ActiveGroupId == groupId ? "active" : null; diff --git a/src/TaTooIne.Demo/Models/Line.cs b/src/TaTooIne.Demo/Models/Line.cs index 65a5c5f..db88176 100644 --- a/src/TaTooIne.Demo/Models/Line.cs +++ b/src/TaTooIne.Demo/Models/Line.cs @@ -1,8 +1,3 @@ namespace TaTooIne.Demo.Models; -public sealed record Line -{ - public required DateTime Time { get; init; } - - public required double Value { get; init; } -} +public sealed record Line(DateTime Time, double Value); diff --git a/src/TaTooIne.Demo/Pages/Demo.razor.cs b/src/TaTooIne.Demo/Pages/Demo.razor.cs index c10cacd..109ee61 100644 --- a/src/TaTooIne.Demo/Pages/Demo.razor.cs +++ b/src/TaTooIne.Demo/Pages/Demo.razor.cs @@ -95,7 +95,7 @@ private async Task CalculateExample(Function function) }, "Volume Indicators" => new { - Volume = _sampleData.Select(c => new Line { Time = c.Time, Value = c.Volume }).ToList(), + Volume = _sampleData.Select(c => new Line(c.Time, c.Volume)).ToList(), OverlayLines = outputLines }, _ => new