Mass push

This commit is contained in:
2022-12-16 11:26:00 -07:00
parent ae1baaaf46
commit 33c5ce6e23
132 changed files with 5869 additions and 3712 deletions

View File

@ -3,6 +3,93 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
internal abstract class Container
{
internal static double GetDefaultValue() => throw new Exception();
internal static DateTime[] GetContainerDateTimes(Models.Item[] filteredItems)
{
DateTime[] results;
DateTime? containerMinimumDateTime;
DateTime? containerMaximumDateTime;
containerMinimumDateTime = (from l in filteredItems select l.ImageFileHolder.LastWriteTime).Min();
if (containerMinimumDateTime is null)
containerMaximumDateTime = null;
else
containerMaximumDateTime = (from l in filteredItems select l.ImageFileHolder.LastWriteTime).Max();
if (containerMinimumDateTime is null || containerMaximumDateTime is null)
results = Array.Empty<DateTime>();
else
results = new DateTime[] { containerMinimumDateTime.Value, containerMaximumDateTime.Value };
return results;
}
internal static Models.Item[] GetFilterItems(Properties.IPropertyConfiguration propertyConfiguration, Models.Container container)
{
List<Models.Item> results = new();
foreach (Models.Item item in container.Items)
{
if (item.ImageFileHolder is not null
&& (item.Abandoned is null || !item.Abandoned.Value)
&& item.ValidImageFormatExtension
&& !propertyConfiguration.IgnoreExtensions.Contains(item.ImageFileHolder.ExtensionLowered))
results.Add(item);
}
return results.ToArray();
}
internal static bool IsIgnoreRelativePath(Properties.IPropertyConfiguration propertyConfiguration, string[] ignoreRelativePaths, string directory)
{
bool result = false;
string? checkDirectory = Path.GetFullPath(directory);
for (int i = 0; i < int.MaxValue; i++)
{
if (ignoreRelativePaths.Contains(Path.GetFileName(checkDirectory)))
{
result = true;
break;
}
checkDirectory = Path.GetDirectoryName(checkDirectory);
if (string.IsNullOrEmpty(checkDirectory) || checkDirectory == propertyConfiguration.RootDirectory)
break;
}
return result;
}
internal static Models.Container[] SortContainers(Properties.IPropertyConfiguration propertyConfiguration, string[] ignoreRelativePaths, bool argZeroIsConfigurationRootDirectory, string argZero, Models.Container[] containers)
{
List<Models.Container> results = new();
Models.Item[] filteredItems;
bool isIgnoreRelativePath;
List<int> collection = new();
for (int i = 1; i < 3; i++)
{
foreach (Models.Container container in containers)
{
if (!container.Items.Any())
continue;
if (!argZeroIsConfigurationRootDirectory && !container.SourceDirectory.StartsWith(argZero))
continue;
filteredItems = GetFilterItems(propertyConfiguration, container);
if (!filteredItems.Any())
continue;
isIgnoreRelativePath = ignoreRelativePaths.Any(l => container.SourceDirectory.Contains(l)) && IsIgnoreRelativePath(propertyConfiguration, ignoreRelativePaths, container.SourceDirectory);
if (i == 1 && isIgnoreRelativePath)
continue;
if (i == 2 && !isIgnoreRelativePath)
continue;
foreach (Models.Item item in filteredItems)
{
if (item.Property?.Id is null)
continue;
if (collection.Contains(item.Property.Id.Value))
{
if (i == 1)
continue;
continue;
}
collection.Add(item.Property.Id.Value);
}
results.Add(container);
}
}
return results.ToArray();
}
}

View File

@ -3,6 +3,129 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
internal abstract class FileHolder
{
internal static double GetDefaultValue() => throw new Exception();
internal static List<Models.FileHolder> GetFileHolders((string, string[])[] collection)
{
List<Models.FileHolder> results = new();
foreach ((string _, string[] files) in collection)
results.AddRange(files.Select(l => new Models.FileHolder(l)));
return results;
}
internal static IEnumerable<Models.FileHolder> GetFileHolders(IEnumerable<(string, string)> collection)
{
foreach ((string _, string file) in collection)
yield return new(file);
}
internal static IEnumerable<(string, string[])> GetFiles(string root, string searchPattern)
{
Stack<string> pending = new();
pending.Push(root);
while (pending.Count != 0)
{
string[]? next = null;
string path = pending.Pop();
try
{
next = Directory.GetFiles(path, searchPattern);
}
catch { }
if (next is not null && next.Any())
yield return new(path, next);
try
{
next = Directory.GetDirectories(path);
foreach (string subDirectory in next)
pending.Push(subDirectory);
}
catch { }
}
}
internal static (int t, List<(int g, string sourceDirectory, string[] sourceDirectoryFiles)>) GetGroupCollection(string rootDirectory, int maxImagesInDirectoryForTopLevelFirstPass, bool reverse, string searchPattern, List<string> topDirectories)
{
int result = 0;
List<(int g, string sourceDirectory, string[] sourceDirectoryFiles)> results = new();
string? parentDirectory;
string[] subDirectories;
string[] sourceDirectoryFiles;
List<string[]> fileCollections = new();
if (!topDirectories.Any())
{
if (!Directory.Exists(rootDirectory))
_ = Directory.CreateDirectory(rootDirectory);
topDirectories.AddRange(from l in Directory.GetDirectories(rootDirectory, "*", SearchOption.TopDirectoryOnly) select Path.GetFullPath(l));
}
for (int g = 1; g < 5; g++)
{
if (g == 4)
{
for (int i = fileCollections.Count - 1; i > -1; i--)
{
parentDirectory = Path.GetDirectoryName(fileCollections[i][0]);
if (string.IsNullOrEmpty(parentDirectory))
continue;
results.Add(new(g, parentDirectory, fileCollections[i]));
fileCollections.RemoveAt(i);
}
}
else if (g == 2)
{
for (int i = fileCollections.Count - 1; i > -1; i--)
{
if (fileCollections[i].Length > maxImagesInDirectoryForTopLevelFirstPass * g)
break;
parentDirectory = Path.GetDirectoryName(fileCollections[i][0]);
if (string.IsNullOrEmpty(parentDirectory))
continue;
results.Add(new(g, parentDirectory, fileCollections[i]));
fileCollections.RemoveAt(i);
}
}
else if (g == 3)
{
subDirectories = Directory.GetDirectories(rootDirectory, "*", SearchOption.AllDirectories);
if (reverse)
subDirectories = subDirectories.Reverse().ToArray();
foreach (string subDirectory in subDirectories)
{
sourceDirectoryFiles = Directory.GetFiles(subDirectory, "*", SearchOption.TopDirectoryOnly);
result += sourceDirectoryFiles.Length;
if (!topDirectories.Contains(subDirectory))
results.Add(new(g, subDirectory, sourceDirectoryFiles));
}
}
else if (g == 1)
{
sourceDirectoryFiles = Directory.GetFiles(rootDirectory, searchPattern, SearchOption.TopDirectoryOnly);
result += sourceDirectoryFiles.Length;
if (sourceDirectoryFiles.Length > maxImagesInDirectoryForTopLevelFirstPass)
fileCollections.Add(sourceDirectoryFiles);
else
results.Add(new(g, rootDirectory, sourceDirectoryFiles));
if (reverse)
topDirectories.Reverse();
subDirectories = topDirectories.ToArray();
foreach (string subDirectory in subDirectories)
{
sourceDirectoryFiles = Directory.GetFiles(subDirectory, searchPattern, SearchOption.TopDirectoryOnly);
result += sourceDirectoryFiles.Length;
if (sourceDirectoryFiles.Length > maxImagesInDirectoryForTopLevelFirstPass)
fileCollections.Add(sourceDirectoryFiles);
else
{
if (sourceDirectoryFiles.Any() || Directory.GetDirectories(subDirectory, "*", SearchOption.TopDirectoryOnly).Any())
results.Add(new(g, subDirectory, sourceDirectoryFiles));
else if (searchPattern == "*" && subDirectory != rootDirectory)
Directory.Delete(subDirectory);
}
}
fileCollections.Reverse();
}
else
throw new Exception();
}
return new(result, results);
}
}

View File

@ -1,10 +1,26 @@
namespace View_by_Distance.Shared.Models.Stateless.Methods;
public interface IContainer
{ // ...
{
double TestStatic_GetDefaultValue();
DateTime[] TestStatic_GetContainerDateTimes(Models.Item[] filteredItems) =>
GetContainerDateTimes(filteredItems);
static DateTime[] GetContainerDateTimes(Models.Item[] filteredItems) =>
Container.GetContainerDateTimes(filteredItems);
static double GetDefaultValue() => Container.GetDefaultValue();
Models.Item[] TestStatic_GetFilterItems(Properties.IPropertyConfiguration propertyConfiguration, Models.Container container) =>
GetFilterItems(propertyConfiguration, container);
static Models.Item[] GetFilterItems(Properties.IPropertyConfiguration propertyConfiguration, Models.Container container) =>
Container.GetFilterItems(propertyConfiguration, container);
bool TestStatic_IsIgnoreRelativePath(Properties.IPropertyConfiguration propertyConfiguration, string[] ignoreRelativePaths, string directory) =>
IsIgnoreRelativePath(propertyConfiguration, ignoreRelativePaths, directory);
static bool IsIgnoreRelativePath(Properties.IPropertyConfiguration propertyConfiguration, string[] ignoreRelativePaths, string directory) =>
Container.IsIgnoreRelativePath(propertyConfiguration, ignoreRelativePaths, directory);
Models.Container[] TestStatic_SortContainers(Properties.IPropertyConfiguration propertyConfiguration, string[] ignoreRelativePaths, bool argZeroIsConfigurationRootDirectory, string argZero, Models.Container[] containers) =>
SortContainers(propertyConfiguration, ignoreRelativePaths, argZeroIsConfigurationRootDirectory, argZero, containers);
static Models.Container[] SortContainers(Properties.IPropertyConfiguration propertyConfiguration, string[] ignoreRelativePaths, bool argZeroIsConfigurationRootDirectory, string argZero, Models.Container[] containers) =>
Container.SortContainers(propertyConfiguration, ignoreRelativePaths, argZeroIsConfigurationRootDirectory, argZero, containers);
}

View File

@ -1,9 +1,31 @@
namespace View_by_Distance.Shared.Models.Stateless.Methods;
public interface IFileHolder
{ // ...
{
Models.FileHolder TestStatic_Refresh();
static Models.FileHolder Refresh(Models.FileHolder fileHolder) => new(fileHolder.FullName);
IEnumerable<(string, string[])> TestStatic_GetFiles(string root, string searchPattern) =>
GetFiles(root, searchPattern);
static IEnumerable<(string, string[])> GetFiles(string root, string searchPattern) =>
FileHolder.GetFiles(root, searchPattern);
List<Models.FileHolder> TestStatic_GetFileHolders((string, string[])[] collection) =>
GetFileHolders(collection);
static List<Models.FileHolder> GetFileHolders((string, string[])[] collection) =>
FileHolder.GetFileHolders(collection);
IEnumerable<Models.FileHolder> TestStatic_GetFileHolders(IEnumerable<(string, string)> collection) =>
GetFileHolders(collection);
static IEnumerable<Models.FileHolder> GetFileHolders(IEnumerable<(string, string)> collection) =>
FileHolder.GetFileHolders(collection);
Models.FileHolder TestStatic_Refresh(Models.FileHolder fileHolder) =>
Refresh(fileHolder);
static Models.FileHolder Refresh(Models.FileHolder fileHolder) =>
new(fileHolder.FullName);
(int t, List<(int g, string sourceDirectory, string[] sourceDirectoryFiles)>) TestStatic_GetGroupCollection(string rootDirectory, int maxImagesInDirectoryForTopLevelFirstPass, bool reverse, string searchPattern, List<string> topDirectories) =>
GetGroupCollection(rootDirectory, maxImagesInDirectoryForTopLevelFirstPass, reverse, searchPattern, topDirectories);
static (int t, List<(int g, string sourceDirectory, string[] sourceDirectoryFiles)>) GetGroupCollection(string rootDirectory, int maxImagesInDirectoryForTopLevelFirstPass, bool reverse, string searchPattern, List<string> topDirectories) =>
FileHolder.GetGroupCollection(rootDirectory, maxImagesInDirectoryForTopLevelFirstPass, reverse, searchPattern, topDirectories);
}

View File

@ -18,10 +18,10 @@ public interface ILocation
static string GetLeftPadded(int locationDigits, int value) =>
GetLeftPadded(locationDigits, value.ToString());
(int?, int?) TestStatic_GetXY(int locationDigits, int locationFactor, int width, int height, string normalizedPixelPercentage) =>
GetXY(locationDigits, locationFactor, width, height, normalizedPixelPercentage);
static (int?, int?) GetXY(int locationDigits, int locationFactor, int width, int height, string normalizedPixelPercentage) =>
Location.GetXY(locationDigits, locationFactor, width, height, normalizedPixelPercentage);
(int?, int?) TestStatic_GetXY(int locationDigits, int locationFactor, int width, int height, string normalizedRectangle) =>
GetXY(locationDigits, locationFactor, width, height, normalizedRectangle);
static (int?, int?) GetXY(int locationDigits, int locationFactor, int width, int height, string normalizedRectangle) =>
Location.GetXY(locationDigits, locationFactor, width, height, normalizedRectangle);
Models.Location? TestStatic_GetLocation(Models.Location? location, int locationDigits, int locationFactor, int height, int width, int zCount) =>
GetLocation(location, locationDigits, locationFactor, height, width, zCount);
@ -33,15 +33,35 @@ 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 TestStatic_GetNormalizedPixelPercentage(Models.Location location, int locationDigits, int locationFactor, OutputResolution outputResolution) =>
GetNormalizedPixelPercentage(location, locationDigits, locationFactor, outputResolution);
static int GetNormalizedPixelPercentage(Models.Location location, int locationDigits, int locationFactor, OutputResolution outputResolution) =>
Location.GetNormalizedPixelPercentage(location.Bottom, outputResolution.Height, location.Left, locationDigits, locationFactor, location.Right, location.Top, outputResolution.Width, zCount: 1);
(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);
int TestStatic_GetNormalizedPixelPercentage(int bottom, int height, int left, int locationDigits, int locationFactor, int right, int top, int width) =>
GetNormalizedPixelPercentage(bottom, height, left, locationDigits, locationFactor, right, top, width);
static int GetNormalizedPixelPercentage(int bottom, int height, int left, int locationDigits, int locationFactor, int right, int top, int width) =>
Location.GetNormalizedPixelPercentage(bottom, height, left, locationDigits, 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) =>
Location.GetHeightLeftTopWidth(bottom, height, left, right, top, width, zCount: 1);
(decimal?, decimal?, decimal?, decimal?) TestStatic_GetHeightLeftTopWidth(int height, int left, int top, int width) =>
GetHeightLeftTopWidth(height, left, top, width);
static (decimal?, decimal?, decimal?, decimal?) GetHeightLeftTopWidth(int height, int left, int top, int width) =>
Location.GetHeightLeftTopWidth(top + height, height, left, left + width, top, width, zCount: 1);
(decimal?, decimal?, decimal?, decimal?) TestStatic_GetHeightLeftTopWidth(Models.Location location, Models.OutputResolution outputResolution) =>
GetHeightLeftTopWidth(location, outputResolution);
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_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);
Models.Location TestStatic_GetTrimBound(double detectionConfidence, System.Drawing.Rectangle rectangle, int width, int height, int facesCount) =>
TrimBound(detectionConfidence, rectangle, width, height, facesCount);

View File

@ -18,24 +18,24 @@ public interface IMapping
static int GetAreaPermille(int faceAreaPermille, int bottom, int height, int left, int right, int top, int width)
=> Mapping.GetAreaPermille(faceAreaPermille, bottom, height, left, right, top, width);
int TestStatic_GetAreaPermille(int faceAreaPermille, Models.Location location, OutputResolution outputResolution)
int TestStatic_GetAreaPermille(int faceAreaPermille, Models.Location location, Models.OutputResolution outputResolution)
=> GetAreaPermille(faceAreaPermille, location, outputResolution);
static int GetAreaPermille(int faceAreaPermille, Models.Location location, OutputResolution outputResolution)
static int GetAreaPermille(int faceAreaPermille, Models.Location location, Models.OutputResolution outputResolution)
=> Mapping.GetAreaPermille(faceAreaPermille, location.Bottom, outputResolution.Height, location.Left, location.Right, location.Top, outputResolution.Width);
string TestStatic_GetDeterministicHashCodeKey(int id, Models.Location location, int locationDigits, int locationFactor, OutputResolution outputResolution)
=> GetDeterministicHashCodeKey(id, location, locationDigits, locationFactor, outputResolution);
static string GetDeterministicHashCodeKey(int id, Models.Location location, int locationDigits, int locationFactor, OutputResolution outputResolution)
=> $"{id}.{ILocation.GetLeftPadded(locationDigits, ILocation.GetNormalizedPixelPercentage(location, locationDigits, locationFactor, outputResolution))}";
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))}";
(int?, int?, List<Models.Mapping>?) TestStatic_GetReversedDeterministicHashCodeKey(string facesFileNameExtension, string file) =>
GetReversedDeterministicHashCodeKey(facesFileNameExtension, file);
static (int?, int?, List<Models.Mapping>?) GetReversedDeterministicHashCodeKey(string facesFileNameExtension, string file) =>
Mapping.GetReversedDeterministicHashCodeKey(facesFileNameExtension, false, new(), file);
(int?, int?, List<Models.Mapping>?) 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_GetReversedDeterministicHashCodeKey(string facesFileNameExtension, bool idToMappingCollectionAny, Dictionary<int, List<Models.Mapping>> idToMappingCollection, string file) =>
GetReversedDeterministicHashCodeKey(facesFileNameExtension, idToMappingCollectionAny, idToMappingCollection, file);
static (int?, int?, List<Models.Mapping>?) GetReversedDeterministicHashCodeKey(string facesFileNameExtension, bool idToMappingCollectionAny, Dictionary<int, List<Models.Mapping>> idToMappingCollection, string file) =>
Mapping.GetReversedDeterministicHashCodeKey(facesFileNameExtension, idToMappingCollectionAny, idToMappingCollection, 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);
}

View File

@ -3,14 +3,19 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
public interface IMappingFromItem
{ // ...
MappingFromItem TestStatic_GetMappingFromItem(Models.Item item, Models.FileHolder? resizedFileHolder)
=> GetMappingFromItem(item, resizedFileHolder);
static MappingFromItem GetMappingFromItem(Models.Item item, Models.FileHolder? resizedFileHolder)
=> MappingFromItem.GetMappingFromItem(item, resizedFileHolder);
MappingFromItem TestStatic_GetMappingFromItem(DateTime[] containerDateTimes, Models.Item item, Models.FileHolder? resizedFileHolder)
=> GetMappingFromItem(containerDateTimes, item, resizedFileHolder);
static MappingFromItem GetMappingFromItem(DateTime[] containerDateTimes, Models.Item item, Models.FileHolder? resizedFileHolder)
=> MappingFromItem.GetMappingFromItem(containerDateTimes, item, resizedFileHolder);
MappingFromItem TestStatic_GetMappingFromItem(DateTime[] containerDateTimes, Models.Item item)
=> GetMappingFromItem(containerDateTimes, item);
static MappingFromItem GetMappingFromItem(DateTime[] containerDateTimes, Models.Item item)
=> GetMappingFromItem(containerDateTimes, item, item.ResizedFileHolder);
MappingFromItem TestStatic_GetMappingFromItem(Models.Item item)
=> GetMappingFromItem(item);
static MappingFromItem GetMappingFromItem(Models.Item item)
=> GetMappingFromItem(item, item.ResizedFileHolder);
=> GetMappingFromItem(containerDateTimes: Array.Empty<DateTime>(), item, item.ResizedFileHolder);
}

View File

@ -0,0 +1,16 @@
namespace View_by_Distance.Shared.Models.Stateless.Methods;
public interface IOutputResolution
{ // ...
int TestStatic_GetHeight(Models.OutputResolution outputResolution) =>
GetHeight(outputResolution);
static int GetHeight(Models.OutputResolution outputResolution) =>
OutputResolution.Get(outputResolution).Height;
int TestStatic_GetWidth(Models.OutputResolution outputResolution) =>
GetWidth(outputResolution);
static int GetWidth(Models.OutputResolution outputResolution) =>
OutputResolution.Get(outputResolution).Width;
}

View File

@ -3,37 +3,46 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
internal abstract class Location
{
internal static void Check(int bottom, int left, int right, int top, int zCount)
internal static bool Check(int bottom, int left, int right, int top, int zCount, bool throwException)
{
bool result = true;
if (left < 0)
throw new Exception();
result = false;
if (right < 0)
throw new Exception();
result = false;
if (right < left)
throw new Exception();
result = false;
if (top < 0)
throw new Exception();
result = false;
if (bottom < 0)
throw new Exception();
result = false;
if (bottom < top)
throw new Exception();
result = false;
if (zCount < 0)
result = false;
if (throwException && !result)
throw new Exception();
return result;
}
internal static void Check(int bottom, int height, int left, int right, int top, int width, int zCount)
internal static bool Check(int bottom, int height, int left, int right, int top, int width, int zCount, bool throwException)
{
bool result = true;
if (bottom > height)
throw new Exception();
result = false;
if (left > width)
throw new Exception();
result = false;
if (right > width)
throw new Exception();
result = false;
if (top > height)
throw new Exception();
result = false;
if (zCount < 0)
result = false;
if (result)
result = Check(bottom, left, right, top, zCount, throwException);
if (throwException && !result)
throw new Exception();
Check(bottom, left, right, top, zCount);
return result;
}
internal static string GetLeftPadded(int locationDigits, string value)
@ -48,54 +57,89 @@ internal abstract class Location
return result;
}
internal static int GetNormalizedPixelPercentage(int bottom, int height, int left, int locationDigits, int locationFactor, int right, int top, int width, int zCount)
internal static (decimal?, decimal?, decimal?, decimal?) GetHeightLeftTopWidth(int bottom, int height, int left, int right, int top, int width, int zCount)
{
int result;
Check(bottom, height, left, right, top, width, zCount);
long check;
int checksum;
(decimal?, decimal?, decimal?, decimal?) result;
bool verified = Check(bottom, height, left, right, top, width, zCount, throwException: false);
decimal t = top;
decimal l = left;
decimal w = right - l;
decimal h = bottom - t;
decimal xHeightPercentageFactored = h / height;
decimal xLeftPercentageFactored = l / width;
decimal xTopPercentageFactored = t / height;
decimal xWidthPercentageFactored = w / width;
if (!verified)
result = new(null, null, null, null);
else
result = new(xHeightPercentageFactored, xLeftPercentageFactored, xTopPercentageFactored, xWidthPercentageFactored);
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;
string yCenterPadded;
decimal factor = locationFactor;
// int.MaxPercentage = 21 4748 3647;
int length = (locationDigits - 1) / 2;
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();
if (xCenterValue > yCenterValue)
checksum = 1;
else
checksum = 2;
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 (yCenterRounded != factor)
yCenterPadded = ILocation.GetLeftPadded(length, yCenterRounded);
if (!verified)
result = new(null, null);
else
yCenterPadded = ILocation.GetLeftPadded(length, yCenterRounded - 1);
if (xCenterRounded != factor)
check = long.Parse(string.Concat(xCenterRounded, yCenterPadded, checksum));
else
check = long.Parse(string.Concat(xCenterRounded - 1, yCenterPadded, checksum));
if (check > int.MaxValue)
throw new Exception();
result = (int)check;
result = new(xCenterRounded, yCenterRounded);
return result;
}
internal static (int?, int?) GetXY(int locationDigits, int locationFactor, int width, int height, string normalizedPixelPercentage)
internal static int GetNormalizedRectangle(int bottom, int height, int left, int locationDigits, int right, int top, int width, int zCount)
{
int result;
string check;
bool verified = Check(bottom, height, left, right, top, width, zCount, throwException: false);
int checksum = left > top ? 4 : 8;
if (!verified)
check = string.Concat(checksum, new string('0', locationDigits - 1));
else
{
decimal factor = 100;
int factorMinusOne = (int)factor - 1;
// int.MaxPercentage = 21 47 48 36 47;
int length = (locationDigits - 1) / 4;
// Rectangle rectangle=new(x, y, width, h);
decimal x = left / (decimal)width * factor;
decimal y = top / (decimal)height * factor;
decimal w = (right - left) / (decimal)width * factor;
decimal h = (bottom - top) / (decimal)height * factor;
string xPadded = x < factor ? ILocation.GetLeftPadded(length, (int)x) : ILocation.GetLeftPadded(length, factorMinusOne);
string yPadded = y < factor ? ILocation.GetLeftPadded(length, (int)y) : ILocation.GetLeftPadded(length, factorMinusOne);
string widthPadded = w < factor ? ILocation.GetLeftPadded(length, (int)w) : ILocation.GetLeftPadded(length, factorMinusOne);
string heightPadded = h < factor ? ILocation.GetLeftPadded(length, (int)h) : ILocation.GetLeftPadded(length, factorMinusOne);
check = string.Concat(checksum, xPadded, yPadded, widthPadded, heightPadded);
}
long value = long.Parse(check);
if (value > int.MaxValue)
throw new Exception();
result = (int)value;
return result;
}
internal static (int?, int?) GetXY(int locationDigits, int locationFactor, int width, int height, string normalizedRectangle)
{
int? x;
int? y;
int center = 2;
decimal factor = locationFactor;
int each = (locationDigits - 1) / center;
string segmentA = normalizedPixelPercentage[..each];
string segmentB = normalizedPixelPercentage[each..^1];
string segmentA = normalizedRectangle[..each];
string segmentB = normalizedRectangle[each..^1];
if (!int.TryParse(segmentA, out int xNormalized) || !int.TryParse(segmentB, out int yNormalized))
{
x = null;

View File

@ -9,69 +9,69 @@ internal abstract class Mapping
string? id;
string? extensionLowered;
bool? needsFacesFileNameExtension;
string? normalizedPixelPercentage;
string? normalizedRectangle;
if (segments.Length < 4 || $".{segments[3]}" != facesFileNameExtension)
{
id = null;
extensionLowered = null;
normalizedPixelPercentage = null;
normalizedRectangle = null;
needsFacesFileNameExtension = null;
}
else
{
id = segments[0];
extensionLowered = $".{segments[2]}";
normalizedPixelPercentage = segments[1];
normalizedRectangle = segments[1];
needsFacesFileNameExtension = segments.Length == 3;
}
return new(id, normalizedPixelPercentage, extensionLowered, needsFacesFileNameExtension);
return new(id, normalizedRectangle, extensionLowered, needsFacesFileNameExtension);
}
private static (int?, int?, List<Models.Mapping>?) GetReversedDeterministicHashCodeKeysFromSegments(string facesFileNameExtension, bool idToMappingCollectionAny, Dictionary<int, List<Models.Mapping>> idToMappingCollection, string fileName)
private static (int?, int?, List<Models.Mapping>?) GetConvertedsFromSegments(string facesFileNameExtension, bool idToMappingCollectionAny, Dictionary<int, List<Models.Mapping>> idToMappingCollection, string fileName)
{
int? id;
int? normalizedPixelPercentage;
int? normalizedRectangle;
List<Models.Mapping>? mappingCollection;
(string? Id, string? NormalizedPixelPercentage, string? ExtensionLowered, bool? Check) segments = GetSegments(facesFileNameExtension, fileName);
if (string.IsNullOrEmpty(segments.Id) || string.IsNullOrEmpty(segments.NormalizedPixelPercentage) || string.IsNullOrEmpty(segments.ExtensionLowered) || segments.Check is null)
(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;
normalizedPixelPercentage = null;
normalizedRectangle = null;
}
else if (!int.TryParse(segments.Id, out int idValue) || !int.TryParse(segments.NormalizedPixelPercentage, out int normalizedPixelPercentageValue))
else if (!int.TryParse(segments.Id, out int idValue) || !int.TryParse(segments.NormalizedRectangle, out int normalizedRectangleValue))
{
id = null;
mappingCollection = null;
normalizedPixelPercentage = null;
normalizedRectangle = null;
}
else
{
id = idValue;
normalizedPixelPercentage = normalizedPixelPercentageValue;
normalizedRectangle = normalizedRectangleValue;
if (!idToMappingCollectionAny || !idToMappingCollection.ContainsKey(idValue))
mappingCollection = null;
else
mappingCollection = idToMappingCollection[idValue];
}
return new(id, normalizedPixelPercentage, mappingCollection);
return new(id, normalizedRectangle, mappingCollection);
}
internal static (int?, int?, List<Models.Mapping>?) GetReversedDeterministicHashCodeKey(string facesFileNameExtension, bool idToMappingCollectionAny, Dictionary<int, List<Models.Mapping>> idToMappingCollection, string file)
internal static (int?, int?, List<Models.Mapping>?) GetConverted(string facesFileNameExtension, bool idToMappingCollectionAny, Dictionary<int, List<Models.Mapping>> idToMappingCollection, string file)
{
int? id;
int? normalizedPixelPercentage;
int? normalizedRectangle;
List<Models.Mapping>? mappingCollection;
string fileName = Path.GetFileName(file);
if (fileName.Length < 2 || fileName[1..].Contains('-'))
if (fileName.Length >= 2 && !fileName[1..].Contains('-'))
(id, normalizedRectangle, mappingCollection) = GetConvertedsFromSegments(facesFileNameExtension, idToMappingCollectionAny, idToMappingCollection, fileName);
else
{
id = null;
mappingCollection = null;
normalizedPixelPercentage = null;
normalizedRectangle = null;
}
else
(id, normalizedPixelPercentage, mappingCollection) = GetReversedDeterministicHashCodeKeysFromSegments(facesFileNameExtension, idToMappingCollectionAny, idToMappingCollection, fileName);
return new(id, normalizedPixelPercentage, mappingCollection);
return new(id, normalizedRectangle, mappingCollection);
}
internal static int GetAreaPermille(int faceAreaPermille, int bottom, int height, int left, int right, int top, int width)

View File

@ -0,0 +1,28 @@
namespace View_by_Distance.Shared.Models.Stateless.Methods;
internal abstract class OutputResolution
{
internal static (int Width, int Height) Get(Models.OutputResolution outputResolution)
{
// (int, int) result = outputResolution.Orientation switch // exif 274
// {
// 0 => new(outputResolution.Width, outputResolution.Height),
// 1 => new(outputResolution.Width, outputResolution.Height), // 1 = Horizontal (normal)
// 2 => new(outputResolution.Width, outputResolution.Height), // 2 = Mirror horizontal
// 3 => new(outputResolution.Width, outputResolution.Height), // 3 = Rotate 180
// 4 => new(outputResolution.Width, outputResolution.Height), // 4 = Mirror vertical
// 5 => new(outputResolution.Height, outputResolution.Width), // 5 = Mirror horizontal and rotate 270 CW
// 6 => new(outputResolution.Height, outputResolution.Width), // 6 = Rotate 90 CW
// 7 => new(outputResolution.Height, outputResolution.Width), // 7 = Mirror horizontal and rotate 90 CW
// 8 => new(outputResolution.Height, outputResolution.Width), // 8 = Rotate 270 CW
// _ => throw new Exception()
// };
(int, int) result = outputResolution.Orientation switch // exif 274
{
_ => new(outputResolution.Width, outputResolution.Height)
};
return result;
}
}

View File

@ -9,13 +9,13 @@ internal abstract class PersonContainer
int? id;
string checkFile;
string? checkDirectory;
int? normalizedPixelPercentage;
int? normalizedRectangle;
foreach (string personDisplayDirectoryAllFile in results)
{
if (personDisplayDirectoryAllFile.EndsWith(".lnk"))
continue;
(id, normalizedPixelPercentage, _) = IMapping.GetReversedDeterministicHashCodeKey(facesFileNameExtension, personDisplayDirectoryAllFile);
if (id is not null && normalizedPixelPercentage is not null && !personDisplayDirectoryAllFile.EndsWith(".json"))
(id, normalizedRectangle, _) = IMapping.GetConverted(facesFileNameExtension, personDisplayDirectoryAllFile);
if (id is not null && normalizedRectangle is not null && !personDisplayDirectoryAllFile.EndsWith(".json"))
continue;
checkDirectory = Path.GetDirectoryName(personDisplayDirectoryAllFile);
if (string.IsNullOrEmpty(checkDirectory))

View File

@ -99,12 +99,18 @@ internal abstract class Property
string format;
string fullFormat;
StringBuilder value = new();
const string ticksExample = "##################";
string[][] dateFormats = new string[][]
{
new string[] { string.Empty, "yyyyMMdd_HHmmss", string.Empty },
new string[] { string.Empty, "yyyyMMddHHmmssfff", string.Empty },
new string[] { string.Empty, "yyyyMMdd_", ticksExample },
new string[] { string.Empty, "yyyy-MM-dd_", ticksExample },
new string[] { string.Empty, "yyyy-MM-dd.", ticksExample },
new string[] { string.Empty, "yyyy-MM-dd HH.mm.ss", string.Empty },
new string[] { string.Empty, "yyyyMMdd_HHmmss", "_LLS" },
new string[] { string.Empty, "yyyyMMdd_HHmmss", "_HDR" },
new string[] { "WIN_", "yyyyMMdd_HH_mm_ss", "_Pro" },
new string[] { "IMG_", "yyyyMMdd_HHmmss", string.Empty },
new string[] { "IMG#####-", "yyyyMMdd-HHmm", string.Empty },
new string[] { "CameraZOOM-", "yyyyMMddHHmmss", string.Empty },
@ -113,6 +119,8 @@ internal abstract class Property
foreach (string[] dateFormat in dateFormats)
{
_ = value.Clear();
if (dateFormat.Length != 3)
throw new Exception();
fullFormat = string.Join(string.Empty, dateFormat);
if (fileHolder.NameWithoutExtension.Length != fullFormat.Length)
continue;
@ -124,7 +132,10 @@ internal abstract class Property
continue;
if (DateTime.TryParseExact(value.ToString(), format, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime checkDateTime))
{
result = checkDateTime;
if (fileHolder.NameWithoutExtension.Length < ticksExample.Length || !long.TryParse(fileHolder.NameWithoutExtension[^ticksExample.Length..], out long ticks))
result = checkDateTime;
else
result = new DateTime(ticks);
break;
}
}

View File

@ -8,7 +8,7 @@ internal abstract class Sorting
Models.Sorting result;
if (faceDistanceLength.Length is null)
throw new NotSupportedException();
if (faceDistanceLength.NormalizedPixelPercentage is null)
if (faceDistanceLength.NormalizedRectangle is null)
throw new NotSupportedException();
if (faceDistanceEncoding.MinimumDateTime is null || faceDistanceLength.MinimumDateTime is null)
throw new NotSupportedException();
@ -33,7 +33,7 @@ internal abstract class Sorting
}
}
int withinRange = withinRanges.Max();
result = new(daysDelta, distancePermyriad, faceDistanceLength.Id, faceDistanceLength.NormalizedPixelPercentage.Value, older, withinRange);
result = new(daysDelta, distancePermyriad, faceDistanceLength.Id, faceDistanceLength.NormalizedRectangle.Value, older, withinRange);
return result;
}