Re-Write without checking mapped
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user