diff --git a/SightKeeper.Application/Annotating/HotKeyScreenshoter.cs b/SightKeeper.Application/Annotating/HotKeyScreenshoter.cs index 97c1d7b7..34a9d875 100644 --- a/SightKeeper.Application/Annotating/HotKeyScreenshoter.cs +++ b/SightKeeper.Application/Annotating/HotKeyScreenshoter.cs @@ -1,7 +1,6 @@ using CommunityToolkit.Diagnostics; using SharpHook.Native; using SightKeeper.Application.Input; -using SightKeeper.Domain.Model.DataSets; using SightKeeper.Domain.Model.DataSets.Detector; namespace SightKeeper.Application.Annotating; diff --git a/SightKeeper.Application/Annotating/Screenshoter.cs b/SightKeeper.Application/Annotating/Screenshoter.cs index 590bd87a..efe75d3e 100644 --- a/SightKeeper.Application/Annotating/Screenshoter.cs +++ b/SightKeeper.Application/Annotating/Screenshoter.cs @@ -1,7 +1,6 @@ using SightKeeper.Domain.Model; using SightKeeper.Domain.Model.DataSets.Detector; using SightKeeper.Domain.Model.DataSets.Screenshots; -using SightKeeper.Domain.Services; namespace SightKeeper.Application.Annotating; diff --git a/SightKeeper.Application/Annotating/StreamScreenshoter.cs b/SightKeeper.Application/Annotating/StreamScreenshoter.cs index 990d83cb..c8bce240 100644 --- a/SightKeeper.Application/Annotating/StreamScreenshoter.cs +++ b/SightKeeper.Application/Annotating/StreamScreenshoter.cs @@ -1,5 +1,4 @@ -using SightKeeper.Domain.Model.DataSets; -using SightKeeper.Domain.Model.DataSets.Detector; +using SightKeeper.Domain.Model.DataSets.Detector; namespace SightKeeper.Application.Annotating; diff --git a/SightKeeper.Application/Prediction/Handling/ScreenshoterDetectionHandler.cs b/SightKeeper.Application/Prediction/Handling/ScreenshoterDetectionHandler.cs index d9dbeded..f132931f 100644 --- a/SightKeeper.Application/Prediction/Handling/ScreenshoterDetectionHandler.cs +++ b/SightKeeper.Application/Prediction/Handling/ScreenshoterDetectionHandler.cs @@ -1,7 +1,5 @@ using System.Reactive.Linq; -using SightKeeper.Domain.Model.DataSets; using SightKeeper.Domain.Model.DataSets.Detector; -using SightKeeper.Domain.Services; namespace SightKeeper.Application.Prediction.Handling; diff --git a/SightKeeper.Application/Prediction/ONNXDetector.cs b/SightKeeper.Application/Prediction/ONNXDetector.cs index dbaa7dfa..0b4c11bf 100644 --- a/SightKeeper.Application/Prediction/ONNXDetector.cs +++ b/SightKeeper.Application/Prediction/ONNXDetector.cs @@ -7,7 +7,6 @@ using SightKeeper.Domain.Model.DataSets; using SightKeeper.Domain.Model.DataSets.Tags; using SightKeeper.Domain.Model.DataSets.Weights; -using SightKeeper.Domain.Services; using SixLabors.ImageSharp; using RectangleF = System.Drawing.RectangleF; using Size = SixLabors.ImageSharp.Size; diff --git a/SightKeeper.Application/Training/Trainer.cs b/SightKeeper.Application/Training/Trainer.cs index d215c550..5b4e2dec 100644 --- a/SightKeeper.Application/Training/Trainer.cs +++ b/SightKeeper.Application/Training/Trainer.cs @@ -3,7 +3,6 @@ using SightKeeper.Application.Extensions; using SightKeeper.Domain.Model.DataSets.Detector; using SightKeeper.Domain.Model.DataSets.Weights; -using SightKeeper.Domain.Services; namespace SightKeeper.Application.Training; diff --git a/SightKeeper.Domain/Services/WeightsDataAccess.cs b/SightKeeper.Application/WeightsDataAccess.cs similarity index 73% rename from SightKeeper.Domain/Services/WeightsDataAccess.cs rename to SightKeeper.Application/WeightsDataAccess.cs index 50b141d7..0e9a7e7d 100644 --- a/SightKeeper.Domain/Services/WeightsDataAccess.cs +++ b/SightKeeper.Application/WeightsDataAccess.cs @@ -2,33 +2,35 @@ using SightKeeper.Domain.Model.DataSets.Tags; using SightKeeper.Domain.Model.DataSets.Weights; -namespace SightKeeper.Domain.Services; +namespace SightKeeper.Application; public abstract class WeightsDataAccess { public Weights CreateWeights( WeightsLibrary library, byte[] data, + DateTime creationDate, ModelSize modelSize, WeightsMetrics metrics, IEnumerable tags) where TTag : Tag, MinimumTagsCount { - var weights = library.CreateWeights(modelSize, metrics, tags); - SaveWeightsData(weights, new WeightsData(data)); + var weights = library.CreateWeights(creationDate, modelSize, metrics, tags); + SaveWeightsData(weights, data); return weights; } public Weights CreateWeights( WeightsLibrary library, byte[] data, + DateTime creationDate, ModelSize modelSize, WeightsMetrics metrics, IEnumerable<(TTag, IEnumerable)> tags) where TTag : PoserTag where TKeyPointTag : KeyPointTag { - var weights = library.CreateWeights(modelSize, metrics, tags); - SaveWeightsData(weights, new WeightsData(data)); + var weights = library.CreateWeights(creationDate, modelSize, metrics, tags); + SaveWeightsData(weights, data); return weights; } @@ -46,8 +48,8 @@ public void RemoveWeights(Weights weight RemoveWeightsData(weights); } - public abstract WeightsData LoadWeightsData(Weights weights); + public abstract byte[] LoadWeightsData(Weights weights); - protected abstract void SaveWeightsData(Weights weights, WeightsData data); + protected abstract void SaveWeightsData(Weights weights, byte[] data); protected abstract void RemoveWeightsData(Weights weights); } \ No newline at end of file diff --git a/SightKeeper.Avalonia/DataSets/DataSetViewModel.cs b/SightKeeper.Avalonia/DataSets/DataSetViewModel.cs index 54b04585..daab6df6 100644 --- a/SightKeeper.Avalonia/DataSets/DataSetViewModel.cs +++ b/SightKeeper.Avalonia/DataSets/DataSetViewModel.cs @@ -2,12 +2,12 @@ using System.Collections.Generic; using System.Reactive.Disposables; using DynamicData; +using SightKeeper.Application; using SightKeeper.Avalonia.ViewModels; using SightKeeper.Domain.Model; using SightKeeper.Domain.Model.DataSets; using SightKeeper.Domain.Model.DataSets.Tags; using SightKeeper.Domain.Model.DataSets.Weights; -using SightKeeper.Domain.Services; namespace SightKeeper.Avalonia.DataSets; diff --git a/SightKeeper.Avalonia/DataSets/DataSetsListViewModel.cs b/SightKeeper.Avalonia/DataSets/DataSetsListViewModel.cs index fd257b4b..186aa171 100644 --- a/SightKeeper.Avalonia/DataSets/DataSetsListViewModel.cs +++ b/SightKeeper.Avalonia/DataSets/DataSetsListViewModel.cs @@ -6,7 +6,6 @@ using SightKeeper.Application.Extensions; using SightKeeper.Avalonia.ViewModels; using SightKeeper.Domain.Model.DataSets; -using SightKeeper.Domain.Services; namespace SightKeeper.Avalonia.DataSets; diff --git a/SightKeeper.Avalonia/Setup/ServicesBootstrapper.cs b/SightKeeper.Avalonia/Setup/ServicesBootstrapper.cs index ce6643c1..bf35458d 100644 --- a/SightKeeper.Avalonia/Setup/ServicesBootstrapper.cs +++ b/SightKeeper.Avalonia/Setup/ServicesBootstrapper.cs @@ -9,7 +9,6 @@ using SightKeeper.Data.Binary.Formatters; using SightKeeper.Data.Binary.Services; using SightKeeper.Domain.Model.DataSets; -using SightKeeper.Domain.Services; using GamesDataAccess = SightKeeper.Application.Games.GamesDataAccess; namespace SightKeeper.Avalonia.Setup; diff --git a/SightKeeper.Avalonia/ViewModels/Annotating/ScreenshoterViewModel.cs b/SightKeeper.Avalonia/ViewModels/Annotating/ScreenshoterViewModel.cs index 7f1b9d8e..982160b6 100644 --- a/SightKeeper.Avalonia/ViewModels/Annotating/ScreenshoterViewModel.cs +++ b/SightKeeper.Avalonia/ViewModels/Annotating/ScreenshoterViewModel.cs @@ -2,7 +2,6 @@ using System.Reactive.Subjects; using CommunityToolkit.Diagnostics; using SightKeeper.Application.Annotating; -using SightKeeper.Domain.Model.DataSets; using SightKeeper.Domain.Model.DataSets.Detector; namespace SightKeeper.Avalonia.ViewModels.Annotating; diff --git a/SightKeeper.Avalonia/ViewModels/Annotating/SelectedDataSetViewModel.cs b/SightKeeper.Avalonia/ViewModels/Annotating/SelectedDataSetViewModel.cs index a6661336..2b8bcab4 100644 --- a/SightKeeper.Avalonia/ViewModels/Annotating/SelectedDataSetViewModel.cs +++ b/SightKeeper.Avalonia/ViewModels/Annotating/SelectedDataSetViewModel.cs @@ -2,9 +2,9 @@ using System.Collections.Generic; using System.Reactive.Disposables; using DynamicData; +using SightKeeper.Application; using SightKeeper.Avalonia.DataSets; using SightKeeper.Domain.Model.DataSets.Weights; -using SightKeeper.Domain.Services; namespace SightKeeper.Avalonia.ViewModels.Annotating; diff --git a/SightKeeper.Avalonia/ViewModels/Dialogs/WeightsEditorViewModel.cs b/SightKeeper.Avalonia/ViewModels/Dialogs/WeightsEditorViewModel.cs index bc21971b..fbeba613 100644 --- a/SightKeeper.Avalonia/ViewModels/Dialogs/WeightsEditorViewModel.cs +++ b/SightKeeper.Avalonia/ViewModels/Dialogs/WeightsEditorViewModel.cs @@ -5,9 +5,9 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using DynamicData; +using SightKeeper.Application; using SightKeeper.Avalonia.Dialogs; using SightKeeper.Domain.Model.DataSets.Weights; -using SightKeeper.Domain.Services; namespace SightKeeper.Avalonia.ViewModels.Dialogs; diff --git a/SightKeeper.Data/Binary/Conversion/DataSets/Classifier/ClassifierDataSetsConverter.cs b/SightKeeper.Data/Binary/Conversion/DataSets/Classifier/ClassifierDataSetsConverter.cs index e0e9e976..45cf0c69 100644 --- a/SightKeeper.Data/Binary/Conversion/DataSets/Classifier/ClassifierDataSetsConverter.cs +++ b/SightKeeper.Data/Binary/Conversion/DataSets/Classifier/ClassifierDataSetsConverter.cs @@ -1,12 +1,9 @@ using System.Collections.Immutable; -using System.Runtime.CompilerServices; using CommunityToolkit.Diagnostics; using SightKeeper.Data.Binary.DataSets; using SightKeeper.Data.Binary.Services; using SightKeeper.Domain.Model.DataSets.Classifier; using SightKeeper.Domain.Model.DataSets.Screenshots; -using SightKeeper.Domain.Model.DataSets.Tags; -using SightKeeper.Domain.Model.DataSets.Weights; using ClassifierAsset = SightKeeper.Data.Binary.DataSets.Classifier.ClassifierAsset; using ClassifierDataSet = SightKeeper.Data.Binary.DataSets.Classifier.ClassifierDataSet; using Screenshot = SightKeeper.Data.Binary.DataSets.Screenshot; @@ -67,14 +64,6 @@ public Domain.Model.DataSets.Classifier.ClassifierDataSet ConvertBack( private readonly ScreenshotsConverter _screenshotsConverter; private readonly ClassifierAssetsConverter _assetsConverter; - [UnsafeAccessor(UnsafeAccessorKind.Method)] - private static extern Weights CreateWeights( - WeightsLibrary library, - ModelSize size, - WeightsMetrics metrics, - IEnumerable tags) - where TTag : Domain.Model.DataSets.Tags.Tag, MinimumTagsCount; - private static void AddTags(Domain.Model.DataSets.Classifier.ClassifierDataSet dataSet, ImmutableArray tags, ReverseConversionSession session) { foreach (var rawTag in tags) @@ -110,7 +99,7 @@ private void AddWeights(Domain.Model.DataSets.Classifier.ClassifierDataSet dataS { foreach (var rawWeights in raw) { - var weights = CreateWeights(dataSet.Weights, rawWeights.Size, rawWeights.Metrics, rawWeights.Tags.Select(tagId => (ClassifierTag)session.Tags[tagId])); + var weights = dataSet.Weights.CreateWeights(rawWeights.CreationDate, rawWeights.Size, rawWeights.Metrics, rawWeights.Tags.Select(tagId => (ClassifierTag)session.Tags[tagId])); _weightsDataAccess.AssociateId(weights, rawWeights.Id); session.Weights.Add(rawWeights.Id, weights); } diff --git a/SightKeeper.Data/Binary/Conversion/DataSets/Detector/DetectorDataSetsConverter.cs b/SightKeeper.Data/Binary/Conversion/DataSets/Detector/DetectorDataSetsConverter.cs index 1916561d..a91e32be 100644 --- a/SightKeeper.Data/Binary/Conversion/DataSets/Detector/DetectorDataSetsConverter.cs +++ b/SightKeeper.Data/Binary/Conversion/DataSets/Detector/DetectorDataSetsConverter.cs @@ -1,12 +1,9 @@ using System.Collections.Immutable; -using System.Runtime.CompilerServices; using CommunityToolkit.Diagnostics; using SightKeeper.Data.Binary.DataSets; using SightKeeper.Data.Binary.Services; using SightKeeper.Domain.Model.DataSets.Detector; using SightKeeper.Domain.Model.DataSets.Screenshots; -using SightKeeper.Domain.Model.DataSets.Tags; -using SightKeeper.Domain.Model.DataSets.Weights; using DetectorAsset = SightKeeper.Data.Binary.DataSets.Detector.DetectorAsset; using DetectorDataSet = SightKeeper.Data.Binary.DataSets.Detector.DetectorDataSet; using Screenshot = SightKeeper.Data.Binary.DataSets.Screenshot; @@ -69,14 +66,6 @@ internal Domain.Model.DataSets.Detector.DetectorDataSet ConvertBack( private readonly WeightsConverter _weightsConverter; private readonly DetectorAssetsConverter _assetsConverter; - [UnsafeAccessor(UnsafeAccessorKind.Method)] - private static extern Weights CreateWeights( - WeightsLibrary library, - ModelSize size, - WeightsMetrics metrics, - IEnumerable tags) - where TTag : Domain.Model.DataSets.Tags.Tag, MinimumTagsCount; - private static void AddTags(Domain.Model.DataSets.Detector.DetectorDataSet dataSet, ImmutableArray tags, ReverseConversionSession session) { foreach (var rawTag in tags) @@ -113,7 +102,7 @@ private void AddWeights(Domain.Model.DataSets.Detector.DetectorDataSet dataSet, { foreach (var rawWeights in raw) { - var weights = CreateWeights(dataSet.Weights, rawWeights.Size, rawWeights.Metrics, rawWeights.Tags.Select(tagId => (DetectorTag)session.Tags[tagId])); + var weights = dataSet.Weights.CreateWeights(rawWeights.CreationDate, rawWeights.Size, rawWeights.Metrics, rawWeights.Tags.Select(tagId => (DetectorTag)session.Tags[tagId])); _weightsDataAccess.AssociateId(weights, rawWeights.Id); session.Weights.Add(rawWeights.Id, weights); } diff --git a/SightKeeper.Data/Binary/Conversion/DataSets/Poser2D/Poser2DDataSetsConverter.cs b/SightKeeper.Data/Binary/Conversion/DataSets/Poser2D/Poser2DDataSetsConverter.cs index ab87557f..5c60ce96 100644 --- a/SightKeeper.Data/Binary/Conversion/DataSets/Poser2D/Poser2DDataSetsConverter.cs +++ b/SightKeeper.Data/Binary/Conversion/DataSets/Poser2D/Poser2DDataSetsConverter.cs @@ -1,13 +1,10 @@ using System.Collections.Immutable; -using System.Runtime.CompilerServices; using CommunityToolkit.Diagnostics; using FlakeId; using SightKeeper.Data.Binary.DataSets.Poser; using SightKeeper.Data.Binary.Services; -using SightKeeper.Domain.Model.DataSets.Poser; using SightKeeper.Domain.Model.DataSets.Poser2D; using SightKeeper.Domain.Model.DataSets.Screenshots; -using SightKeeper.Domain.Model.DataSets.Weights; using Poser2DAsset = SightKeeper.Data.Binary.DataSets.Poser2D.Poser2DAsset; using Poser2DDataSet = SightKeeper.Data.Binary.DataSets.Poser2D.Poser2DDataSet; using Poser2DTag = SightKeeper.Data.Binary.DataSets.Poser2D.Poser2DTag; @@ -72,15 +69,6 @@ internal Domain.Model.DataSets.Poser2D.Poser2DDataSet ConvertBack( private readonly WeightsConverter _weightsConverter; private readonly Poser2DAssetsConverter _assetsConverter; - [UnsafeAccessor(UnsafeAccessorKind.Method)] - private static extern Weights CreateWeights( - WeightsLibrary library, - ModelSize size, - WeightsMetrics metrics, - ImmutableDictionary> tags) - where TTag : PoserTag - where TKeyPointTag : KeyPointTag; - private static void CreateTags(Domain.Model.DataSets.Poser2D.Poser2DDataSet dataSet, ImmutableArray tags, ReverseConversionSession session) { foreach (var rawTag in tags) @@ -136,18 +124,20 @@ private void CreateWeights(Domain.Model.DataSets.Poser2D.Poser2DDataSet dataSet, { foreach (var rawWeights in raw) { - var weights = CreateWeights(dataSet.Weights, rawWeights.Size, rawWeights.Metrics, ConvertBack(rawWeights.Tags, session)); + var weights = dataSet.Weights.CreateWeights(rawWeights.CreationDate, rawWeights.Size, rawWeights.Metrics, ConvertBack(rawWeights.Tags, session)); _weightsDataAccess.AssociateId(weights, rawWeights.Id); session.Weights.Add(rawWeights.Id, weights); } } - private ImmutableDictionary> ConvertBack( + private IEnumerable<(Domain.Model.DataSets.Poser2D.Poser2DTag, IEnumerable)> ConvertBack( ImmutableArray<(Id Id, ImmutableArray KeyPointIds)> tags, ReverseConversionSession session) { - return tags.ToImmutableDictionary( - t => (Domain.Model.DataSets.Poser2D.Poser2DTag)session.Tags[t.Id], - t => t.KeyPointIds.Select(id => (KeyPointTag2D)session.Tags[id]).ToImmutableHashSet()); + foreach (var (tagId, keyPointIds) in tags) + { + yield return ((Domain.Model.DataSets.Poser2D.Poser2DTag)session.Tags[tagId], + keyPointIds.Select(id => (KeyPointTag2D)session.Tags[id]).ToImmutableList()); + } } } \ No newline at end of file diff --git a/SightKeeper.Data/Binary/Conversion/DataSets/WeightsConverter.cs b/SightKeeper.Data/Binary/Conversion/DataSets/WeightsConverter.cs index 00725919..8dede98c 100644 --- a/SightKeeper.Data/Binary/Conversion/DataSets/WeightsConverter.cs +++ b/SightKeeper.Data/Binary/Conversion/DataSets/WeightsConverter.cs @@ -67,7 +67,7 @@ private static ImmutableArray Convert( } private static ImmutableArray<(Id, ImmutableArray)> Convert( - IImmutableDictionary> tags, + ImmutableDictionary> tags, ConversionSession session) where TTag : PoserTag where TKeyPointTag : KeyPointTag diff --git a/SightKeeper.Data/Binary/Services/FileSystemWeightsDataAccess.cs b/SightKeeper.Data/Binary/Services/FileSystemWeightsDataAccess.cs index 7577b1cd..b373ec5a 100644 --- a/SightKeeper.Data/Binary/Services/FileSystemWeightsDataAccess.cs +++ b/SightKeeper.Data/Binary/Services/FileSystemWeightsDataAccess.cs @@ -1,7 +1,6 @@ -using System.Runtime.CompilerServices; -using FlakeId; +using FlakeId; +using SightKeeper.Application; using SightKeeper.Domain.Model.DataSets.Weights; -using SightKeeper.Domain.Services; namespace SightKeeper.Data.Binary.Services; @@ -13,13 +12,9 @@ public string DirectoryPath set => _dataAccess.DirectoryPath = value; } - public override WeightsData LoadWeightsData(Weights weights) + public override byte[] LoadWeightsData(Weights weights) { - var data = _dataAccess.ReadAllBytes(weights); - return CreateWeightsData(data); - - [UnsafeAccessor(UnsafeAccessorKind.Constructor)] - static extern WeightsData CreateWeightsData(byte[] content); + return _dataAccess.ReadAllBytes(weights); } public Id GetId(Weights weights) @@ -32,9 +27,9 @@ public void AssociateId(Weights weights, Id id) _dataAccess.AssociateId(weights, id); } - protected override void SaveWeightsData(Weights weights, WeightsData data) + protected override void SaveWeightsData(Weights weights, byte[] data) { - _dataAccess.WriteAllBytes(weights, data.Content); + _dataAccess.WriteAllBytes(weights, data); } protected override void RemoveWeightsData(Weights weights) diff --git a/SightKeeper.Domain.Tests/DataSets/Classifier/ClassifierWeightsLibraryTests.cs b/SightKeeper.Domain.Tests/DataSets/Classifier/ClassifierWeightsLibraryTests.cs index d88bec73..83948e7c 100644 --- a/SightKeeper.Domain.Tests/DataSets/Classifier/ClassifierWeightsLibraryTests.cs +++ b/SightKeeper.Domain.Tests/DataSets/Classifier/ClassifierWeightsLibraryTests.cs @@ -11,8 +11,7 @@ public void ShouldCreateWeights() ClassifierDataSet dataSet = new(); var tag1 = dataSet.Tags.CreateTag("1"); var tag2 = dataSet.Tags.CreateTag("2"); - SimpleWeightsDataAccess weightsDataAccess = new(); - var weights = weightsDataAccess.CreateWeights(dataSet.Weights, [], ModelSize.Nano, new WeightsMetrics(), [tag1, tag2]); + var weights = dataSet.Weights.CreateWeights(DateTime.UtcNow, ModelSize.Nano, new WeightsMetrics(), [tag1, tag2]); dataSet.Weights.Should().Contain(weights); } @@ -20,8 +19,7 @@ public void ShouldCreateWeights() public void ShouldNotCreateWeightsWithNoTags() { ClassifierDataSet dataSet = new(); - SimpleWeightsDataAccess weightsDataAccess = new(); - Assert.ThrowsAny(() => weightsDataAccess.CreateWeights(dataSet.Weights, [], ModelSize.Nano, new WeightsMetrics(), [])); + Assert.ThrowsAny(() => dataSet.Weights.CreateWeights(DateTime.UtcNow, ModelSize.Nano, new WeightsMetrics(), [])); dataSet.Weights.Should().BeEmpty(); } @@ -30,8 +28,7 @@ public void ShouldNotCreateWeightsWithOneTag() { ClassifierDataSet dataSet = new(); var tag = dataSet.Tags.CreateTag(""); - SimpleWeightsDataAccess weightsDataAccess = new(); - Assert.ThrowsAny(() => weightsDataAccess.CreateWeights(dataSet.Weights, [], ModelSize.Nano, new WeightsMetrics(), [tag])); + Assert.ThrowsAny(() => dataSet.Weights.CreateWeights(DateTime.UtcNow, ModelSize.Nano, new WeightsMetrics(), [tag])); dataSet.Weights.Should().BeEmpty(); } @@ -41,8 +38,7 @@ public void ShouldNotCreateWeightsWithDuplicateTags() ClassifierDataSet dataSet = new(); var tag1 = dataSet.Tags.CreateTag("1"); var tag2 = dataSet.Tags.CreateTag("2"); - SimpleWeightsDataAccess weightsDataAccess = new(); - Assert.ThrowsAny(() => weightsDataAccess.CreateWeights(dataSet.Weights, [], ModelSize.Nano, new WeightsMetrics(), [tag1, tag1, tag2])); + Assert.ThrowsAny(() => dataSet.Weights.CreateWeights(DateTime.UtcNow, ModelSize.Nano, new WeightsMetrics(), [tag1, tag1, tag2])); dataSet.Weights.Should().BeEmpty(); } } \ No newline at end of file diff --git a/SightKeeper.Domain.Tests/DataSets/Detector/DetectorWeightsLibraryTests.cs b/SightKeeper.Domain.Tests/DataSets/Detector/DetectorWeightsLibraryTests.cs index 07965ad4..1f464d9e 100644 --- a/SightKeeper.Domain.Tests/DataSets/Detector/DetectorWeightsLibraryTests.cs +++ b/SightKeeper.Domain.Tests/DataSets/Detector/DetectorWeightsLibraryTests.cs @@ -10,8 +10,7 @@ public void ShouldCreateWeights() { DetectorDataSet dataSet = new(); var tag = dataSet.Tags.CreateTag(""); - SimpleWeightsDataAccess weightsDataAccess = new(); - var weights = weightsDataAccess.CreateWeights(dataSet.Weights, [], ModelSize.Nano, new WeightsMetrics(), [tag]); + var weights = dataSet.Weights.CreateWeights(DateTime.UtcNow, ModelSize.Nano, new WeightsMetrics(), [tag]); dataSet.Weights.Should().Contain(weights); } @@ -19,8 +18,7 @@ public void ShouldCreateWeights() public void ShouldNotCreateWeightsWithNoTags() { DetectorDataSet dataSet = new(); - SimpleWeightsDataAccess weightsDataAccess = new(); - Assert.ThrowsAny(() => weightsDataAccess.CreateWeights(dataSet.Weights, [], ModelSize.Nano, new WeightsMetrics(), [])); + Assert.ThrowsAny(() => dataSet.Weights.CreateWeights(DateTime.UtcNow, ModelSize.Nano, new WeightsMetrics(), [])); dataSet.Weights.Should().BeEmpty(); } @@ -29,8 +27,7 @@ public void ShouldNotCreateWeightsWithDuplicateTags() { DetectorDataSet dataSet = new(); var tag = dataSet.Tags.CreateTag(""); - SimpleWeightsDataAccess weightsDataAccess = new(); - Assert.ThrowsAny(() => weightsDataAccess.CreateWeights(dataSet.Weights, [], ModelSize.Nano, new WeightsMetrics(), [tag, tag])); + Assert.ThrowsAny(() => dataSet.Weights.CreateWeights(DateTime.UtcNow, ModelSize.Nano, new WeightsMetrics(), [tag, tag])); dataSet.Weights.Should().BeEmpty(); } } \ No newline at end of file diff --git a/SightKeeper.Domain.Tests/DataSets/Poser2D/Poser2DWeightsLibraryTests.cs b/SightKeeper.Domain.Tests/DataSets/Poser2D/Poser2DWeightsLibraryTests.cs index 1625609d..33fea630 100644 --- a/SightKeeper.Domain.Tests/DataSets/Poser2D/Poser2DWeightsLibraryTests.cs +++ b/SightKeeper.Domain.Tests/DataSets/Poser2D/Poser2DWeightsLibraryTests.cs @@ -11,8 +11,7 @@ public void ShouldCreateWeights() { Poser2DDataSet dataSet = new(); var tag = dataSet.Tags.CreateTag(""); - SimpleWeightsDataAccess weightsDataAccess = new(); - var weights = weightsDataAccess.CreateWeights(dataSet.Weights, [], ModelSize.Nano, new WeightsMetrics(), [(tag, [])]); + var weights = dataSet.Weights.CreateWeights(DateTime.UtcNow, ModelSize.Nano, new WeightsMetrics(), [(tag, [])]); dataSet.Weights.Should().Contain(weights); } @@ -20,8 +19,7 @@ public void ShouldCreateWeights() public void ShouldNotCreateWeightsWithNoTags() { Poser2DDataSet dataSet = new(); - SimpleWeightsDataAccess weightsDataAccess = new(); - Assert.ThrowsAny(() => weightsDataAccess.CreateWeights(dataSet.Weights, [], ModelSize.Nano, new WeightsMetrics(), [])); + Assert.ThrowsAny(() => dataSet.Weights.CreateWeights(DateTime.UtcNow, ModelSize.Nano, new WeightsMetrics(), [])); dataSet.Weights.Should().BeEmpty(); } @@ -33,10 +31,9 @@ public void ShouldNotCreateWeightsWithWrongAssociatedKeyPointTags() tag1.CreateKeyPoint("1.1"); var tag2 = dataSet.Tags.CreateTag("2"); var keyPoint2 = tag2.CreateKeyPoint("2.1"); - SimpleWeightsDataAccess weightsDataAccess = new(); var tagsBuilder = ImmutableDictionary.CreateBuilder>(); tagsBuilder.Add(tag1, ImmutableHashSet.Create(keyPoint2)); - Assert.ThrowsAny(() => weightsDataAccess.CreateWeights(dataSet.Weights, [], ModelSize.Nano, new WeightsMetrics(), [(tag1, [keyPoint2])])); + Assert.ThrowsAny(() => dataSet.Weights.CreateWeights(DateTime.UtcNow, ModelSize.Nano, new WeightsMetrics(), [(tag1, [keyPoint2])])); dataSet.Weights.Should().BeEmpty(); } } \ No newline at end of file diff --git a/SightKeeper.Domain.Tests/DataSets/SimpleWeightsDataAccess.cs b/SightKeeper.Domain.Tests/DataSets/SimpleWeightsDataAccess.cs deleted file mode 100644 index 5ed32d63..00000000 --- a/SightKeeper.Domain.Tests/DataSets/SimpleWeightsDataAccess.cs +++ /dev/null @@ -1,25 +0,0 @@ -using CommunityToolkit.Diagnostics; -using SightKeeper.Domain.Model.DataSets.Weights; -using SightKeeper.Domain.Services; - -namespace SightKeeper.Domain.Tests.DataSets; - -public class SimpleWeightsDataAccess : WeightsDataAccess -{ - public override WeightsData LoadWeightsData(Weights weights) - { - return _data[weights]; - } - - protected override void SaveWeightsData(Weights weights, WeightsData data) - { - _data.Add(weights, data); - } - - protected override void RemoveWeightsData(Weights weights) - { - Guard.IsTrue(_data.Remove(weights)); - } - - private readonly Dictionary _data = new(); -} \ No newline at end of file diff --git a/SightKeeper.Domain.Tests/Profiles/Behaviours/AimBehaviourTests.cs b/SightKeeper.Domain.Tests/Profiles/Behaviours/AimBehaviourTests.cs index 1787566a..e507915e 100644 --- a/SightKeeper.Domain.Tests/Profiles/Behaviours/AimBehaviourTests.cs +++ b/SightKeeper.Domain.Tests/Profiles/Behaviours/AimBehaviourTests.cs @@ -5,7 +5,6 @@ using SightKeeper.Domain.Model.DataSets.Weights; using SightKeeper.Domain.Model.Profiles; using SightKeeper.Domain.Model.Profiles.Behaviours; -using SightKeeper.Domain.Tests.DataSets; namespace SightKeeper.Domain.Tests.Profiles.Behaviours; @@ -14,10 +13,9 @@ public sealed class AimBehaviourTests [Fact] public void ShouldSetTags() { - SimpleWeightsDataAccess weightsDataAccess = new(); DetectorDataSet dataSet = new(); var tag = dataSet.Tags.CreateTag(""); - var weights = weightsDataAccess.CreateWeights(dataSet.Weights, [], ModelSize.Nano, new WeightsMetrics(), [tag]); + var weights = dataSet.Weights.CreateWeights(DateTime.UtcNow, ModelSize.Nano, new WeightsMetrics(), [tag]); Profile profile = new(""); var module = profile.CreateModule(weights); var tagsBuilder = ImmutableDictionary.CreateBuilder(); @@ -30,13 +28,12 @@ public void ShouldSetTags() [Fact] public void ShouldNotSetTagsWithWrongOwnership() { - SimpleWeightsDataAccess weightsDataAccess = new(); DetectorDataSet dataSet1 = new(); var tag1 = dataSet1.Tags.CreateTag(""); - var weights1 = weightsDataAccess.CreateWeights(dataSet1.Weights, [], ModelSize.Nano, new WeightsMetrics(), [tag1]); + var weights1 = dataSet1.Weights.CreateWeights(DateTime.UtcNow, ModelSize.Nano, new WeightsMetrics(), [tag1]); DetectorDataSet dataSet2 = new(); var tag2 = dataSet2.Tags.CreateTag(""); - weightsDataAccess.CreateWeights(dataSet2.Weights, [], ModelSize.Nano, new WeightsMetrics(), [tag2]); + dataSet2.Weights.CreateWeights(DateTime.UtcNow, ModelSize.Nano, new WeightsMetrics(), [tag2]); Profile profile = new(""); var module = profile.CreateModule(weights1); var tagsBuilder = ImmutableDictionary.CreateBuilder(); diff --git a/SightKeeper.Domain.Tests/Profiles/Behaviours/TriggerBehaviourTests.cs b/SightKeeper.Domain.Tests/Profiles/Behaviours/TriggerBehaviourTests.cs index b3dc04c0..8886065d 100644 --- a/SightKeeper.Domain.Tests/Profiles/Behaviours/TriggerBehaviourTests.cs +++ b/SightKeeper.Domain.Tests/Profiles/Behaviours/TriggerBehaviourTests.cs @@ -4,7 +4,6 @@ using SightKeeper.Domain.Model.DataSets.Tags; using SightKeeper.Domain.Model.DataSets.Weights; using SightKeeper.Domain.Model.Profiles; -using SightKeeper.Domain.Tests.DataSets; using Action = SightKeeper.Domain.Model.Profiles.Actions.Action; namespace SightKeeper.Domain.Tests.Profiles.Behaviours; @@ -14,11 +13,10 @@ public sealed class TriggerBehaviourTests [Fact] public void ShouldSetTags() { - SimpleWeightsDataAccess weightsDataAccess = new(); ClassifierDataSet dataSet = new(); var tag1 = dataSet.Tags.CreateTag("1"); var tag2 = dataSet.Tags.CreateTag("2"); - var weights = weightsDataAccess.CreateWeights(dataSet.Weights, [], ModelSize.Nano, new WeightsMetrics(), [tag1, tag2]); + var weights = dataSet.Weights.CreateWeights(DateTime.UtcNow, ModelSize.Nano, new WeightsMetrics(), [tag1, tag2]); Profile profile = new(""); var module = profile.CreateModule(weights); var tagsBuilder = ImmutableDictionary.CreateBuilder(); @@ -30,15 +28,14 @@ public void ShouldSetTags() [Fact] public void ShouldNotSetTagsWithWrongOwnership() { - SimpleWeightsDataAccess weightsDataAccess = new(); ClassifierDataSet dataSet1 = new(); var tag1 = dataSet1.Tags.CreateTag("1"); var tag2 = dataSet1.Tags.CreateTag("2"); - var weights1 = weightsDataAccess.CreateWeights(dataSet1.Weights, [], ModelSize.Nano, new WeightsMetrics(), [tag1, tag2]); + var weights1 = dataSet1.Weights.CreateWeights(DateTime.UtcNow, ModelSize.Nano, new WeightsMetrics(), [tag1, tag2]); ClassifierDataSet dataSet2 = new(); var tag3 = dataSet2.Tags.CreateTag("3"); var tag4 = dataSet2.Tags.CreateTag("4"); - weightsDataAccess.CreateWeights(dataSet2.Weights, [], ModelSize.Nano, new WeightsMetrics(), [tag3, tag4]); + dataSet2.Weights.CreateWeights(DateTime.UtcNow, ModelSize.Nano, new WeightsMetrics(), [tag3, tag4]); Profile profile = new(""); var module = profile.CreateModule(weights1); var tagsBuilder = ImmutableDictionary.CreateBuilder(); diff --git a/SightKeeper.Domain.Tests/Profiles/Modules/ModuleTests.cs b/SightKeeper.Domain.Tests/Profiles/Modules/ModuleTests.cs index d78930ab..baf88494 100644 --- a/SightKeeper.Domain.Tests/Profiles/Modules/ModuleTests.cs +++ b/SightKeeper.Domain.Tests/Profiles/Modules/ModuleTests.cs @@ -4,7 +4,6 @@ using SightKeeper.Domain.Model.Profiles; using SightKeeper.Domain.Model.Profiles.Modules.Scaling; using SightKeeper.Domain.Model.Profiles.Modules.Walking; -using SightKeeper.Domain.Tests.DataSets; namespace SightKeeper.Domain.Tests.Profiles.Modules; @@ -13,10 +12,9 @@ public sealed class ModuleTests [Fact] public void ShouldNotSetIterativeScalingAndIterativeWalkingOptionsTogether() { - SimpleWeightsDataAccess weightsDataAccess = new(); DetectorDataSet dataSet = new(); var tag = dataSet.Tags.CreateTag(""); - var weights = weightsDataAccess.CreateWeights(dataSet.Weights, [], ModelSize.Nano, new WeightsMetrics(), [tag]); + var weights = dataSet.Weights.CreateWeights(DateTime.UtcNow, ModelSize.Nano, new WeightsMetrics(), [tag]); Profile profile = new(""); var module = profile.CreateModule(weights); module.PassiveScalingOptions = new IterativeScalingOptions(); diff --git a/SightKeeper.Domain/Model/DataSets/Weights/Weights.cs b/SightKeeper.Domain/Model/DataSets/Weights/Weights.cs index e94c0190..862d7a9c 100644 --- a/SightKeeper.Domain/Model/DataSets/Weights/Weights.cs +++ b/SightKeeper.Domain/Model/DataSets/Weights/Weights.cs @@ -15,9 +15,9 @@ public abstract class Weights public abstract bool Contains(Tag tag); - protected Weights(ModelSize size, WeightsMetrics metrics) + protected Weights(DateTime creationDate, ModelSize size, WeightsMetrics metrics) { - CreationDate = DateTime.Now; + CreationDate = creationDate; Size = size; Metrics = metrics; } @@ -25,7 +25,7 @@ protected Weights(ModelSize size, WeightsMetrics metrics) public sealed class Weights : Weights where TTag : Tag, MinimumTagsCount { - public IImmutableSet Tags { get; } + public ImmutableHashSet Tags { get; } public override WeightsLibrary Library { get; } public override bool Contains(Tag tag) @@ -34,11 +34,12 @@ public override bool Contains(Tag tag) } internal Weights( + DateTime creationDate, ModelSize size, WeightsMetrics metrics, IEnumerable tags, WeightsLibrary library) - : base(size, metrics) + : base(creationDate, size, metrics) { Tags = tags.ToImmutableHashSetThrowOnDuplicate(); Library = library; @@ -57,7 +58,7 @@ public sealed class Weights : Weights where TTag : PoserTag where TKeyPointTag : KeyPointTag { - public IImmutableDictionary> Tags { get; } + public ImmutableDictionary> Tags { get; } public override WeightsLibrary Library { get; } public override bool Contains(Tag tag) @@ -71,13 +72,14 @@ public override bool Contains(Tag tag) } internal Weights( + DateTime creationDate, ModelSize size, WeightsMetrics metrics, IEnumerable<(TTag, IEnumerable)> tags, WeightsLibrary library) - : base(size, metrics) + : base(creationDate, size, metrics) { - var builder = ImmutableDictionary.CreateBuilder>(); + var builder = ImmutableDictionary.CreateBuilder>(); foreach (var (tag, keyPointTags) in tags) builder.Add(tag, ImmutableHashSet.CreateRange(keyPointTags)); Tags = builder.ToImmutable(); diff --git a/SightKeeper.Domain/Model/DataSets/Weights/WeightsData.cs b/SightKeeper.Domain/Model/DataSets/Weights/WeightsData.cs deleted file mode 100644 index c329d26e..00000000 --- a/SightKeeper.Domain/Model/DataSets/Weights/WeightsData.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace SightKeeper.Domain.Model.DataSets.Weights; - -public sealed class WeightsData -{ - public byte[] Content { get; } - - internal WeightsData(byte[] content) - { - Content = content; - } -} \ No newline at end of file diff --git a/SightKeeper.Domain/Model/DataSets/Weights/WeightsLibrary.cs b/SightKeeper.Domain/Model/DataSets/Weights/WeightsLibrary.cs index 767360d4..591a9798 100644 --- a/SightKeeper.Domain/Model/DataSets/Weights/WeightsLibrary.cs +++ b/SightKeeper.Domain/Model/DataSets/Weights/WeightsLibrary.cs @@ -33,20 +33,20 @@ internal WeightsLibrary(DataSet dataSet) DataSet = dataSet; } - internal Weights CreateWeights( + public Weights CreateWeights( + DateTime creationDate, ModelSize modelSize, WeightsMetrics metrics, IEnumerable tags) { - Weights weights = new(modelSize, metrics, tags, this); + Weights weights = new(creationDate, modelSize, metrics, tags, this); Guard.IsTrue(_weights.Add(weights)); return weights; } - internal void RemoveWeights(Weights weights) + public void RemoveWeights(Weights weights) { - var isRemoved = _weights.Remove(weights); - Guard.IsTrue(isRemoved); + Guard.IsTrue(_weights.Remove(weights)); } private readonly SortedSet> _weights = new(WeightsDateComparer.Instance); @@ -74,20 +74,20 @@ internal WeightsLibrary(DataSet dataSet) DataSet = dataSet; } - internal Weights CreateWeights( + public Weights CreateWeights( + DateTime creationDate, ModelSize modelSize, WeightsMetrics metrics, IEnumerable<(TTag, IEnumerable)> tags) { - Weights weights = new(modelSize, metrics, tags, this); + Weights weights = new(creationDate, modelSize, metrics, tags, this); Guard.IsTrue(_weights.Add(weights)); return weights; } - internal void RemoveWeights(Weights weights) + public void RemoveWeights(Weights weights) { - var isRemoved = _weights.Remove(weights); - Guard.IsTrue(isRemoved); + Guard.IsTrue(_weights.Remove(weights)); } private readonly SortedSet> _weights = new(WeightsDateComparer.Instance);