Sorting without ... improvements

This commit is contained in:
2022-12-21 22:54:50 -07:00
parent 44d8eaf5fb
commit 2da3db7aa5
25 changed files with 353 additions and 358 deletions

View File

@ -134,23 +134,23 @@ public class Mapping : Properties.IMapping
return result;
}
public void UpdateMappingFromUnknownPerson(int? by, SortingContainer sortingContainer)
public void UpdateMappingFromUnknownPerson(SortingContainer sortingContainer)
{
_By = by;
_By = Stateless.IMapLogic.Sorting;
_SortingContainer = sortingContainer;
}
public void UpdateMappingFromPerson(int? approximateYears, int? by, string displayDirectoryName, PersonBirthday personBirthday, string segmentB)
public void UpdateMappingFromPerson(int? approximateYears, string displayDirectoryName, PersonBirthday personBirthday, string segmentB)
{
_By = by;
_SortingContainer = null;
_By = Stateless.IMapLogic.Mapping;
_MappingFromPerson = new(approximateYears, displayDirectoryName, personBirthday, segmentB);
}
public void UpdateMappingFromPerson(int? approximateYears, int? by, string displayDirectoryName, PersonBirthday personBirthday, string segmentB, string segmentC, SortingContainer sortingContainer)
public void UpdateMappingFromPerson(int? approximateYears, string displayDirectoryName, PersonBirthday personBirthday, string segmentB, string segmentC, SortingContainer sortingContainer)
{
_By = by;
_SegmentC = segmentC;
_By = Stateless.IMapLogic.Sorting;
_SortingContainer = sortingContainer;
_MappingFromPerson = new(approximateYears, displayDirectoryName, personBirthday, segmentB);
}

View File

@ -0,0 +1,13 @@
namespace View_by_Distance.Shared.Models.Stateless;
public interface IMapLogic
{ // ...
const int CopyNotMappedFaces = 5;
const int ForceSingleImage = 3;
const int ManualCopy = 4;
const int Mapping = 1;
const int Sigma = 3;
const int Sorting = 2;
}

View File

@ -21,7 +21,7 @@ public interface IAge
char[] TestStatic_GetChars() =>
GetChars();
static char[] GetChars() =>
new char[] { '!', '#', '^', '_', '`', '~', '+' };
new char[] { '!', '#', ']', '^', '_', '`', '~', '+' };
int? TestStatic_GetApproximateYears(string personDisplayDirectoryName, char[] chars) =>
GetApproximateYears(personDisplayDirectoryName, chars);

View File

@ -1,8 +1,15 @@
using System.Drawing;
namespace View_by_Distance.Shared.Models.Stateless.Methods;
public interface ILocation
{ // ...
Rectangle TestStatic_GetRectangle(Rectangle checkRectangle, int locationDigits, int locationFactor, int normalizedRectangle, Models.OutputResolution outputResolution, bool useOldWay) =>
GetRectangle(checkRectangle, locationDigits, locationFactor, normalizedRectangle, outputResolution, useOldWay);
static Rectangle GetRectangle(Rectangle checkRectangle, int locationDigits, int locationFactor, int normalizedRectangle, Models.OutputResolution outputResolution, bool useOldWay) =>
Location.GetRectangle(checkRectangle, locationDigits, locationFactor, normalizedRectangle, OutputResolution.Get(outputResolution).Height, OutputResolution.Get(outputResolution).Width, useOldWay);
string TestStatic_GetLeftPadded(int locationDigits, string value) =>
GetLeftPadded(locationDigits, value);
static string GetLeftPadded(int locationDigits, string value) =>
@ -33,11 +40,6 @@ public interface ILocation
static Models.Location? GetLocation(int factor, Models.Location? location, int locationDigits, int locationFactor, int height, int width, int zCount) =>
location is null ? null : new(location.Confidence, factor, height, location, locationDigits, locationFactor, width, zCount);
(int?, int?) TestStatic_GetCenterRoundedXY(int bottom, int height, int left, int locationFactor, int right, int top, int width) =>
GetCenterRoundedXY(bottom, height, left, locationFactor, right, top, width);
static (int?, int?) GetCenterRoundedXY(int bottom, int height, int left, int locationFactor, int right, int top, int width) =>
Location.GetCenterRoundedXY(bottom, height, left, locationFactor, right, top, width, zCount: 1);
(decimal?, decimal?, decimal?, decimal?) TestStatic_GetHeightLeftTopWidth(int bottom, int height, int left, int right, int top, int width) =>
GetHeightLeftTopWidth(bottom, height, left, right, top, width);
static (decimal?, decimal?, decimal?, decimal?) GetHeightLeftTopWidth(int bottom, int height, int left, int right, int top, int width) =>
@ -63,9 +65,9 @@ public interface ILocation
static int GetNormalizedRectangle(int bottom, int height, int left, int locationDigits, int right, int top, int width) =>
Location.GetNormalizedRectangle(bottom, height, left, locationDigits, right, top, width, zCount: 1);
Models.Location TestStatic_GetTrimBound(double detectionConfidence, System.Drawing.Rectangle rectangle, int width, int height, int facesCount) =>
Models.Location TestStatic_GetTrimBound(double detectionConfidence, Rectangle rectangle, int width, int height, int facesCount) =>
TrimBound(detectionConfidence, rectangle, width, height, facesCount);
static Models.Location TrimBound(double detectionConfidence, System.Drawing.Rectangle rectangle, int width, int height, int facesCount) =>
static Models.Location TrimBound(double detectionConfidence, Rectangle rectangle, int width, int height, int facesCount) =>
new(Math.Min(rectangle.Bottom, height),
detectionConfidence,
height,

View File

@ -28,14 +28,9 @@ public interface IMapping
static string GetDeterministicHashCodeKey(int id, Models.Location location, int locationDigits, Models.OutputResolution outputResolution)
=> $"{id}.{ILocation.GetLeftPadded(locationDigits, ILocation.GetNormalizedRectangle(location, locationDigits, outputResolution))}";
(int?, int?, List<Models.Mapping>?) TestStatic_GetConverted(string facesFileNameExtension, string file) =>
(int?, int?) TestStatic_GetConverted(string facesFileNameExtension, string file) =>
GetConverted(facesFileNameExtension, file);
static (int?, int?, List<Models.Mapping>?) GetConverted(string facesFileNameExtension, string file) =>
Mapping.GetConverted(facesFileNameExtension, false, new(), file);
(int?, int?, List<Models.Mapping>?) TestStatic_GetConverted(string facesFileNameExtension, bool idToMappingCollectionAny, Dictionary<int, List<Models.Mapping>> idToMappingCollection, string file) =>
GetConverted(facesFileNameExtension, idToMappingCollectionAny, idToMappingCollection, file);
static (int?, int?, List<Models.Mapping>?) GetConverted(string facesFileNameExtension, bool idToMappingCollectionAny, Dictionary<int, List<Models.Mapping>> idToMappingCollection, string file) =>
Mapping.GetConverted(facesFileNameExtension, idToMappingCollectionAny, idToMappingCollection, file);
static (int?, int?) GetConverted(string facesFileNameExtension, string file) =>
Mapping.GetConverted(facesFileNameExtension, file);
}

View File

@ -1,3 +1,5 @@
using System.Drawing;
namespace View_by_Distance.Shared.Models.Stateless.Methods;
internal abstract class Location
@ -76,29 +78,6 @@ internal abstract class Location
return result;
}
internal static (int?, int?) GetCenterRoundedXY(int bottom, int height, int left, int locationFactor, int right, int top, int width, int zCount)
{
(int?, int?) result;
bool verified = Check(bottom, height, left, right, top, width, zCount, throwException: false);
decimal center = 2m;
decimal factor = locationFactor;
decimal xCenterValue = (left + right) / center;
decimal yCenterValue = (top + bottom) / center;
if (xCenterValue < left || xCenterValue > right)
throw new Exception();
if (yCenterValue < top || yCenterValue > bottom)
throw new Exception();
decimal xCenterPercentageFactored = xCenterValue / width * factor;
decimal yCenterPercentageFactored = yCenterValue / height * factor;
int xCenterRounded = (int)Math.Round(xCenterPercentageFactored, 0);
int yCenterRounded = (int)Math.Round(yCenterPercentageFactored, 0);
if (!verified)
result = new(null, null);
else
result = new(xCenterRounded, yCenterRounded);
return result;
}
internal static int GetNormalizedRectangle(int bottom, int height, int left, int locationDigits, int right, int top, int width, int zCount)
{
int result;
@ -160,4 +139,54 @@ internal abstract class Location
int result = (int)(confidence / rangeFaceConfidence[1] * faceConfidencePercent);
return result;
}
private static Rectangle? GetRectangle(int locationDigits, int height, string normalizedRectangle, int width)
{
Rectangle? result;
int length = (locationDigits - 1) / 4;
string[] segments = new string[]
{
normalizedRectangle[..1],
normalizedRectangle.Substring(1, length),
normalizedRectangle.Substring(3, length),
normalizedRectangle.Substring(5, length),
normalizedRectangle.Substring(7, length)
};
if (string.Join(string.Empty, segments) != normalizedRectangle)
result = null;
else
{
if (!int.TryParse(segments[1], out int xNormalized) || !int.TryParse(segments[2], out int yNormalized) || !int.TryParse(segments[3], out int wNormalized) || !int.TryParse(segments[4], out int hNormalized))
result = null;
else
{
decimal factor = 100;
result = new((int)(xNormalized / factor * width), (int)(yNormalized / factor * height), (int)(wNormalized / factor * width), (int)(hNormalized / factor * height));
}
}
return result;
}
internal static Rectangle GetRectangle(Rectangle checkRectangle, int locationDigits, int locationFactor, int normalizedRectangleValue, int height, int width, bool useOldWay)
{
Rectangle? result;
string normalizedRectangle = normalizedRectangleValue.ToString();
if (normalizedRectangle.Length != locationDigits)
throw new NotImplementedException();
if (!useOldWay)
{
result = GetRectangle(locationDigits, height, normalizedRectangle, width);
if (result is null)
throw new NullReferenceException(nameof(result));
}
else
{
(int? x, int? y) = GetXY(locationDigits, locationFactor, width, height, normalizedRectangle);
if (x is null || y is null)
throw new Exception();
result = new(x.Value - (checkRectangle.Width / 2), y.Value - (checkRectangle.Height / 2), checkRectangle.Width, checkRectangle.Height);
}
return result.Value;
}
}

View File

@ -27,51 +27,42 @@ internal abstract class Mapping
return new(id, normalizedRectangle, extensionLowered, needsFacesFileNameExtension);
}
private static (int?, int?, List<Models.Mapping>?) GetConvertedsFromSegments(string facesFileNameExtension, bool idToMappingCollectionAny, Dictionary<int, List<Models.Mapping>> idToMappingCollection, string fileName)
private static (int?, int?) GetConvertedFromSegments(string facesFileNameExtension, string fileName)
{
int? id;
int? normalizedRectangle;
List<Models.Mapping>? mappingCollection;
(string? Id, string? NormalizedRectangle, string? ExtensionLowered, bool? Check) segments = GetSegments(facesFileNameExtension, fileName);
if (string.IsNullOrEmpty(segments.Id) || string.IsNullOrEmpty(segments.NormalizedRectangle) || string.IsNullOrEmpty(segments.ExtensionLowered) || segments.Check is null)
{
id = null;
mappingCollection = null;
normalizedRectangle = null;
}
else if (!int.TryParse(segments.Id, out int idValue) || !int.TryParse(segments.NormalizedRectangle, out int normalizedRectangleValue))
{
id = null;
mappingCollection = null;
normalizedRectangle = null;
}
else
{
id = idValue;
normalizedRectangle = normalizedRectangleValue;
if (!idToMappingCollectionAny || !idToMappingCollection.ContainsKey(idValue))
mappingCollection = null;
else
mappingCollection = idToMappingCollection[idValue];
}
return new(id, normalizedRectangle, mappingCollection);
return new(id, normalizedRectangle);
}
internal static (int?, int?, List<Models.Mapping>?) GetConverted(string facesFileNameExtension, bool idToMappingCollectionAny, Dictionary<int, List<Models.Mapping>> idToMappingCollection, string file)
internal static (int?, int?) GetConverted(string facesFileNameExtension, string file)
{
int? id;
int? normalizedRectangle;
List<Models.Mapping>? mappingCollection;
string fileName = Path.GetFileName(file);
if (fileName.Length >= 2 && !fileName[1..].Contains('-'))
(id, normalizedRectangle, mappingCollection) = GetConvertedsFromSegments(facesFileNameExtension, idToMappingCollectionAny, idToMappingCollection, fileName);
(id, normalizedRectangle) = GetConvertedFromSegments(facesFileNameExtension, fileName);
else
{
id = null;
mappingCollection = null;
normalizedRectangle = null;
}
return new(id, normalizedRectangle, mappingCollection);
return new(id, normalizedRectangle);
}
internal static int GetAreaPermille(int faceAreaPermille, int bottom, int height, int left, int right, int top, int width)

View File

@ -14,7 +14,7 @@ internal abstract class PersonContainer
{
if (personDisplayDirectoryAllFile.EndsWith(".lnk"))
continue;
(id, normalizedRectangle, _) = IMapping.GetConverted(facesFileNameExtension, personDisplayDirectoryAllFile);
(id, normalizedRectangle) = IMapping.GetConverted(facesFileNameExtension, personDisplayDirectoryAllFile);
if (id is not null && normalizedRectangle is not null && !personDisplayDirectoryAllFile.EndsWith(".json"))
continue;
checkDirectory = Path.GetDirectoryName(personDisplayDirectoryAllFile);