Re-Write without checking mapped

This commit is contained in:
2022-09-14 19:00:57 -07:00
parent 73de1070b8
commit ad28ab2d38
70 changed files with 1596 additions and 2342 deletions

View File

@ -1,45 +0,0 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace View_by_Distance.Shared.Models;
public class Closest : Properties.IClosest
{
protected readonly bool _AboveTolerance;
protected readonly int _Average;
protected readonly bool? _IsWrongYear;
protected Mapping _Mapping;
protected readonly double _Minimum;
protected readonly DateTime _MinimumDateTime;
protected readonly int _NormalizedPixelPercentage;
protected readonly long? _TicksDelta;
public bool AboveTolerance => _AboveTolerance;
public double Average => _Average;
public bool? IsWrongYear => _IsWrongYear;
public Mapping Mapping => _Mapping;
public double Minimum => _Minimum;
public DateTime MinimumDateTime => _MinimumDateTime;
public int NormalizedPixelPercentage => _NormalizedPixelPercentage;
public long? TicksDelta => _TicksDelta;
[JsonConstructor]
public Closest(bool aboveTolerance, int average, int normalizedPixelPercentage, bool? isWrongYear, Mapping mapping, double minimum, DateTime minimumDateTime, long? ticksDelta)
{
_AboveTolerance = aboveTolerance;
_Average = average;
_NormalizedPixelPercentage = normalizedPixelPercentage;
_IsWrongYear = isWrongYear;
_Mapping = mapping;
_Minimum = minimum;
_MinimumDateTime = minimumDateTime;
_TicksDelta = ticksDelta;
}
public override string ToString()
{
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
return result;
}
}

View File

@ -7,67 +7,47 @@ public class Face : Properties.IFace
{
protected DateTime _DateTime;
protected List<FaceDistance> _FaceDistances;
protected FaceDistance? _FaceDistance;
protected FaceEncoding? _FaceEncoding;
protected Dictionary<Stateless.FacePart, FacePoint[]>? _FaceParts;
protected List<int[]>? _FaceNumbers;
protected readonly OutputResolution? _OutputResolution;
protected Location? _Location;
protected readonly int? _LocationIndex;
protected Mapping? _Mapping;
protected readonly string _RelativePath;
protected List<object> _Tags;
public DateTime DateTime => _DateTime;
public List<FaceDistance> FaceDistances => _FaceDistances;
public FaceDistance? FaceDistance => _FaceDistance;
public FaceEncoding? FaceEncoding => _FaceEncoding;
public Dictionary<Stateless.FacePart, FacePoint[]>? FaceParts => _FaceParts;
public List<int[]>? FaceNumbers => _FaceNumbers;
public Location? Location => _Location;
public int? LocationIndex => _LocationIndex;
public Mapping? Mapping => _Mapping;
public OutputResolution? OutputResolution => _OutputResolution;
public string RelativePath => _RelativePath;
public List<object> Tags => _Tags;
[JsonConstructor]
public Face(DateTime dateTime, List<FaceDistance> faceDistances, FaceEncoding? faceEncoding, Dictionary<Stateless.FacePart, FacePoint[]>? faceParts, List<int[]>? faceNumbers, Location? location, int? locationIndex, OutputResolution? outputResolution, string relativePath)
public Face(DateTime dateTime, FaceDistance? faceDistance, FaceEncoding? faceEncoding, Dictionary<Stateless.FacePart, FacePoint[]>? faceParts, Location? location, int? locationIndex, Mapping? mapping, OutputResolution? outputResolution, string relativePath)
{
if (faceDistances is null)
faceDistances = new();
_DateTime = dateTime;
_FaceDistances = faceDistances;
_FaceDistance = faceDistance;
_FaceEncoding = faceEncoding;
_FaceParts = faceParts;
_FaceNumbers = faceNumbers;
_Location = location;
_LocationIndex = locationIndex;
_Mapping = mapping;
_OutputResolution = outputResolution;
_RelativePath = relativePath;
_Tags = new();
}
public Face() :
this(DateTime.MinValue, new(), null, null, null, null, null, null, string.Empty)
{ }
public Face(Location location) :
this(DateTime.MinValue, new(), null, null, null, location, null, null, string.Empty)
{ }
public Face(int facesCount, Face face) :
this(face.DateTime, new(), face.FaceEncoding, face.FaceParts, null, face.Location, face.LocationIndex, face.OutputResolution, face.RelativePath)
this(face.DateTime, null, face.FaceEncoding, face.FaceParts, face.Location, face.LocationIndex, null, face.OutputResolution, face.RelativePath)
{
if (face.Location?.Confidence is not null && face.OutputResolution is not null)
_Location = new(face.Location.Confidence, face.OutputResolution.Height, face.Location, face.OutputResolution.Width, facesCount);
}
public Face(int outputResolutionWidth, int outputResolutionHeight, int outputResolutionOrientation, Face face) :
this(face.DateTime, new(), face.FaceEncoding, face.FaceParts, null, face.Location, face.LocationIndex, null, face.RelativePath)
{
if (outputResolutionHeight > 0)
_OutputResolution = new(outputResolutionHeight, outputResolutionOrientation, outputResolutionWidth);
}
public Face(Property property, int outputResolutionWidth, int outputResolutionHeight, int outputResolutionOrientation, string relativePath, int? i, Location? location) :
this(DateTime.MinValue, new(), null, null, null, location, i, null, relativePath)
this(DateTime.MinValue, null, null, null, location, i, null, null, relativePath)
{
DateTime?[] dateTimes;
_OutputResolution = new(outputResolutionHeight, outputResolutionOrientation, outputResolutionWidth);
@ -85,6 +65,10 @@ public class Face : Properties.IFace
public void SetFaceParts(Dictionary<Stateless.FacePart, FacePoint[]> faceParts) => _FaceParts = faceParts;
public void SetFaceNumbers(List<int[]> faceNumbers) => _FaceNumbers = faceNumbers;
public void ReleaseFaceDistance() => _FaceDistance = null;
public void SetMapping(Mapping mapping) => _Mapping = mapping;
public void FaceDistanceAdd(FaceDistance faceDistance) => _FaceDistance = faceDistance;
}

View File

@ -3,30 +3,39 @@ using System.Text.Json.Serialization;
namespace View_by_Distance.Shared.Models;
public class FaceDistance : Properties.IFaceDistance
public record class FaceDistance : Properties.IFaceDistance
{
protected readonly List<double> _Distances;
protected readonly bool? _IsWrongYear;
protected readonly string _Key;
protected readonly Mapping _Mapping;
protected readonly DateTime _MinimumDateTime;
public List<double> Distances => _Distances;
public bool? IsWrongYear => _IsWrongYear;
public string Key => _Key;
public Mapping Mapping => _Mapping;
public DateTime MinimumDateTime => _MinimumDateTime;
public double? Confidence { init; get; }
public object? Encoding { init; get; }
public int Id { init; get; }
public bool? IsWrongYear { init; get; }
public double? Length { init; get; }
public DateTime? MinimumDateTime { init; get; }
public int? NormalizedPixelPercentage { init; get; }
[JsonConstructor]
public FaceDistance(List<double> distances, bool? isWrongYear, string key, Mapping mapping, DateTime minimumDateTime)
public FaceDistance(double? confidence, object? encoding, int id, bool? isWrongYear, double? length, DateTime? minimumDateTime, int? normalizedPixelPercentage)
{
_Distances = distances;
_IsWrongYear = isWrongYear;
_Key = key;
_Mapping = mapping;
_MinimumDateTime = minimumDateTime;
Confidence = confidence;
Encoding = encoding;
Id = id;
IsWrongYear = isWrongYear;
Length = length;
MinimumDateTime = minimumDateTime;
NormalizedPixelPercentage = normalizedPixelPercentage;
}
public FaceDistance(double? confidence, object? encoding, int id, bool? isWrongYear, DateTime? minimumDateTime, int? normalizedPixelPercentage) :
this(confidence, encoding, id, isWrongYear, null, minimumDateTime, normalizedPixelPercentage)
{ }
public FaceDistance(FaceDistance faceDistance, double length) :
this(faceDistance.Confidence, null, faceDistance.Id, faceDistance.IsWrongYear, length, faceDistance.MinimumDateTime, faceDistance.NormalizedPixelPercentage)
{ }
public FaceDistance(object encoding) => Encoding = encoding;
public override string ToString()
{
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });

View File

@ -0,0 +1,25 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace View_by_Distance.Shared.Models;
public record class FaceDistanceContainer : Properties.IFaceDistanceContainer
{
public Face Face { init; get; }
public FaceDistance FaceDistance { init; get; }
[JsonConstructor]
public FaceDistanceContainer(Face face, FaceDistance faceDistance)
{
Face = face;
FaceDistance = faceDistance;
}
public override string ToString()
{
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
return result;
}
}

View File

@ -8,10 +8,8 @@ public class Item : Properties.IItem
protected readonly bool? _Abandoned;
protected readonly bool? _Changed;
protected List<Closest> _Closest;
protected List<Face> _Faces;
protected readonly FileHolder? _ImageFileHolder;
protected List<Mapping> _Mapping;
protected bool? _Moved;
protected readonly bool? _NoJson;
protected Property? _Property;
@ -21,10 +19,8 @@ public class Item : Properties.IItem
protected bool _ValidImageFormatExtension;
public bool? Abandoned => _Abandoned;
public bool? Changed => _Changed;
public List<Closest> Closest => _Closest;
public List<Face> Faces => _Faces;
public FileHolder? ImageFileHolder => _ImageFileHolder;
public List<Mapping> Mapping => _Mapping;
public bool? Moved => _Moved;
public bool? NoJson => _NoJson;
public Property? Property => _Property;
@ -34,14 +30,12 @@ public class Item : Properties.IItem
public bool ValidImageFormatExtension => _ValidImageFormatExtension;
[JsonConstructor]
public Item(bool? abandoned, bool? changed, List<Closest> closest, List<Face> faces, FileHolder? imageFileHolder, List<Mapping> mapping, bool? moved, bool? noJson, Property? property, string relativePath, FileHolder? resizedFileHolder, string sourceDirectoryFile, bool validImageFormatExtension)
public Item(bool? abandoned, bool? changed, List<Face> faces, FileHolder? imageFileHolder, bool? moved, bool? noJson, Property? property, string relativePath, FileHolder? resizedFileHolder, string sourceDirectoryFile, bool validImageFormatExtension)
{
_Abandoned = abandoned;
_Changed = changed;
_Closest = closest;
_Faces = faces;
_ImageFileHolder = imageFileHolder;
_Mapping = mapping;
_Moved = moved;
_NoJson = noJson;
_Property = property;
@ -54,8 +48,6 @@ public class Item : Properties.IItem
public Item(string sourceDirectoryFile, string relativePath, FileHolder? imageFileInfo, bool isValidImageFormatExtension, Property? property, bool? abandoned, bool? changed)
{
_Faces = new();
_Mapping = new();
_Closest = new();
_Changed = changed;
_Property = property;
_Abandoned = abandoned;

View File

@ -28,16 +28,16 @@ public class Location : Properties.ILocation, IEquatable<Location>
_NormalizedPixelPercentage = normalizedPixelPercentage;
_Right = right;
_Top = top;
Check(bottom, left, normalizedPixelPercentage, right, top, zCount: 1);
Stateless.Methods.Location.Check(bottom, left, normalizedPixelPercentage, right, top, zCount: 1);
}
public Location(double confidence, int height, Location location, int width, int zCount) :
this(location.Bottom, confidence, location.Left, GetNormalizedPixelPercentage(location.Bottom, height, location.Left, location.Right, location.Top, width, zCount), location.Right, location.Top) =>
Check(_Bottom, _Left, _NormalizedPixelPercentage, _Right, _Top, zCount);
this(location.Bottom, confidence, location.Left, Stateless.Methods.Location.GetNormalizedPixelPercentage(location.Bottom, height, location.Left, location.Right, location.Top, width, zCount), location.Right, location.Top) =>
Stateless.Methods.Location.Check(_Bottom, _Left, _NormalizedPixelPercentage, _Right, _Top, zCount);
public Location(int bottom, double confidence, int height, int left, int right, int top, int width, int zCount) :
this(bottom, confidence, left, GetNormalizedPixelPercentage(bottom, height, left, right, top, width, zCount), right, top) =>
Check(_Bottom, height, _Left, _NormalizedPixelPercentage, _Right, _Top, width, zCount);
this(bottom, confidence, left, Stateless.Methods.Location.GetNormalizedPixelPercentage(bottom, height, left, right, top, width, zCount), right, top) =>
Stateless.Methods.Location.Check(_Bottom, height, _Left, _NormalizedPixelPercentage, _Right, _Top, width, zCount);
public Location(double confidence, int factor, int height, Location location, int width, int zCount)
{
@ -47,8 +47,8 @@ public class Location : Properties.ILocation, IEquatable<Location>
int left = Math.Max(location.Left - x, 0);
int right = Math.Min(location.Right + x, width);
int top = Math.Max(location.Top - y, 0);
int normalizedPixelPercentage = GetNormalizedPixelPercentage(location.Bottom, height, location.Left, location.Right, location.Top, width, zCount);
Check(bottom, left, _NormalizedPixelPercentage, right, top, zCount);
int normalizedPixelPercentage = Stateless.Methods.Location.GetNormalizedPixelPercentage(location.Bottom, height, location.Left, location.Right, location.Top, width, zCount);
Stateless.Methods.Location.Check(bottom, left, _NormalizedPixelPercentage, right, top, zCount);
_Confidence = confidence;
_Bottom = bottom;
_Left = left;
@ -65,53 +65,6 @@ public class Location : Properties.ILocation, IEquatable<Location>
return result;
}
private static void Check(int bottom, int left, int right, int top, int zCount)
{
if (left < 0)
throw new Exception();
if (right < 0)
throw new Exception();
if (right < left)
throw new Exception();
if (top < 0)
throw new Exception();
if (bottom < 0)
throw new Exception();
if (bottom < top)
throw new Exception();
if (zCount < 0)
throw new Exception();
}
private static void Check(int bottom, int height, int left, int right, int top, int width, int zCount)
{
if (bottom > height)
throw new Exception();
if (left > width)
throw new Exception();
if (right > width)
throw new Exception();
if (top > height)
throw new Exception();
if (zCount < 0)
throw new Exception();
}
private static void Check(int bottom, int left, int? normalizedPixelPercentage, int right, int top, int zCount)
{
Check(bottom, left, right, top, zCount);
if (normalizedPixelPercentage.HasValue && normalizedPixelPercentage.Value < 0)
throw new Exception();
}
private static void Check(int bottom, int height, int left, int? normalizedPixelPercentage, int right, int top, int width, int zCount)
{
Check(bottom, left, right, top, zCount);
Check(bottom, height, left, right, top, width, zCount);
if (normalizedPixelPercentage.HasValue && normalizedPixelPercentage.Value < 0)
throw new Exception();
}
public override int GetHashCode()
{
int hashCode = -773114317;
@ -122,22 +75,6 @@ public class Location : Properties.ILocation, IEquatable<Location>
return hashCode;
}
public static int GetNormalizedPixelPercentage(int bottom, int height, int left, int right, int top, int width, int zCount)
{
int result;
double value;
double total = width * height;
Check(bottom, left, right, top, zCount);
double xCenter = left + ((right - left) / 2);
double yCenter = top + ((bottom - top) / 2);
double at = ((yCenter - 1) * width) + xCenter;
value = at / total;
if (value < 0)
value = 3;
result = (int)(Math.Round(value, Stateless.ILocation.Digits) * Stateless.ILocation.Factor);
return result;
}
public bool Equals(Location? location)
{
return location is not null

View File

@ -3,52 +3,105 @@ using System.Text.Json.Serialization;
namespace View_by_Distance.Shared.Models;
public class Mapping : Properties.IMapping
public class MappingFromItem : Properties.IMappingFromItem
{
protected int? _ApproximateYears;
protected readonly string _DisplayDirectoryName;
protected bool? _Filtered;
protected bool _Forced;
protected readonly int? _NormalizedPixelPercentage;
protected PersonBirthday _PersonBirthday;
protected readonly string _SegmentB;
public int? ApproximateYears => _ApproximateYears;
public string DisplayDirectoryName => _DisplayDirectoryName;
public bool? Filtered => _Filtered;
public bool Forced => _Forced;
public int? NormalizedPixelPercentage => _NormalizedPixelPercentage;
public PersonBirthday PersonBirthday => _PersonBirthday;
public string SegmentB => _SegmentB;
public int Id { init; get; }
public FileHolder ImageFileHolder { init; get; }
public bool? IsWrongYear { init; get; }
public DateTime MinimumDateTime { init; get; }
public FileHolder ResizedFileHolder { init; get; }
[JsonConstructor]
public Mapping(int? approximateYears, string displayDirectoryName, bool? filtered, bool forced, int? normalizedPixelPercentage, PersonBirthday personBirthday, string segmentB)
public MappingFromItem(int id, FileHolder imageFileHolder, bool? isWrongYear, DateTime minimumDateTime, FileHolder resizedFileHolder)
{
_ApproximateYears = approximateYears;
_DisplayDirectoryName = displayDirectoryName;
_Filtered = filtered;
_Forced = forced;
_NormalizedPixelPercentage = normalizedPixelPercentage;
_PersonBirthday = personBirthday;
_SegmentB = segmentB;
Id = id;
ImageFileHolder = imageFileHolder;
IsWrongYear = isWrongYear;
MinimumDateTime = minimumDateTime;
ResizedFileHolder = resizedFileHolder;
}
public Mapping(int? approximateYears, string displayDirectoryName, bool forced, int? normalizedPixelPercentage, PersonBirthday personBirthday, string segmentB) :
this(approximateYears, displayDirectoryName, null, forced, normalizedPixelPercentage, personBirthday, segmentB)
{ }
public Mapping(int? approximateYears, string displayDirectoryName, bool forced, PersonBirthday personBirthday, string segmentB) :
this(approximateYears, displayDirectoryName, null, forced, null, personBirthday, segmentB)
{ }
public override string ToString()
{
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
return result;
}
public void SetFiltered() => _Filtered = true;
}
public void SetFiltered(bool value) => _Filtered = value;
public class MappingFromLocation : Properties.IMappingFromLocation
{
public double Confidence { init; get; }
public string DeterministicHashCodeKeyDisplay { init; get; }
public int NormalizedPixelPercentage { init; get; }
[JsonConstructor]
public MappingFromLocation(double confidence, string deterministicHashCodeKeyDisplay, int normalizedPixelPercentage)
{
Confidence = confidence;
DeterministicHashCodeKeyDisplay = deterministicHashCodeKeyDisplay;
NormalizedPixelPercentage = normalizedPixelPercentage;
}
public override string ToString()
{
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
return result;
}
}
public class MappingFromPerson : Properties.IMappingFromPerson
{
public int? ApproximateYears { init; get; }
public int? By { init; get; }
public string DisplayDirectoryName { init; get; }
public PersonBirthday? PersonBirthday { init; get; }
public string SegmentB { init; get; }
[JsonConstructor]
public MappingFromPerson(int? approximateYears, int? by, string displayDirectoryName, PersonBirthday? personBirthday, string segmentB)
{
ApproximateYears = approximateYears;
By = by;
DisplayDirectoryName = displayDirectoryName;
PersonBirthday = personBirthday;
SegmentB = segmentB;
}
public override string ToString()
{
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
return result;
}
}
public class Mapping : Properties.IMapping
{
protected MappingFromPerson _MappingFromPerson;
public MappingFromItem MappingFromItem { init; get; }
public MappingFromLocation MappingFromLocation { init; get; }
public MappingFromPerson MappingFromPerson => _MappingFromPerson;
[JsonConstructor]
public Mapping(MappingFromItem mappingFromItem, MappingFromLocation mappingFromLocation, MappingFromPerson mappingFromPerson)
{
MappingFromItem = mappingFromItem;
MappingFromLocation = mappingFromLocation;
_MappingFromPerson = mappingFromPerson;
}
public override string ToString()
{
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
return result;
}
public void UpdateMappingFromPerson(int? approximateYears, int? by, string displayDirectoryName, PersonBirthday personBirthday, string segmentB) => _MappingFromPerson = new(approximateYears, by, displayDirectoryName, personBirthday, segmentB);
}

View File

@ -1,48 +0,0 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace View_by_Distance.Shared.Models;
public class MappingContainer : Properties.IMappingContainer
{
protected double? _Distance;
protected readonly Face? _Face;
protected readonly int _Id;
protected readonly bool? _IsWrongYear;
protected readonly string _Key;
protected readonly Mapping _Mapping;
protected readonly DateTime _MinimumDateTime;
public double? Distance => _Distance;
public Face? Face => _Face;
public int Id => _Id;
public bool? IsWrongYear => _IsWrongYear;
public string Key => _Key;
public Mapping Mapping => _Mapping;
public DateTime MinimumDateTime => _MinimumDateTime;
[JsonConstructor]
public MappingContainer(double? distance, Face? face, int id, bool? isWrongYear, string key, Mapping mapping, DateTime minimumDateTime)
{
_Distance = distance;
_Face = face;
_Id = id;
_IsWrongYear = isWrongYear;
_Key = key;
_Mapping = mapping;
_MinimumDateTime = minimumDateTime;
}
public MappingContainer(Face face, int id, bool? isWrongYear, string key, Mapping mapping, DateTime minimumDateTime) :
this(null, face, id, isWrongYear, key, mapping, minimumDateTime)
{ }
public override string ToString()
{
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
return result;
}
public void SetDistance(double v) => _Distance = v;
}

View File

@ -1,8 +0,0 @@
namespace View_by_Distance.Shared.Models.Methods;
public interface IClosest : Stateless.Methods.IClosest
{ // ...
//
}

View File

@ -1,8 +0,0 @@
namespace View_by_Distance.Shared.Models.Methods;
public interface INamed : Stateless.Methods.IMapping
{ // ...
//
}

View File

@ -1,14 +0,0 @@
namespace View_by_Distance.Shared.Models.Properties;
public interface IClosest
{
public double Average { get; }
public bool? IsWrongYear { get; }
public Mapping Mapping { get; }
public double Minimum { get; }
public DateTime MinimumDateTime { get; }
public int NormalizedPixelPercentage { get; }
public long? TicksDelta { get; }
}

View File

@ -4,12 +4,12 @@ public interface IFace
{
public DateTime DateTime { get; }
public List<FaceDistance> FaceDistances { get; }
public FaceDistance? FaceDistance { get; }
public FaceEncoding? FaceEncoding { get; }
public Dictionary<Stateless.FacePart, FacePoint[]>? FaceParts { get; }
public List<int[]>? FaceNumbers { get; }
public Location? Location { get; }
public int? LocationIndex { get; }
public Mapping? Mapping { get; }
public OutputResolution? OutputResolution { get; }
public string RelativePath { get; }

View File

@ -3,10 +3,12 @@ namespace View_by_Distance.Shared.Models.Properties;
public interface IFaceDistance
{
public List<double> Distances { get; }
public bool? IsWrongYear { get; }
public string Key { get; }
public Mapping Mapping { get; }
public DateTime MinimumDateTime { get; }
public double? Confidence { init; get; }
public object? Encoding { init; get; }
public int Id { init; get; }
public bool? IsWrongYear { init; get; }
public double? Length { init; get; }
public DateTime? MinimumDateTime { init; get; }
public int? NormalizedPixelPercentage { init; get; }
}

View File

@ -0,0 +1,9 @@
namespace View_by_Distance.Shared.Models.Properties;
public interface IFaceDistanceContainer
{
public Face Face { init; get; }
public FaceDistance FaceDistance { init; get; }
}

View File

@ -5,10 +5,8 @@ public interface IItem
public bool? Abandoned { get; }
public bool? Changed { get; }
public List<Closest> Closest { get; }
public List<Face> Faces { get; }
public FileHolder? ImageFileHolder { get; }
public List<Mapping> Mapping { get; }
public bool? Moved { get; }
public bool? NoJson { get; }
public Property? Property { get; }

View File

@ -1,14 +1,41 @@
namespace View_by_Distance.Shared.Models.Properties;
public interface IMappingFromItem
{
public int Id { init; get; }
public FileHolder ImageFileHolder { init; get; }
public bool? IsWrongYear { init; get; }
public DateTime MinimumDateTime { init; get; }
public FileHolder ResizedFileHolder { init; get; }
}
public interface IMappingFromLocation
{
public double Confidence { init; get; }
public string DeterministicHashCodeKeyDisplay { init; get; }
public int NormalizedPixelPercentage { init; get; }
}
public interface IMappingFromPerson
{
public int? ApproximateYears { init; get; }
public int? By { init; get; }
public string DisplayDirectoryName { init; get; }
public PersonBirthday? PersonBirthday { init; get; }
public string SegmentB { init; get; }
}
public interface IMapping
{
public int? ApproximateYears { get; }
public string DisplayDirectoryName { get; }
public bool? Filtered { get; }
public bool Forced { get; }
public int? NormalizedPixelPercentage { get; }
public PersonBirthday PersonBirthday { get; }
public string SegmentB { get; }
public MappingFromItem MappingFromItem { init; get; }
public MappingFromLocation MappingFromLocation { init; get; }
public MappingFromPerson MappingFromPerson { get; }
}

View File

@ -1,14 +0,0 @@
namespace View_by_Distance.Shared.Models.Properties;
public interface IMappingContainer
{
public double? Distance { get; }
public Face? Face { get; }
public int Id { get; }
public bool? IsWrongYear { get; }
public string Key { get; }
public Mapping Mapping { get; }
public DateTime MinimumDateTime { get; }
}

View File

@ -3,10 +3,10 @@ namespace View_by_Distance.Shared.Models.Properties;
public interface ISorting
{
public double? Confidence { init; get; }
public double? Distance { init; get; }
public int? FaceEncoding { init; get; }
public int DaysDelta { init; get; }
public int DistancePermyriad { init; get; }
public int Id { init; get; }
public int? NormalizedPixelPercentage { init; get; }
public int NormalizedPixelPercentage { init; get; }
public int WithinRange { init; get; }
}

View File

@ -0,0 +1,9 @@
namespace View_by_Distance.Shared.Models.Properties;
public interface ISortingContainer
{
public Face Face { init; get; }
public Sorting Sorting { init; get; }
}

View File

@ -3,32 +3,25 @@ using System.Text.Json.Serialization;
namespace View_by_Distance.Shared.Models;
public class Sorting : Properties.ISorting
public record class Sorting : Properties.ISorting
{
public double? Confidence { init; get; }
public double? Distance { init; get; }
public int? FaceEncoding { init; get; }
public int DaysDelta { init; get; }
public int DistancePermyriad { init; get; }
public int Id { init; get; }
public int? NormalizedPixelPercentage { init; get; }
public int NormalizedPixelPercentage { init; get; }
public bool Older { init; get; }
public int WithinRange { init; get; }
[JsonConstructor]
public Sorting(double? confidence, double? distance, int? faceEncoding, int id, int? normalizedPixelPercentage)
public Sorting(int daysDelta, int distancePermyriad, int id, int normalizedPixelPercentage, bool older, int withinRange)
{
Confidence = confidence;
Distance = distance;
FaceEncoding = faceEncoding;
Id = id;
NormalizedPixelPercentage = normalizedPixelPercentage;
}
public Sorting(double? confidence, int id, int? normalizedPixelPercentage)
{
Confidence = confidence;
Distance = null;
FaceEncoding = int.MaxValue;
DaysDelta = daysDelta;
DistancePermyriad = distancePermyriad;
Id = id;
NormalizedPixelPercentage = normalizedPixelPercentage;
Older = older;
WithinRange = withinRange;
}
public override string ToString()
@ -37,13 +30,4 @@ public class Sorting : Properties.ISorting
return result;
}
public Sorting(Sorting sorting, double? distance)
{
Confidence = sorting.Confidence;
Distance = distance;
FaceEncoding = null;
Id = sorting.Id;
NormalizedPixelPercentage = sorting.NormalizedPixelPercentage;
}
}

View File

@ -0,0 +1,25 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace View_by_Distance.Shared.Models;
public record class SortingContainer : Properties.ISortingContainer
{
public Face Face { init; get; }
public Sorting Sorting { init; get; }
[JsonConstructor]
public SortingContainer(Face face, Sorting sorting)
{
Face = face;
Sorting = sorting;
}
public override string ToString()
{
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
return result;
}
}

View File

@ -1,17 +0,0 @@
namespace View_by_Distance.Shared.Models.Stateless;
public interface IClosest
{
// 637972153144596958
// const int Digits = 3;
// const int Factor = 1000;
// const int MaximumPer = 50;
// const bool SkipIsWrongYear = false;
const int Digits = 3;
const int Factor = 1000;
const int MaximumPer = 50;
const double Tolerance = 0.6d;
}

View File

@ -6,6 +6,7 @@ public interface IFaceDistance
// const int MaximumPer = 999;
const int HiddenImageFactor = 2;
const int MaximumPer = 9999;
const int Permyriad = 10000;
const double Tolerance = 0.2d;
}

View File

@ -5,7 +5,6 @@ public interface ILocation
const double MinimumConfidence = 0.8d;
const int Digits = 6;
const double Tolerance = 0.6d;
const int Factor = 1000000;
}

View File

@ -10,5 +10,6 @@ public interface IMapping
const bool UseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToMapping = false;
const bool UseDeterministicHashCodeUnknownFaceKeyValuePairsForSaveMapping = false;
const bool SaveFaceEncoding = false;
const bool SaveMapped = false;
}

View File

@ -0,0 +1,13 @@
namespace View_by_Distance.Shared.Models.Stateless;
public interface ISorting
{
const int FacesToSkipAfterSortBeforeLoad = 0;
const int FacesToTakeAfterSortBeforeLoad = 21000;
const int MaximumPerFaceShouldBeHigh = 1000;
const int DaysDeltaTolerance = 700;
const int MaximumPerKey = 27;
const int Sigma = 3;
}

View File

@ -3,19 +3,31 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
internal abstract class Age
{
internal static (int, TimeSpan) GetAge(DateTime minuend, DateTime subtrahend)
internal static (int, TimeSpan) GetAge(long minuendTicks, long subtrahendTicks)
{
TimeSpan result;
int years = 0;
DateTime check = new(subtrahend.Ticks);
DateTime check = new(subtrahendTicks);
for (int i = 0; i < int.MaxValue; i++)
{
check = check.AddYears(1);
if (check > minuend)
if (check.Ticks > minuendTicks)
break;
years += 1;
}
result = new(minuend.Ticks - check.AddYears(-1).Ticks);
result = new(minuendTicks - check.AddYears(-1).Ticks);
return (years, result);
}
internal static (int, TimeSpan) GetAge(long minuendTicks, DateTime subtrahend)
{
(int years, TimeSpan result) = GetAge(minuendTicks, subtrahend.Ticks);
return (years, result);
}
internal static (int, TimeSpan) GetAge(DateTime minuend, DateTime subtrahend)
{
(int years, TimeSpan result) = GetAge(minuend.Ticks, subtrahend.Ticks);
return (years, result);
}

View File

@ -1,39 +0,0 @@
namespace View_by_Distance.Shared.Models.Stateless.Methods;
internal abstract class Closest
{
private static int Get(double rawAverage) => (int)(Math.Round(rawAverage, Stateless.IClosest.Digits) * Stateless.ILocation.Factor);
private static Models.Closest Get(Models.Face face, DateTime minimumDateTime, FaceDistance faceDistance)
{
Models.Closest result;
long? ticksDelta;
double minimum = faceDistance.Distances.Min();
double rawAverage = faceDistance.Distances.Average();
bool aboveTolerance = minimum >= Stateless.IClosest.Tolerance || rawAverage >= Stateless.IClosest.Tolerance;
if (faceDistance.IsWrongYear is null || faceDistance.IsWrongYear.Value)
ticksDelta = null;
else
{
ticksDelta = Math.Abs(faceDistance.MinimumDateTime.Ticks - minimumDateTime.Ticks);
if (faceDistance.MinimumDateTime < faceDistance.Mapping.PersonBirthday.Value)
ticksDelta *= 2;
else if (faceDistance.Mapping.ApproximateYears.HasValue && faceDistance.MinimumDateTime < DateTime.Now.AddYears(-faceDistance.Mapping.ApproximateYears.Value))
ticksDelta *= 2;
}
if (face.Location?.NormalizedPixelPercentage is null)
throw new NullReferenceException(nameof(face.Location.NormalizedPixelPercentage));
int average = Get(rawAverage);
result = new(aboveTolerance, average, face.Location.NormalizedPixelPercentage.Value, faceDistance.IsWrongYear, faceDistance.Mapping, minimum, faceDistance.MinimumDateTime, ticksDelta);
return result;
}
internal static Models.Closest[] GetCollection(Models.Face face, DateTime minimumDateTime, List<FaceDistance> faceDistances)
{
Models.Closest[] results;
Models.Closest[] closestCollection = (from l in faceDistances select Get(face, minimumDateTime, l)).ToArray();
results = (from l in closestCollection orderby l.Average, l.TicksDelta.HasValue, l.TicksDelta select l).ToArray();
return results;
}
}

View File

@ -37,21 +37,6 @@ internal abstract class Face
return jsonElements;
}
internal static List<Models.Sorting> GetSortingCollection(Models.Face face)
{
List<Models.Sorting> results = new();
Models.Sorting sorting;
if (face.FaceNumbers is not null)
{
foreach (int[] numbers in face.FaceNumbers)
{
sorting = Sorting.Get(numbers);
results.Add(sorting);
}
}
return results;
}
private static List<Models.Face> GetFaces(string jsonFileFullName, int? maximum)
{
List<Models.Face> results = new();

View File

@ -0,0 +1,8 @@
namespace View_by_Distance.Shared.Models.Stateless.Methods;
internal abstract class FaceDistance
{
internal static double GetDefaultValue() => throw new Exception();
}

View File

@ -0,0 +1,6 @@
namespace View_by_Distance.Shared.Models.Stateless.Methods;
internal abstract class FaceDistanceContainer
{
}

View File

@ -3,6 +3,12 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
public interface IAge
{ // ...
(int, TimeSpan) TestStatic_GetAge(long minuendTicks, long subtrahendTicks);
static (int, TimeSpan) GetAge(long minuendTicks, long subtrahendTicks) => Age.GetAge(minuendTicks, subtrahendTicks);
(int, TimeSpan) TestStatic_GetAge(long minuendTicks, DateTime subtrahend);
static (int, TimeSpan) GetAge(long minuendTicks, DateTime subtrahend) => Age.GetAge(minuendTicks, subtrahend);
(int, TimeSpan) TestStatic_GetAge(DateTime minuend, DateTime subtrahend);
static (int, TimeSpan) GetAge(DateTime minuend, DateTime subtrahend) => Age.GetAge(minuend, subtrahend);

View File

@ -1,10 +0,0 @@
namespace View_by_Distance.Shared.Models.Stateless.Methods;
public interface IClosest
{ // ...
Models.Closest[] TestStatic_Get(List<FaceDistance> faceDistances);
static Models.Closest[] GetCollection(Models.Face face, DateTime minimumDateTime, List<FaceDistance> faceDistances) => Closest.GetCollection(face, minimumDateTime, faceDistances);
}

View File

@ -18,9 +18,6 @@ public interface IFace
Models.Face[] TestStatic_Getα(Dictionary<FacePart, Models.FacePoint[]> faceParts);
static double? Getα(Dictionary<FacePart, Models.FacePoint[]> faceParts) => Face.Getα(faceParts);
List<Models.Sorting> TestStatic_GetSortingCollection(Models.Face face);
static List<Models.Sorting> GetSortingCollection(Models.Face face) => Face.GetSortingCollection(face);
int?[] TestStatic_GetInts(List<Models.Face> faces);
static int?[] GetInts(List<Models.Face> faces) =>
(from l in faces where l.FaceEncoding is not null && l.Location?.NormalizedPixelPercentage is not null select l.Location?.NormalizedPixelPercentage).ToArray();

View File

@ -0,0 +1,10 @@
namespace View_by_Distance.Shared.Models.Stateless.Methods;
public interface IFaceDistance
{ // ...
double TestStatic_GetDefaultValue();
static double GetDefaultValue() => FaceDistance.GetDefaultValue();
}

View File

@ -0,0 +1,6 @@
namespace View_by_Distance.Shared.Models.Stateless.Methods;
public interface IFaceDistanceContainer
{ // ...
}

View File

@ -3,10 +3,14 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
public interface IFaceFileSystem : IFileSystem
{ // ...
void TestStatic_SearchForMissingFile(string fullFileName, FileInfo fileInfo, string dataFullFileName);
Models.FaceFileSystem[][] TestStatic_GetFaceFileSystemCollection(string requestPath, string rootResultsDirectory, (string RootResultsDirectoryAbsoluteUri, string C_ResizeContentDirectory, string D_FacesContentDirectory, string E_DistanceCollectionDirectory) tuple, string selectedFileFullName);
void TestStatic_SearchForMissingFile(string fullFileName, FileInfo fileInfo, string dataFullFileName) =>
SearchForMissingFile(fullFileName, fileInfo, dataFullFileName);
static void SearchForMissingFile(string fullFileName, FileInfo fileInfo, string dataFullFileName) =>
FaceFileSystem.SearchForMissingFile(fullFileName, fileInfo, dataFullFileName);
static void SearchForMissingFile(string fullFileName, FileInfo fileInfo, string dataFullFileName) => FaceFileSystem.SearchForMissingFile(fullFileName, fileInfo, dataFullFileName);
static Models.FaceFileSystem[] GetFaceFileSystemCollection(string requestPath, (string RootResultsDirectoryAbsoluteUri, string C_ResizeContentDirectory, string D_FacesContentDirectory, string E_DistanceCollectionDirectory) tuple, string selectedFileFullName) => FaceFileSystem.GetFaceFileSystemCollection(requestPath, tuple, selectedFileFullName);
Models.FaceFileSystem[] TestStatic_GetFaceFileSystemCollection(string requestPath, string rootResultsDirectory, (string RootResultsDirectoryAbsoluteUri, string C_ResizeContentDirectory, string D_FacesContentDirectory, string E_DistanceCollectionDirectory) tuple, string selectedFileFullName) =>
GetFaceFileSystemCollection(requestPath, tuple, selectedFileFullName);
static Models.FaceFileSystem[] GetFaceFileSystemCollection(string requestPath, (string RootResultsDirectoryAbsoluteUri, string C_ResizeContentDirectory, string D_FacesContentDirectory, string E_DistanceCollectionDirectory) tuple, string selectedFileFullName) =>
FaceFileSystem.GetFaceFileSystemCollection(requestPath, tuple, selectedFileFullName);
}

View File

@ -1,18 +0,0 @@
namespace View_by_Distance.Shared.Models.Stateless.Methods;
public interface IMapping
{ // ...
double? TestStatic_GetReversedDeterministicHashCodeKey(string file);
static double? GetReversedDeterministicHashCodeKey(bool keyValuePairsAny, Dictionary<int, List<Models.Face>> keyValuePairs, string file) =>
Mapping.GetReversedDeterministicHashCodeKey(keyValuePairsAny, keyValuePairs, file);
double TestStatic_GetDeterministicHashCodeKey(Models.Item item, Models.Face face);
static double GetDeterministicHashCodeKey(Models.Item item, Models.Face face) =>
Mapping.GetDeterministicHashCodeKey(item, face);
double TestStatic_GetDeterministicHashCodeKey(Models.Item item, Models.Closest closest);
static double GetDeterministicHashCodeKey(Models.Item item, Models.Closest closest) =>
Mapping.GetDeterministicHashCodeKey(item, closest);
}

View File

@ -3,15 +3,24 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
public interface ILocation
{ // ...
Models.Location? TestStatic_GetLocation(Models.Location? location, int height, int width, int zCount);
Models.Location? TestStatic_GetLocation(Models.Location? location, int height, int width, int zCount) =>
GetLocation(location, height, width, zCount);
static Models.Location? GetLocation(Models.Location? location, int height, int width, int zCount) =>
location is null ? null : new(location.Confidence, height, location, width, zCount);
Models.Location? TestStatic_GetLocation(int factor, Models.Location? location, int height, int width, int zCount);
Models.Location? TestStatic_GetLocation(int factor, Models.Location? location, int height, int width, int zCount) =>
GetLocation(location, height, width, zCount);
static Models.Location? GetLocation(int factor, Models.Location? location, int height, int width, int zCount) =>
location is null ? null : new(location.Confidence, factor, height, location, width, zCount);
int?[] TestStatic_GetInts(List<Models.Location> locations);
static int?[] GetInts(List<Models.Location> locations) => (from l in locations where l.NormalizedPixelPercentage is not null select l.NormalizedPixelPercentage).ToArray();
int?[] TestStatic_GetInts(List<Models.Location> locations) =>
GetInts(locations);
static int?[] GetInts(List<Models.Location> locations) =>
(from l in locations where l.NormalizedPixelPercentage is not null select l.NormalizedPixelPercentage).ToArray();
int TestStatic_GetNormalizedPixelPercentage(int bottom, int height, int left, int right, int top, int width, int zCount) =>
GetNormalizedPixelPercentage(bottom, height, left, right, top, width, zCount);
static int GetNormalizedPixelPercentage(int bottom, int height, int left, int right, int top, int width, int zCount) =>
Location.GetNormalizedPixelPercentage(bottom, height, left, right, top, width, zCount);
}

View File

@ -0,0 +1,17 @@
namespace View_by_Distance.Shared.Models.Stateless.Methods;
public interface IMapping
{ // ...
static string GetDeterministicHashCodeKeyDisplay(int id, int normalizedPixelPercentage)
=> $"{id}.{normalizedPixelPercentage}";
static double GetDeterministicHashCodeKeyValue(int id, int normalizedPixelPercentage)
=> Math.Round(double.Parse($"{id}.{normalizedPixelPercentage}"), Stateless.ILocation.Digits);
(int?, int?) TestStatic_GetReversedDeterministicHashCodeKey(bool keyValuePairsAny, Dictionary<int, List<Models.Face>> keyValuePairs, string file) =>
GetReversedDeterministicHashCodeKey(keyValuePairsAny, keyValuePairs, file);
static (int?, int?) GetReversedDeterministicHashCodeKey(bool keyValuePairsAny, Dictionary<int, List<Models.Face>> keyValuePairs, string file) =>
Mapping.GetReversedDeterministicHashCodeKey(keyValuePairsAny, keyValuePairs, file);
}

View File

@ -11,7 +11,8 @@ public interface IPersonBirthday
// ...
double? TestStatic_GetAge(Models.PersonBirthday birthday);
double? TestStatic_GetAge(Models.PersonBirthday birthday) =>
GetAge(birthday);
static double? GetAge(Models.PersonBirthday birthday) =>
PersonBirthday.GetAge(birthday);
@ -30,10 +31,16 @@ public interface IPersonBirthday
static string GetFileName(Models.PersonBirthday personBirthday) =>
PersonBirthday.GetFileName(personBirthday);
(int, TimeSpan) TestStatic_GetAge(DateTime dateTime, Models.PersonBirthday birthday);
(int, TimeSpan) TestStatic_GetAge(DateTime dateTime, Models.PersonBirthday birthday) =>
GetAge(dateTime, birthday);
static (int, TimeSpan) GetAge(DateTime dateTime, Models.PersonBirthday birthday) =>
PersonBirthday.GetAge(dateTime, birthday);
(int, TimeSpan) TestStatic_GetAge(long dateTimeTicks, Models.PersonBirthday birthday) =>
GetAge(dateTimeTicks, birthday);
static (int, TimeSpan) GetAge(long dateTimeTicks, Models.PersonBirthday birthday) =>
PersonBirthday.GetAge(dateTimeTicks, birthday);
string TestStatic_GetFormatted(Models.PersonBirthday personBirthday) =>
PersonBirthday.GetFormatted(personBirthday);
static string GetFormatted(Models.PersonBirthday personBirthday) =>
@ -44,16 +51,25 @@ public interface IPersonBirthday
static Models.PersonBirthday? GetPersonBirthday(string personKey) =>
PersonBirthday.GetPersonBirthday(personKey);
bool TestStatic_IsCounterPersonBirthday(Models.PersonBirthday personBirthday);
static bool IsCounterPersonBirthday(Models.PersonBirthday personBirthday) =>
PersonBirthday.IsCounterPersonBirthday(personBirthday);
Models.PersonBirthday TestStatic_GetNextBirthDate(Properties.IStorage storage) =>
PersonBirthday.GetNextBirthDate(storage);
static Models.PersonBirthday GetNextBirthDate(Properties.IStorage storage) =>
PersonBirthday.GetNextBirthDate(storage);
TimeSpan? TestStatic_Get(DateTime now, Models.PersonBirthday personBirthday) =>
PersonBirthday.GetTimeSpan(now, isWrongYear: false, personBirthday);
TimeSpan? TestStatic_Get(DateTime minimumDateTime, Models.PersonBirthday personBirthday) =>
PersonBirthday.GetTimeSpan(minimumDateTime, isWrongYear: false, personBirthday);
static TimeSpan? GetTimeSpan(DateTime minimumDateTime, Models.PersonBirthday personBirthday) =>
PersonBirthday.GetTimeSpan(minimumDateTime, isWrongYear: false, personBirthday);
TimeSpan? TestStatic_Get(long minimumDateTimeTicks, bool? isWrongYear, Models.PersonBirthday personBirthday) =>
PersonBirthday.GetTimeSpan(minimumDateTimeTicks, isWrongYear, personBirthday);
static TimeSpan? GetTimeSpan(long minimumDateTimeTicks, bool? isWrongYear, Models.PersonBirthday personBirthday) =>
PersonBirthday.GetTimeSpan(minimumDateTimeTicks, isWrongYear, personBirthday);
string TestStatic_GetFileFullName(Properties.IStorage storage, Models.PersonBirthday personBirthday) =>
PersonBirthday.GetFileFullName(storage, personBirthday);
static string GetFileFullName(Properties.IStorage storage, Models.PersonBirthday personBirthday) =>
@ -69,4 +85,8 @@ public interface IPersonBirthday
static TimeSpan? GetTimeSpan(DateTime minimumDateTime, bool? isWrongYear, Models.PersonBirthday personBirthday) =>
PersonBirthday.GetTimeSpan(minimumDateTime, isWrongYear, personBirthday);
bool TestStatic_IsWrongYearFilterOrCounterPersonBirthday(bool? isWrongYear, Models.PersonBirthday personBirthday);
static bool IsWrongYearFilterOrCounterPersonBirthday(bool? isWrongYear, Models.PersonBirthday personBirthday) =>
PersonBirthday.IsWrongYearFilterOrCounterPersonBirthday(isWrongYear, personBirthday);
}

View File

@ -3,10 +3,14 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
public interface ISorting
{ // ...
Models.Sorting TestStatic_GetSorting(int[] numbers);
static Models.Sorting GetSorting(int[] numbers) => Sorting.Get(numbers);
Models.Sorting[] TestStatic_Sort(List<Models.Sorting> collection) =>
Sort(collection);
static Models.Sorting[] Sort(List<Models.Sorting> collection) =>
(from l in collection orderby l.WithinRange, l.DistancePermyriad, l.DaysDelta select l).ToArray();
List<int[]> TestStatic_GetFaceNumbers(List<Models.Sorting> collection);
static List<int[]> GetFaceNumbers(List<Models.Sorting> collection) => Sorting.GetFaceNumbers(collection);
Models.Sorting TestStatic_Get(Models.FaceDistance faceDistanceEncoding, Models.FaceDistance faceDistanceLength, bool anyLowerThanTolerance, List<(long lcl, long minimum, long maximum, long ucl)> personKeysRangesCollection) =>
Get(faceDistanceEncoding, faceDistanceLength, anyLowerThanTolerance, personKeysRangesCollection);
static Models.Sorting Get(Models.FaceDistance faceDistanceEncoding, Models.FaceDistance faceDistanceLength, bool anyLowerThanTolerance, List<(long lcl, long minimum, long maximum, long ucl)> personKeysRangesCollection) =>
Sorting.Get(faceDistanceEncoding, faceDistanceLength, anyLowerThanTolerance, personKeysRangesCollection);
}

View File

@ -0,0 +1,11 @@
namespace View_by_Distance.Shared.Models.Stateless.Methods;
public interface ISortingContainer
{ // ...
Models.SortingContainer[] TestStatic_Sort(List<Models.SortingContainer> collection) =>
Sort(collection);
static Models.SortingContainer[] Sort(List<Models.SortingContainer> collection) =>
(from l in collection orderby l.Sorting.WithinRange, l.Sorting.DistancePermyriad, l.Sorting.DaysDelta select l).ToArray();
}

View File

@ -3,4 +3,67 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
internal abstract class Location
{
internal static int GetNormalizedPixelPercentage(int bottom, int height, int left, int right, int top, int width, int zCount)
{
int result;
double value;
double total = width * height;
Check(bottom, left, right, top, zCount);
double xCenter = left + ((right - left) / 2);
double yCenter = top + ((bottom - top) / 2);
double at = ((yCenter - 1) * width) + xCenter;
value = at / total;
if (value < 0)
value = 3;
result = (int)(Math.Round(value, Stateless.ILocation.Digits) * Stateless.ILocation.Factor);
return result;
}
internal static void Check(int bottom, int left, int right, int top, int zCount)
{
if (left < 0)
throw new Exception();
if (right < 0)
throw new Exception();
if (right < left)
throw new Exception();
if (top < 0)
throw new Exception();
if (bottom < 0)
throw new Exception();
if (bottom < top)
throw new Exception();
if (zCount < 0)
throw new Exception();
}
internal static void Check(int bottom, int height, int left, int right, int top, int width, int zCount)
{
if (bottom > height)
throw new Exception();
if (left > width)
throw new Exception();
if (right > width)
throw new Exception();
if (top > height)
throw new Exception();
if (zCount < 0)
throw new Exception();
}
internal static void Check(int bottom, int left, int? normalizedPixelPercentage, int right, int top, int zCount)
{
Check(bottom, left, right, top, zCount);
if (normalizedPixelPercentage.HasValue && normalizedPixelPercentage.Value < 0)
throw new Exception();
}
internal static void Check(int bottom, int height, int left, int? normalizedPixelPercentage, int right, int top, int width, int zCount)
{
Check(bottom, left, right, top, zCount);
Check(bottom, height, left, right, top, width, zCount);
if (normalizedPixelPercentage.HasValue && normalizedPixelPercentage.Value < 0)
throw new Exception();
}
}

View File

@ -5,24 +5,11 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
internal abstract class Mapping
{
private static double GetDeterministicHashCodeKey(int id, int normalizedPixelPercentage)
=> Math.Round(double.Parse($"{id}.{normalizedPixelPercentage}"), Stateless.ILocation.Digits);
internal static double GetDeterministicHashCodeKey(Models.Item item, Models.Closest closest)
{
double result;
if (item.Property?.Id is null || item.ImageFileHolder is null)
throw new NullReferenceException();
result = GetDeterministicHashCodeKey(item.Property.Id.Value, closest.NormalizedPixelPercentage);
return result;
}
internal static double GetDeterministicHashCodeKey(Models.Item item, Models.Face face)
{
double result;
if (item.Property?.Id is null || item.ImageFileHolder is null || face.Location?.NormalizedPixelPercentage is null)
throw new NullReferenceException();
result = GetDeterministicHashCodeKey(item.Property.Id.Value, face.Location.NormalizedPixelPercentage.Value);
double result = IMapping.GetDeterministicHashCodeKeyValue(item.Property.Id.Value, face.Location.NormalizedPixelPercentage.Value);
return result;
}
@ -37,7 +24,7 @@ internal abstract class Mapping
{
if (face.FaceEncoding is null || face.Location?.NormalizedPixelPercentage is null)
continue;
if (normalizedPixelPercentageValue != face.Location.NormalizedPixelPercentage.Value && deterministicHashCodeKey != GetDeterministicHashCodeKey(id, face.Location.NormalizedPixelPercentage.Value))
if (normalizedPixelPercentageValue != face.Location.NormalizedPixelPercentage.Value && deterministicHashCodeKey != IMapping.GetDeterministicHashCodeKeyValue(id, face.Location.NormalizedPixelPercentage.Value))
continue;
collection.Add(face);
}
@ -56,36 +43,46 @@ internal abstract class Mapping
}
}
private static double? GetReversedDeterministicHashCodeFromSegments(bool keyValuePairsAny, Dictionary<int, List<Models.Face>> keyValuePairs, string file, string[] segments)
private static (int?, int?, double?) GetReversedDeterministicHashCodeKeysFromSegments(bool keyValuePairsAny, Dictionary<int, List<Models.Face>> keyValuePairs, string file, string[] segments)
{
double? result;
if (segments.Length != 3)
throw new Exception();
string id = segments[0];
int normalizedPixelPercentageValue;
string normalizedPixelPercentage = segments[1];
if (!int.TryParse(id, out int idValue) || !int.TryParse(normalizedPixelPercentage, out int normalizedPixelPercentageValue))
if (!int.TryParse(id, out int idValue) | !int.TryParse(normalizedPixelPercentage, out normalizedPixelPercentageValue))
result = null;
else
{
result = GetDeterministicHashCodeKey(idValue, normalizedPixelPercentageValue);
result = IMapping.GetDeterministicHashCodeKeyValue(idValue, normalizedPixelPercentageValue);
if (keyValuePairsAny && keyValuePairs.ContainsKey(idValue))
UseKeyValuePairsSaveFaceEncoding(keyValuePairs, file, idValue, normalizedPixelPercentageValue, result.Value, $".{segments[2]}");
}
return result;
return new(idValue, normalizedPixelPercentageValue, result);
}
internal static double? GetReversedDeterministicHashCodeKey(bool keyValuePairsAny, Dictionary<int, List<Models.Face>> keyValuePairs, string file)
internal static (int?, int?) GetReversedDeterministicHashCodeKey(bool keyValuePairsAny, Dictionary<int, List<Models.Face>> keyValuePairs, string file)
{
double? result;
int? id;
int? normalizedPixelPercentage;
string fileName = Path.GetFileName(file);
if (fileName.Length < 2 || fileName[1..].Contains('-'))
result = null;
{
id = null;
normalizedPixelPercentage = null;
}
else
{
string[] segments = fileName.Split('.');
result = GetReversedDeterministicHashCodeFromSegments(keyValuePairsAny, keyValuePairs, file, segments);
(id, normalizedPixelPercentage, double? result) = GetReversedDeterministicHashCodeKeysFromSegments(keyValuePairsAny, keyValuePairs, file, segments);
if (result is null)
{
id = null;
normalizedPixelPercentage = null;
}
}
return result;
return new(id, normalizedPixelPercentage);
}
}

View File

@ -26,16 +26,53 @@ internal abstract class PersonBirthday
return result;
}
internal static TimeSpan? GetTimeSpan(DateTime minimumDateTime, bool? isWrongYear, Models.PersonBirthday personBirthday)
internal static bool IsCounterPersonBirthday(Models.PersonBirthday personBirthday)
{
bool result;
if (personBirthday.Value.Year < 1900)
result = true;
else
result = false;
return result;
}
internal static bool IsWrongYearFilterOrCounterPersonBirthday(bool? isWrongYear, Models.PersonBirthday personBirthday)
{
bool result;
if (isWrongYear is null || isWrongYear.Value || IsCounterPersonBirthday(personBirthday))
result = true;
else
result = false;
return result;
}
internal static TimeSpan? GetTimeSpan(long minimumDateTimeTicks, bool? isWrongYear, Models.PersonBirthday personBirthday)
{
TimeSpan? timeSpan;
if (isWrongYear is null || isWrongYear.Value || personBirthday.Value.Year < 1900)
bool isWrongYearFilterOrCounterPersonBirthday = IsWrongYearFilterOrCounterPersonBirthday(isWrongYear, personBirthday);
if (isWrongYearFilterOrCounterPersonBirthday)
timeSpan = null;
else
timeSpan = new(minimumDateTime.Ticks - personBirthday.Value.Ticks);
timeSpan = new(minimumDateTimeTicks - personBirthday.Value.Ticks);
return timeSpan;
}
internal static TimeSpan? GetTimeSpan(DateTime minimumDateTime, bool? isWrongYear, Models.PersonBirthday personBirthday)
{
TimeSpan? timeSpan = GetTimeSpan(minimumDateTime.Ticks, isWrongYear, personBirthday);
return timeSpan;
}
internal static (int, TimeSpan) GetAge(long dateTimeTicks, Models.PersonBirthday birthday)
{
TimeSpan result;
int years;
if (birthday?.Value is null)
throw new NullReferenceException(nameof(birthday.Value));
(years, result) = Age.GetAge(dateTimeTicks, birthday.Value);
return (years, result);
}
internal static (int, TimeSpan) GetAge(DateTime dateTime, Models.PersonBirthday birthday)
{
TimeSpan result;

View File

@ -3,48 +3,47 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
internal abstract class Sorting
{
internal static Models.Sorting Get(int[] collection)
internal static Models.Sorting Get(Models.FaceDistance faceDistanceEncoding, Models.FaceDistance faceDistanceLength, bool anyLowerThanTolerance, List<(long lcl, long minimum, long maximum, long ucl)> personKeysRangesCollection)
{
if (collection.Length != 5)
throw new Exception();
Models.Sorting result;
int id = collection[3];
int distance = collection[1];
int confidence = collection[2];
int faceEncoding = collection[0];
int normalizedPixelPercentage = collection[4];
result = new(confidence, distance, faceEncoding, id, normalizedPixelPercentage);
if (faceDistanceLength.Length is null)
throw new NotSupportedException();
if (faceDistanceLength.NormalizedPixelPercentage is null)
throw new NotSupportedException();
bool older;
int daysDelta;
int withinRange;
int distancePermyriad;
if (faceDistanceLength.Length.Value == 0 || (anyLowerThanTolerance && faceDistanceLength.Length.Value >= Stateless.IFaceDistance.Tolerance))
{
older = false;
daysDelta = 0;
withinRange = 0;
distancePermyriad = 0;
}
else
{
if (faceDistanceEncoding.MinimumDateTime is null || faceDistanceLength.MinimumDateTime is null)
throw new NotSupportedException();
List<int> withinRanges = new();
long ticks = faceDistanceEncoding.MinimumDateTime.Value.Ticks;
TimeSpan timeSpan = new(faceDistanceLength.MinimumDateTime.Value.Ticks - ticks);
older = timeSpan.TotalMilliseconds < 0;
daysDelta = (int)Math.Round(Math.Abs(timeSpan.TotalDays), 0);
distancePermyriad = (int)(faceDistanceLength.Length.Value / Stateless.IFaceDistance.Tolerance * Stateless.IFaceDistance.Permyriad);
foreach ((long lcl, long minimum, long maximum, long ucl) in personKeysRangesCollection)
{
if (ticks > minimum && ticks < maximum)
withinRanges.Add(0);
else if (ticks > lcl && ticks < ucl)
withinRanges.Add(1);
else
withinRanges.Add(2);
}
withinRange = withinRanges.Max();
}
result = new(daysDelta, distancePermyriad, faceDistanceLength.Id, faceDistanceLength.NormalizedPixelPercentage.Value, older, withinRange);
return result;
}
internal static List<int[]> GetFaceNumbers(List<Models.Sorting> collection)
{
List<int[]> results = new();
List<int> faceNumbers;
collection = (from l in collection orderby l.FaceEncoding is not null, l.Distance, l.Confidence descending, l.Id, l.NormalizedPixelPercentage select l).ToList();
foreach (Models.Sorting sorting in collection)
{
faceNumbers = new();
if (sorting.FaceEncoding is null)
faceNumbers.Add(Stateless.ILocation.Factor);
else
faceNumbers.Add(Stateless.ILocation.Factor * 2);
if (sorting.Distance is null)
faceNumbers.Add(Stateless.ILocation.Factor);
else
faceNumbers.Add((int)(Math.Round(sorting.Distance.Value, Stateless.ILocation.Digits) * Stateless.ILocation.Factor));
if (sorting.Confidence is null)
faceNumbers.Add(Stateless.ILocation.Factor);
else
faceNumbers.Add((int)(Math.Round(sorting.Confidence.Value, Stateless.ILocation.Digits) * Stateless.ILocation.Factor));
faceNumbers.Add(sorting.Id);
if (sorting.NormalizedPixelPercentage is null)
faceNumbers.Add(Stateless.ILocation.Factor);
else
faceNumbers.Add(sorting.NormalizedPixelPercentage.Value);
results.Add(faceNumbers.ToArray());
}
return results;
}
}

View File

@ -0,0 +1,6 @@
namespace View_by_Distance.Shared.Models.Stateless.Methods;
internal abstract class SortingContainer
{
}