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

@ -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
{
}