-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ClassifierWeights and PoserWeights, Weights tweaks
- Loading branch information
Showing
13 changed files
with
171 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
SightKeeper.Domain/Model/DataSets/Classifier/ClassifierWeights.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Collections.Immutable; | ||
using CommunityToolkit.Diagnostics; | ||
|
||
namespace SightKeeper.Domain.Model.DataSets.Classifier; | ||
|
||
public sealed class ClassifierWeights : Weights | ||
{ | ||
public IReadOnlyCollection<ClassifierTag> Tags { get; } | ||
public ClassifierWeightsLibrary Library { get; } | ||
public ClassifierDataSet DataSet => Library.DataSet; | ||
|
||
internal ClassifierWeights( | ||
ModelSize size, | ||
WeightsMetrics metrics, | ||
IEnumerable<ClassifierTag> tags, | ||
ClassifierWeightsLibrary library) | ||
: base(size, metrics) | ||
{ | ||
Tags = tags.ToImmutableArray(); | ||
Library = library; | ||
ValidateTags(); | ||
} | ||
|
||
private void ValidateTags() | ||
{ | ||
foreach (var tag in Tags) | ||
Guard.IsReferenceEqualTo(tag.DataSet, DataSet); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
SightKeeper.Domain/Model/DataSets/Classifier/ClassifierWeightsLibrary.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace SightKeeper.Domain.Model.DataSets.Classifier; | ||
|
||
public sealed class ClassifierWeightsLibrary : WeightsLibrary<ClassifierWeights> | ||
{ | ||
public ClassifierDataSet DataSet { get; } | ||
|
||
internal ClassifierWeightsLibrary(ClassifierDataSet dataSet) | ||
{ | ||
DataSet = dataSet; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 10 additions & 14 deletions
24
SightKeeper.Domain/Model/DataSets/Detector/DetectorWeights.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,31 @@ | ||
using System.Collections.Immutable; | ||
using CommunityToolkit.Diagnostics; | ||
|
||
namespace SightKeeper.Domain.Model.DataSets.Detector; | ||
|
||
public sealed class DetectorWeights | ||
public sealed class DetectorWeights : Weights | ||
{ | ||
public DateTime CreationDate { get; } | ||
public ModelSize Size { get; } | ||
public WeightsMetrics WeightsMetrics { get; } | ||
public IReadOnlyCollection<DetectorTag> Tags { get; } | ||
public DetectorWeightsLibrary Library { get; } | ||
public DetectorDataSet DataSet => Library.DataSet; | ||
|
||
internal DetectorWeights( | ||
ModelSize modelSize, | ||
WeightsMetrics weightsMetrics, | ||
ModelSize size, | ||
WeightsMetrics metrics, | ||
IEnumerable<DetectorTag> tags, | ||
DetectorWeightsLibrary library) | ||
: base(size, metrics) | ||
{ | ||
CreationDate = DateTime.Now; | ||
Size = modelSize; | ||
WeightsMetrics = weightsMetrics; | ||
Tags = tags.ToImmutableArray(); | ||
Library = library; | ||
Tags = tags.ToImmutableList(); | ||
ValidateTags(); | ||
} | ||
|
||
public override string ToString() => $"{nameof(Size)}: {Size}, {WeightsMetrics}"; | ||
public override string ToString() => $"{nameof(Size)}: {Size}, {Metrics}"; | ||
|
||
private void ValidateTags() | ||
{ | ||
// TODO | ||
/*var isAllTagsBelongsToGivenLibrary = Tags.All(tag => Library.DataSet.Tags.Contains(tag)); | ||
Guard.IsTrue(isAllTagsBelongsToGivenLibrary);*/ | ||
foreach (var tag in Tags) | ||
Guard.IsReferenceEqualTo(tag.DataSet, DataSet); | ||
} | ||
} |
33 changes: 8 additions & 25 deletions
33
SightKeeper.Domain/Model/DataSets/Detector/DetectorWeightsLibrary.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,21 @@ | ||
using System.Collections; | ||
using CommunityToolkit.Diagnostics; | ||
namespace SightKeeper.Domain.Model.DataSets.Detector; | ||
|
||
namespace SightKeeper.Domain.Model.DataSets.Detector; | ||
|
||
public sealed class DetectorWeightsLibrary : IReadOnlyCollection<DetectorWeights> | ||
public sealed class DetectorWeightsLibrary : WeightsLibrary<DetectorWeights> | ||
{ | ||
public int Count => _weights.Count; | ||
public DetectorDataSet DataSet { get; } | ||
|
||
public IEnumerator<DetectorWeights> GetEnumerator() | ||
{ | ||
return _weights.GetEnumerator(); | ||
} | ||
internal DetectorWeightsLibrary(DetectorDataSet dataSet) | ||
{ | ||
DataSet = dataSet; | ||
} | ||
|
||
internal DetectorWeights CreateWeights( | ||
ModelSize modelSize, | ||
WeightsMetrics metrics, | ||
IEnumerable<DetectorTag> tags) | ||
{ | ||
DetectorWeights weights = new(modelSize, metrics, tags, this); | ||
var isAdded = _weights.Add(weights); | ||
Guard.IsTrue(isAdded); | ||
AddWeights(weights); | ||
return weights; | ||
} | ||
|
||
internal void RemoveWeights(DetectorWeights weights) | ||
{ | ||
var isRemoved = _weights.Remove(weights); | ||
Guard.IsTrue(isRemoved); | ||
} | ||
|
||
private readonly SortedSet<DetectorWeights> _weights = new(WeightsDateComparer.Instance); | ||
|
||
IEnumerator IEnumerable.GetEnumerator() | ||
{ | ||
return GetEnumerator(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Collections.Immutable; | ||
using CommunityToolkit.Diagnostics; | ||
|
||
namespace SightKeeper.Domain.Model.DataSets.Poser; | ||
|
||
public sealed class PoserWeights : Weights | ||
{ | ||
public IReadOnlyCollection<PoserTag> Tags { get; } | ||
public PoserWeightsLibrary Library { get; } | ||
public PoserDataSet DataSet => Library.DataSet; | ||
|
||
public PoserWeights( | ||
ModelSize size, | ||
WeightsMetrics metrics, | ||
IEnumerable<PoserTag> tags, | ||
PoserWeightsLibrary library) | ||
: base(size, metrics) | ||
{ | ||
Tags = tags.ToImmutableArray(); | ||
Library = library; | ||
ValidateTags(); | ||
} | ||
|
||
private void ValidateTags() | ||
{ | ||
foreach (var tag in Tags) | ||
Guard.IsReferenceEqualTo(tag.DataSet, DataSet); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
SightKeeper.Domain/Model/DataSets/Poser/PoserWeightsLibrary.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace SightKeeper.Domain.Model.DataSets.Poser; | ||
|
||
public sealed class PoserWeightsLibrary : WeightsLibrary<PoserWeights> | ||
{ | ||
public PoserDataSet DataSet { get; } | ||
|
||
internal PoserWeightsLibrary(PoserDataSet dataSet) | ||
{ | ||
DataSet = dataSet; | ||
} | ||
|
||
internal PoserWeights CreateWeights( | ||
ModelSize modelSize, | ||
WeightsMetrics metrics, | ||
IEnumerable<PoserTag> tags) | ||
{ | ||
PoserWeights weights = new(modelSize, metrics, tags, this); | ||
AddWeights(weights); | ||
return weights; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace SightKeeper.Domain.Model.DataSets; | ||
|
||
public abstract class Weights | ||
{ | ||
public DateTime CreationDate { get; } | ||
public ModelSize Size { get; } | ||
public WeightsMetrics Metrics { get; } | ||
|
||
protected Weights(ModelSize size, WeightsMetrics metrics) | ||
{ | ||
CreationDate = DateTime.Now; | ||
Size = size; | ||
Metrics = metrics; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Collections; | ||
using CommunityToolkit.Diagnostics; | ||
|
||
namespace SightKeeper.Domain.Model.DataSets; | ||
|
||
public abstract class WeightsLibrary<TWeights> : IReadOnlyCollection<TWeights> where TWeights : Weights | ||
{ | ||
public int Count => _weights.Count; | ||
|
||
public IEnumerator<TWeights> GetEnumerator() | ||
{ | ||
return _weights.GetEnumerator(); | ||
} | ||
|
||
internal void RemoveWeights(TWeights weights) | ||
{ | ||
var isRemoved = _weights.Remove(weights); | ||
Guard.IsTrue(isRemoved); | ||
} | ||
|
||
protected void AddWeights(TWeights weights) | ||
{ | ||
bool isAdded = _weights.Add(weights); | ||
Guard.IsTrue(isAdded); | ||
} | ||
|
||
private readonly SortedSet<TWeights> _weights = new(WeightsDateComparer<TWeights>.Instance); | ||
|
||
IEnumerator IEnumerable.GetEnumerator() | ||
{ | ||
return GetEnumerator(); | ||
} | ||
|
||
} |