WholePercentages

This commit is contained in:
2023-06-21 07:24:32 -07:00
parent 8863fd763f
commit 1d0506d74c
22 changed files with 254 additions and 255 deletions

View File

@ -10,10 +10,10 @@ public interface ILocation
static Models.Location? GetLocation(int height, Rectangle rectangle, int width) =>
Location.GetLocation(height, rectangle, width);
List<Models.Face> TestStatic_FilterByIntersect(Models.Face[] faces, int normalizedRectangle, float rectangleIntersectMinimum) =>
FilterByIntersect(faces, normalizedRectangle, rectangleIntersectMinimum);
static List<Models.Face> FilterByIntersect(Models.Face[] faces, int normalizedRectangle, float rectangleIntersectMinimum) =>
Location.FilterByIntersect(faces, normalizedRectangle, rectangleIntersectMinimum);
List<Models.Face> TestStatic_FilterByIntersect(Models.Face[] faces, float rectangleIntersectMinimum, int wholePercentages) =>
FilterByIntersect(faces, rectangleIntersectMinimum, wholePercentages);
static List<Models.Face> FilterByIntersect(Models.Face[] faces, float rectangleIntersectMinimum, int wholePercentages) =>
Location.FilterByIntersect(faces, rectangleIntersectMinimum, wholePercentages);
Rectangle? TestStatic_GetRectangle(DatabaseFile databaseFile, Marker marker, Models.OutputResolution outputResolution) =>
GetRectangle(databaseFile, marker, outputResolution);
@ -30,15 +30,15 @@ public interface ILocation
static List<Models.Location> GetLocations<T>(List<MappingFromPhotoPrism> mappingFromPhotoPrismCollection, List<Models.Face> faces, List<LocationContainer<T>> containers) =>
Location.GetLocations(mappingFromPhotoPrismCollection, faces, containers);
Rectangle? TestStatic_GetNormalizedRectangle(int locationDigits, int normalizedRectangle) =>
GetNormalizedRectangle(locationDigits, normalizedRectangle);
static Rectangle? GetNormalizedRectangle(int locationDigits, int normalizedRectangle) =>
Location.GetNormalizedRectangle(locationDigits, normalizedRectangle.ToString());
Rectangle? TestStatic_GetWholePercentages(int locationDigits, int wholePercentages) =>
GetWholePercentages(locationDigits, wholePercentages);
static Rectangle? GetWholePercentages(int locationDigits, int wholePercentages) =>
Location.GetWholePercentages(locationDigits, wholePercentages.ToString());
Rectangle? TestStatic_GetRectangle(int locationDigits, int normalizedRectangle, Models.OutputResolution outputResolution) =>
GetRectangle(locationDigits, normalizedRectangle, outputResolution);
static Rectangle? GetRectangle(int locationDigits, int normalizedRectangle, Models.OutputResolution outputResolution) =>
Location.GetRectangle(locationDigits, normalizedRectangle.ToString(), outputResolution);
Rectangle? TestStatic_GetRectangle(int locationDigits, Models.OutputResolution outputResolution, int wholePercentages) =>
GetRectangle(locationDigits, outputResolution, wholePercentages);
static Rectangle? GetRectangle(int locationDigits, Models.OutputResolution outputResolution, int wholePercentages) =>
Location.GetRectangle(locationDigits, outputResolution, wholePercentages.ToString());
string TestStatic_GetLeftPadded(int locationDigits, string value) =>
GetLeftPadded(locationDigits, value);
@ -80,20 +80,20 @@ public interface ILocation
static (decimal?, decimal?, decimal?, decimal?) GetHeightLeftTopWidth(Models.Location location, Models.OutputResolution outputResolution) =>
Location.GetHeightLeftTopWidth(location.Bottom, OutputResolution.Get(outputResolution).Height, location.Left, location.Right, location.Top, OutputResolution.Get(outputResolution).Width, zCount: 1);
int TestStatic_GetNormalizedRectangle(Models.Location location, int locationDigits, Models.OutputResolution outputResolution) =>
GetNormalizedRectangle(location, locationDigits, outputResolution);
static int GetNormalizedRectangle(Models.Location location, int locationDigits, Models.OutputResolution outputResolution) =>
Location.GetNormalizedRectangle(location.Bottom, OutputResolution.Get(outputResolution).Height, location.Left, locationDigits, location.Right, location.Top, OutputResolution.Get(outputResolution).Width, zCount: 1);
int TestStatic_GetWholePercentages(Models.Location location, int locationDigits, Models.OutputResolution outputResolution) =>
GetWholePercentages(location, locationDigits, outputResolution);
static int GetWholePercentages(Models.Location location, int locationDigits, Models.OutputResolution outputResolution) =>
Location.GetWholePercentages(location.Bottom, OutputResolution.Get(outputResolution).Height, location.Left, locationDigits, location.Right, location.Top, OutputResolution.Get(outputResolution).Width, zCount: 1);
int TestStatic_GetNormalizedRectangle(int locationDigits) =>
GetNormalizedRectangle(locationDigits);
static int GetNormalizedRectangle(int locationDigits) =>
Location.GetNormalizedRectangle(1, 1, 0, locationDigits, 1, 0, 1, zCount: 1);
int TestStatic_GetWholePercentages(int locationDigits) =>
GetWholePercentages(locationDigits);
static int GetWholePercentages(int locationDigits) =>
Location.GetWholePercentages(1, 1, 0, locationDigits, 1, 0, 1, zCount: 1);
int TestStatic_GetNormalizedRectangle(int bottom, int height, int left, int locationDigits, int right, int top, int width) =>
GetNormalizedRectangle(bottom, height, left, locationDigits, right, top, width);
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);
int TestStatic_GetWholePercentages(int bottom, int height, int left, int locationDigits, int right, int top, int width) =>
GetWholePercentages(bottom, height, left, locationDigits, right, top, width);
static int GetWholePercentages(int bottom, int height, int left, int locationDigits, int right, int top, int width) =>
Location.GetWholePercentages(bottom, height, left, locationDigits, right, top, width, zCount: 1);
Models.Location TestStatic_GetTrimBound(double detectionConfidence, Rectangle rectangle, int width, int height, int facesCount) =>
TrimBound(detectionConfidence, rectangle, width, height, facesCount);

View File

@ -26,12 +26,12 @@ public interface IMapping
string TestStatic_GetDeterministicHashCodeKey(int id, Models.Location location, int locationDigits, Models.OutputResolution outputResolution)
=> GetDeterministicHashCodeKey(id, location, locationDigits, outputResolution);
static string GetDeterministicHashCodeKey(int id, Models.Location location, int locationDigits, Models.OutputResolution outputResolution)
=> $"{id}.{ILocation.GetLeftPadded(locationDigits, ILocation.GetNormalizedRectangle(location, locationDigits, outputResolution))}";
=> $"{id}.{ILocation.GetLeftPadded(locationDigits, ILocation.GetWholePercentages(location, locationDigits, outputResolution))}";
string TestStatic_GetDeterministicHashCodeKey(int id, int locationDigits)
=> GetDeterministicHashCodeKey(id, locationDigits);
static string GetDeterministicHashCodeKey(int id, int locationDigits)
=> $"{id}.{ILocation.GetLeftPadded(locationDigits, ILocation.GetNormalizedRectangle(locationDigits))}";
=> $"{id}.{ILocation.GetLeftPadded(locationDigits, ILocation.GetWholePercentages(locationDigits))}";
(int?, int?) TestStatic_GetConverted(string facesFileNameExtension, string file) =>
GetConverted(facesFileNameExtension, file);

View File

@ -78,7 +78,7 @@ internal abstract class Location
return result;
}
internal static int GetNormalizedRectangle(int bottom, int height, int left, int locationDigits, int right, int top, int width, int zCount)
internal static int GetWholePercentages(int bottom, int height, int left, int locationDigits, int right, int top, int width, int zCount)
{
int result;
string check;
@ -114,34 +114,37 @@ internal abstract class Location
return result;
}
internal static Rectangle? GetNormalizedRectangle(int locationDigits, string normalizedRectangle)
internal static Rectangle? GetWholePercentages(int locationDigits, string wholePercentages)
{
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)
wholePercentages[..1],
wholePercentages.Substring(1, length),
wholePercentages.Substring(3, length),
wholePercentages.Substring(5, length),
wholePercentages.Substring(7, length)
};
if (string.Join(string.Empty, segments) != normalizedRectangle)
if (string.Join(string.Empty, segments) != wholePercentages)
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))
if (!int.TryParse(segments[1], out int xWholePercent) || !int.TryParse(segments[2], out int yWholePercent) || !int.TryParse(segments[3], out int wWholePercent) || !int.TryParse(segments[4], out int hWholePercent))
result = null;
else
result = new(xNormalized, yNormalized, wNormalized, hNormalized);
result = new(xWholePercent, yWholePercent, wWholePercent, hWholePercent);
}
return result;
}
internal static Rectangle? GetRectangle(int height, int locationDigits, string normalizedRectangle, int width)
internal static Rectangle? GetRectangle(int locationDigits, Models.OutputResolution outputResolution, string wholePercentages)
{
Rectangle? result;
Rectangle? rectangle = GetNormalizedRectangle(locationDigits, normalizedRectangle);
if (wholePercentages.Length != locationDigits || wholePercentages[0] is not '4' and not '8')
throw new NotSupportedException("Old way has been removed!");
(int width, int height) = OutputResolution.Get(outputResolution);
Rectangle? rectangle = GetWholePercentages(locationDigits, wholePercentages);
if (rectangle is null)
result = null;
else
@ -149,16 +152,6 @@ internal abstract class Location
decimal factor = 100;
result = new((int)(rectangle.Value.X / factor * width), (int)(rectangle.Value.Y / factor * height), (int)(rectangle.Value.Width / factor * width), (int)(rectangle.Value.Height / factor * height));
}
return result;
}
internal static Rectangle? GetRectangle(int locationDigits, string normalizedRectangle, Models.OutputResolution outputResolution)
{
Rectangle? result;
if (normalizedRectangle.Length != locationDigits || normalizedRectangle[0] is not '4' and not '8')
throw new NotSupportedException("Old way has been removed!");
(int width, int height) = OutputResolution.Get(outputResolution);
result = GetRectangle(height, locationDigits, normalizedRectangle, width);
if (result is null)
throw new NullReferenceException(nameof(result));
return result;
@ -290,7 +283,12 @@ internal abstract class Location
return results;
}
internal static List<Models.Face> FilterByIntersect(Models.Face[] faces, int normalizedRectangle, float rectangleIntersectMinimum)
// private static double GP(OutputResolution outputResolution,Location location, ){
// double result;
// return result;
// }
internal static List<Models.Face> FilterByIntersect(Models.Face[] faces, float rectangleIntersectMinimum, int wholePercentages)
{
List<Models.Face> results = new();
double? percent;
@ -302,7 +300,7 @@ internal abstract class Location
if (face.Location is null || face.OutputResolution is null)
continue;
checkRectangle = new(face.Location.Left, face.Location.Top, face.Location.Right - face.Location.Left, face.Location.Bottom - face.Location.Top);
sourceRectangle = GetRectangle(Stateless.ILocation.Digits, normalizedRectangle.ToString(), face.OutputResolution);
sourceRectangle = GetRectangle(Stateless.ILocation.Digits, face.OutputResolution, wholePercentages.ToString());
if (sourceRectangle is null)
continue;
intersectRectangle = Rectangle.Intersect(checkRectangle, sourceRectangle.Value);

View File

@ -8,61 +8,61 @@ internal abstract class Mapping
string[] segments = fileName.Split('.');
string? id;
string? extensionLowered;
string? wholePercentages;
bool? needsFacesFileNameExtension;
string? normalizedRectangle;
if (segments.Length < 4 || $".{segments[3]}" != facesFileNameExtension)
{
id = null;
extensionLowered = null;
normalizedRectangle = null;
wholePercentages = null;
needsFacesFileNameExtension = null;
}
else
{
id = segments[0];
extensionLowered = $".{segments[2]}";
normalizedRectangle = segments[1];
wholePercentages = segments[1];
needsFacesFileNameExtension = segments.Length == 3;
}
return new(id, normalizedRectangle, extensionLowered, needsFacesFileNameExtension);
return new(id, wholePercentages, extensionLowered, needsFacesFileNameExtension);
}
private static (int?, int?) GetConvertedFromSegments(string facesFileNameExtension, string fileName)
{
int? id;
int? normalizedRectangle;
(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)
int? wholePercentages;
(string? Id, string? WholePercentages, string? ExtensionLowered, bool? Check) segments = GetSegments(facesFileNameExtension, fileName);
if (string.IsNullOrEmpty(segments.Id) || string.IsNullOrEmpty(segments.WholePercentages) || string.IsNullOrEmpty(segments.ExtensionLowered) || segments.Check is null)
{
id = null;
normalizedRectangle = null;
wholePercentages = null;
}
else if (!int.TryParse(segments.Id, out int idValue) || !int.TryParse(segments.NormalizedRectangle, out int normalizedRectangleValue))
else if (!int.TryParse(segments.Id, out int idValue) || !int.TryParse(segments.WholePercentages, out int wholePercentagesValue))
{
id = null;
normalizedRectangle = null;
wholePercentages = null;
}
else
{
id = idValue;
normalizedRectangle = normalizedRectangleValue;
wholePercentages = wholePercentagesValue;
}
return new(id, normalizedRectangle);
return new(id, wholePercentages);
}
internal static (int?, int?) GetConverted(string facesFileNameExtension, string file)
{
int? id;
int? normalizedRectangle;
int? wholePercentages;
string fileName = Path.GetFileName(file);
if (fileName.Length >= 2 && !fileName[1..].Contains('-'))
(id, normalizedRectangle) = GetConvertedFromSegments(facesFileNameExtension, fileName);
(id, wholePercentages) = GetConvertedFromSegments(facesFileNameExtension, fileName);
else
{
id = null;
normalizedRectangle = null;
wholePercentages = null;
}
return new(id, normalizedRectangle);
return new(id, wholePercentages);
}
internal static int GetAreaPermyriad(int faceAreaPermyriad, int bottom, int height, int left, int right, int top, int width)

View File

@ -64,15 +64,15 @@ internal abstract class PersonContainer
string[] results;
int? id;
string checkFile;
int? wholePercentages;
string? checkDirectory;
int? normalizedRectangle;
string[] files = Directory.GetFiles(personDisplayDirectory, "*", SearchOption.TopDirectoryOnly);
foreach (string file in files)
{
if (file.EndsWith(".lnk"))
continue;
(id, normalizedRectangle) = IMapping.GetConverted(facesFileNameExtension, file);
if (id is not null && normalizedRectangle is not null)
(id, wholePercentages) = IMapping.GetConverted(facesFileNameExtension, file);
if (id is not null && wholePercentages is not null)
continue;
checkDirectory = Path.GetDirectoryName(file);
if (string.IsNullOrEmpty(checkDirectory))

View File

@ -8,13 +8,13 @@ internal abstract class Sorting
Models.Sorting result;
if (faceDistanceLength.Length is null)
throw new NotSupportedException();
if (faceDistanceLength.NormalizedRectangle is null)
if (faceDistanceLength.WholePercentages is null)
throw new NotSupportedException();
TimeSpan timeSpan = new(faceDistanceLength.DateTimeOriginalThenMinimumDateTime.Ticks - faceDistanceEncoding.DateTimeOriginalThenMinimumDateTime.Ticks);
bool older = timeSpan.TotalMilliseconds < 0;
int daysDelta = (int)Math.Round(Math.Abs(timeSpan.TotalDays), 0);
int distancePermyriad = (int)(faceDistanceLength.Length.Value / rangeDistanceTolerance * faceDistancePermyriad);
result = new(daysDelta, distancePermyriad, faceDistanceLength.Id, faceDistanceLength.NormalizedRectangle.Value, older);
result = new(daysDelta, distancePermyriad, faceDistanceLength.Id, older, faceDistanceLength.WholePercentages.Value);
return result;
}