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

@ -12,10 +12,10 @@ public record class FaceDistance : Properties.IFaceDistance
public bool? IsWrongYear { init; get; }
public double? Length { init; get; }
public DateTime? MinimumDateTime { init; get; }
public int? NormalizedPixelPercentage { init; get; }
public int? NormalizedRectangle { init; get; }
[JsonConstructor]
public FaceDistance(int? confidencePercent, object? encoding, int id, bool? isWrongYear, double? length, DateTime? minimumDateTime, int? normalizedPixelPercentage)
public FaceDistance(int? confidencePercent, object? encoding, int id, bool? isWrongYear, double? length, DateTime? minimumDateTime, int? normalizedRectangle)
{
ConfidencePercent = confidencePercent;
Encoding = encoding;
@ -23,15 +23,15 @@ public record class FaceDistance : Properties.IFaceDistance
IsWrongYear = isWrongYear;
Length = length;
MinimumDateTime = minimumDateTime;
NormalizedPixelPercentage = normalizedPixelPercentage;
NormalizedRectangle = normalizedRectangle;
}
public FaceDistance(int? confidencePercent, object? encoding, int id, bool? isWrongYear, DateTime? minimumDateTime, int? normalizedPixelPercentage) :
this(confidencePercent, encoding, id, isWrongYear, null, minimumDateTime, normalizedPixelPercentage)
public FaceDistance(int? confidencePercent, object? encoding, int id, bool? isWrongYear, DateTime? minimumDateTime, int? normalizedRectangle) :
this(confidencePercent, encoding, id, isWrongYear, null, minimumDateTime, normalizedRectangle)
{ }
public FaceDistance(FaceDistance faceDistance, double length) :
this(faceDistance.ConfidencePercent, null, faceDistance.Id, faceDistance.IsWrongYear, length, faceDistance.MinimumDateTime, faceDistance.NormalizedPixelPercentage)
this(faceDistance.ConfidencePercent, null, faceDistance.Id, faceDistance.IsWrongYear, length, faceDistance.MinimumDateTime, faceDistance.NormalizedRectangle)
{ }
public FaceDistance(object encoding) => Encoding = encoding;

View File

@ -10,6 +10,7 @@ public class FileHolder : Properties.IFileHolder
protected readonly bool _Exists;
protected readonly string _ExtensionLowered;
protected readonly string _FullName;
protected readonly int? _Id;
protected readonly DateTime? _LastWriteTime;
protected readonly long? _Length;
protected readonly string _Name;
@ -19,25 +20,27 @@ public class FileHolder : Properties.IFileHolder
public bool Exists => _Exists;
public string ExtensionLowered => _ExtensionLowered;
public string FullName => _FullName;
public int? Id => _Id;
public DateTime? LastWriteTime => _LastWriteTime;
public long? Length => _Length;
public string Name => _Name;
public string NameWithoutExtension => _NameWithoutExtension;
public FileHolder(DateTime? creationTime, string? directoryName, bool exists, string extensionLowered, string fullName, DateTime? lastWriteTime, long? length, string name, string nameWithoutExtension)
public FileHolder(DateTime? creationTime, string? directoryName, bool exists, string extensionLowered, string fullName, int? id, DateTime? lastWriteTime, long? length, string name, string nameWithoutExtension)
{
_CreationTime = creationTime;
_DirectoryName = directoryName;
_Exists = exists;
_ExtensionLowered = extensionLowered;
_FullName = fullName;
_Id = id;
_LastWriteTime = lastWriteTime;
_Length = length;
_Name = name;
_NameWithoutExtension = nameWithoutExtension;
}
public FileHolder(FileInfo fileInfo)
public FileHolder(FileInfo fileInfo, int? id)
{
if (fileInfo.Exists)
{
@ -49,13 +52,18 @@ public class FileHolder : Properties.IFileHolder
_DirectoryName = fileInfo.DirectoryName;
_Exists = fileInfo.Exists;
_ExtensionLowered = fileInfo.Extension.ToLower();
_Id = id;
_FullName = fileInfo.FullName;
_Name = fileInfo.Name;
_NameWithoutExtension = Path.GetFileNameWithoutExtension(fileInfo.FullName);
}
public FileHolder(string fileName) :
this(new FileInfo(fileName))
this(new FileInfo(fileName), null)
{ }
public FileHolder(string fileName, int? id) :
this(new FileInfo(fileName), id)
{ }
public override string ToString()

View File

@ -16,7 +16,7 @@ public class Item : Properties.IItem
protected Property? _Property;
protected readonly string _RelativePath;
protected FileHolder? _ResizedFileHolder;
protected readonly string _SourceDirectoryFile;
protected readonly FileHolder _SourceDirectoryFileHolder;
protected bool _ValidImageFormatExtension;
public bool? Abandoned => _Abandoned;
public List<Face> Faces => _Faces;
@ -28,11 +28,11 @@ public class Item : Properties.IItem
public Property? Property => _Property;
public string RelativePath => _RelativePath;
public FileHolder? ResizedFileHolder => _ResizedFileHolder;
public string SourceDirectoryFile => _SourceDirectoryFile;
public FileHolder SourceDirectoryFileHolder => _SourceDirectoryFileHolder;
public bool ValidImageFormatExtension => _ValidImageFormatExtension;
[JsonConstructor]
public Item(bool? abandoned, List<Face> faces, bool? fileSizeChanged, FileHolder imageFileHolder, bool? lastWriteTimeChanged, bool? moved, bool? noJson, Property? property, string relativePath, FileHolder? resizedFileHolder, string sourceDirectoryFile, bool validImageFormatExtension)
public Item(bool? abandoned, List<Face> faces, bool? fileSizeChanged, FileHolder imageFileHolder, bool? lastWriteTimeChanged, bool? moved, bool? noJson, Property? property, string relativePath, FileHolder? resizedFileHolder, FileHolder sourceDirectoryFileHolder, bool validImageFormatExtension)
{
_Faces = faces;
_Moved = moved;
@ -43,13 +43,13 @@ public class Item : Properties.IItem
_FileSizeChanged = fileSizeChanged;
_ImageFileHolder = imageFileHolder;
_ResizedFileHolder = resizedFileHolder;
_SourceDirectoryFile = sourceDirectoryFile;
_SourceDirectoryFileHolder = sourceDirectoryFileHolder;
_LastWriteTimeChanged = lastWriteTimeChanged;
_ValidImageFormatExtension = validImageFormatExtension;
}
public Item(string sourceDirectoryFile, string relativePath, FileHolder imageFileInfo, bool validImageFormatExtension, Property? property, bool? abandoned, bool? fileSizeChanged, bool? lastWriteTimeChanged) :
this(abandoned, new(), fileSizeChanged, imageFileInfo, lastWriteTimeChanged, null, abandoned is null, property, relativePath, null, sourceDirectoryFile, validImageFormatExtension)
public Item(FileHolder sourceDirectoryFileHolder, string relativePath, FileHolder imageFileInfo, bool validImageFormatExtension, Property? property, bool? abandoned, bool? fileSizeChanged, bool? lastWriteTimeChanged) :
this(abandoned, new(), fileSizeChanged, imageFileInfo, lastWriteTimeChanged, null, abandoned is null, property, relativePath, null, sourceDirectoryFileHolder, validImageFormatExtension)
{
if (relativePath.EndsWith(".json"))
throw new ArgumentException("Can not be a *.json file!");
@ -57,8 +57,8 @@ public class Item : Properties.IItem
throw new ArgumentException("Can not be a *.json file!");
}
public Item(string sourceDirectoryFile, string relativePath, bool isValidImageFormatExtension) :
this(sourceDirectoryFile, relativePath, new(sourceDirectoryFile), isValidImageFormatExtension, null, null, null, null)
public Item(FileHolder sourceDirectoryFileHolder, string relativePath, bool isValidImageFormatExtension) :
this(sourceDirectoryFileHolder, relativePath, sourceDirectoryFileHolder, isValidImageFormatExtension, null, null, null, null)
{ }
public override string ToString()

View File

@ -20,7 +20,7 @@ public class Location : Properties.ILocation, IEquatable<Location>
Left = left;
Right = right;
Top = top;
Stateless.Methods.Location.Check(bottom, left, right, top, zCount: 1);
_ = Stateless.Methods.Location.Check(bottom, left, right, top, zCount: 1, throwException: true);
}
public Location(double confidence, int height, Location location, int locationDigits, int locationFactor, int width, int zCount) :
@ -30,7 +30,7 @@ public class Location : Properties.ILocation, IEquatable<Location>
location.Left,
location.Right,
location.Top) =>
Stateless.Methods.Location.Check(Bottom, height, Left, Right, Top, width, zCount);
Stateless.Methods.Location.Check(Bottom, height, Left, Right, Top, width, zCount, throwException: true);
public Location(int bottom, double confidence, int height, int left, int locationDigits, int locationFactor, int right, int top, int width, int zCount) :
this(
@ -39,7 +39,7 @@ public class Location : Properties.ILocation, IEquatable<Location>
left,
right,
top) =>
Stateless.Methods.Location.Check(Bottom, height, Left, Right, Top, width, zCount);
Stateless.Methods.Location.Check(Bottom, height, Left, Right, Top, width, zCount, throwException: true);
public Location(int height, Location location, int locationDigits, int locationFactor, int width, int zCount) :
this(
@ -48,7 +48,7 @@ public class Location : Properties.ILocation, IEquatable<Location>
location.Left,
location.Right,
location.Top) =>
Stateless.Methods.Location.Check(Bottom, height, Left, Right, Top, width, zCount);
Stateless.Methods.Location.Check(Bottom, height, Left, Right, Top, width, zCount, throwException: true);
public Location(double confidence, int factor, int height, Location location, int locationDigits, int locationFactor, int width, int zCount)
{
@ -58,7 +58,7 @@ public class Location : Properties.ILocation, IEquatable<Location>
int left = Math.Max(location.Left - x, 0);
int right = Math.Min(location.Right + x, width);
int top = Math.Max(location.Top - y, 0);
Stateless.Methods.Location.Check(Bottom, height, Left, Right, Top, width, zCount);
_ = Stateless.Methods.Location.Check(Bottom, height, Left, Right, Top, width, zCount, throwException: true);
Confidence = confidence;
Bottom = bottom;
Left = left;

View File

@ -6,6 +6,7 @@ namespace View_by_Distance.Shared.Models;
public class MappingFromItem : Properties.IMappingFromItem
{
public DateTime[] ContainerDateTimes { init; get; }
public int Id { init; get; }
public FileHolder ImageFileHolder { init; get; }
public bool? IsWrongYear { init; get; }
@ -14,8 +15,9 @@ public class MappingFromItem : Properties.IMappingFromItem
public FileHolder ResizedFileHolder { init; get; }
[JsonConstructor]
public MappingFromItem(int id, FileHolder imageFileHolder, bool? isWrongYear, DateTime minimumDateTime, string relativePath, FileHolder resizedFileHolder)
public MappingFromItem(DateTime[] containerDateTimes, int id, FileHolder imageFileHolder, bool? isWrongYear, DateTime minimumDateTime, string relativePath, FileHolder resizedFileHolder)
{
ContainerDateTimes = containerDateTimes;
Id = id;
ImageFileHolder = imageFileHolder;
IsWrongYear = isWrongYear;
@ -30,7 +32,7 @@ public class MappingFromItem : Properties.IMappingFromItem
return result;
}
internal static MappingFromItem GetMappingFromItem(Item item, FileHolder? resizedFileHolder)
internal static MappingFromItem GetMappingFromItem(DateTime[] containerDateTimes, Item item, FileHolder? resizedFileHolder)
{
MappingFromItem result;
bool? isWrongYear;
@ -41,7 +43,7 @@ public class MappingFromItem : Properties.IMappingFromItem
throw new NotSupportedException();
minimumDateTime = Stateless.Methods.IProperty.GetMinimumDateTime(item.Property);
(isWrongYear, _) = item.Property.IsWrongYear(item.ImageFileHolder, minimumDateTime);
result = new(item.Property.Id.Value, item.ImageFileHolder, isWrongYear, minimumDateTime, item.RelativePath, resizedFileHolder);
result = new(containerDateTimes, item.Property.Id.Value, item.ImageFileHolder, isWrongYear, minimumDateTime, item.RelativePath, resizedFileHolder);
return result;
}
@ -53,15 +55,15 @@ public class MappingFromLocation : Properties.IMappingFromLocation
public int AreaPermille { init; get; }
public int ConfidencePercent { init; get; }
public string DeterministicHashCodeKey { init; get; }
public int NormalizedPixelPercentage { init; get; }
public int NormalizedRectangle { init; get; }
[JsonConstructor]
public MappingFromLocation(int areaPermille, int confidencePercent, string deterministicHashCodeKey, int normalizedPixelPercentage)
public MappingFromLocation(int areaPermille, int confidencePercent, string deterministicHashCodeKey, int normalizedRectangle)
{
AreaPermille = areaPermille;
ConfidencePercent = confidencePercent;
DeterministicHashCodeKey = deterministicHashCodeKey;
NormalizedPixelPercentage = normalizedPixelPercentage;
NormalizedRectangle = normalizedRectangle;
}
public override string ToString()
@ -102,17 +104,20 @@ public class Mapping : Properties.IMapping
protected int? _By;
protected MappingFromPerson? _MappingFromPerson;
public string? _SegmentC;
protected SortingContainer? _SortingContainer;
public int? By => _By;
public MappingFromItem MappingFromItem { init; get; }
public MappingFromLocation MappingFromLocation { init; get; }
public MappingFromPerson? MappingFromPerson => _MappingFromPerson;
public string? SegmentC => _SegmentC;
public SortingContainer? SortingContainer => _SortingContainer;
[JsonConstructor]
public Mapping(int? by, MappingFromItem mappingFromItem, MappingFromLocation mappingFromLocation, MappingFromPerson? mappingFromPerson, SortingContainer? sortingContainer)
public Mapping(int? by, MappingFromItem mappingFromItem, MappingFromLocation mappingFromLocation, MappingFromPerson? mappingFromPerson, string? segmentC, SortingContainer? sortingContainer)
{
_By = by;
_SegmentC = segmentC;
MappingFromItem = mappingFromItem;
MappingFromLocation = mappingFromLocation;
_MappingFromPerson = mappingFromPerson;
@ -120,7 +125,7 @@ public class Mapping : Properties.IMapping
}
public Mapping(MappingFromItem mappingFromItem, MappingFromLocation mappingFromLocation) :
this(null, mappingFromItem, mappingFromLocation, null, null)
this(null, mappingFromItem, mappingFromLocation, null, null, null)
{ }
public override string ToString()
@ -142,9 +147,10 @@ public class Mapping : Properties.IMapping
_MappingFromPerson = new(approximateYears, displayDirectoryName, personBirthday, segmentB);
}
public void UpdateMappingFromPerson(int? approximateYears, int? by, string displayDirectoryName, PersonBirthday personBirthday, string segmentB, SortingContainer sortingContainer)
public void UpdateMappingFromPerson(int? approximateYears, int? by, string displayDirectoryName, PersonBirthday personBirthday, string segmentB, string segmentC, SortingContainer sortingContainer)
{
_By = by;
_SegmentC = segmentC;
_SortingContainer = sortingContainer;
_MappingFromPerson = new(approximateYears, displayDirectoryName, personBirthday, segmentB);
}

30
Shared/Models/Marker.cs Normal file
View File

@ -0,0 +1,30 @@
using System.Text.Json.Serialization;
namespace View_by_Distance.Shared.Models;
public record Marker(
[property: JsonPropertyName("marker_uid")] string MarkerUid,
[property: JsonPropertyName("file_uid")] string FileUid,
[property: JsonPropertyName("marker_type")] string MarkerType,
[property: JsonPropertyName("marker_src")] string MarkerSrc,
[property: JsonPropertyName("marker_name")] string MarkerName,
[property: JsonPropertyName("marker_review")] int MarkerReview,
[property: JsonPropertyName("marker_invalid")] int MarkerInvalid,
[property: JsonPropertyName("subj_uid")] string SubjUid,
[property: JsonPropertyName("subj_src")] string SubjSrc,
[property: JsonPropertyName("face_id")] string FaceId,
[property: JsonPropertyName("face_dist")] double FaceDist,
[property: JsonPropertyName("embeddings_json")] string EmbeddingsJson,
[property: JsonPropertyName("landmarks_json")] string LandmarksJson,
[property: JsonPropertyName("x")] double X,
[property: JsonPropertyName("y")] double Y,
[property: JsonPropertyName("w")] double W,
[property: JsonPropertyName("h")] double H,
[property: JsonPropertyName("q")] int Q,
[property: JsonPropertyName("size")] int Size,
[property: JsonPropertyName("score")] int Score,
[property: JsonPropertyName("thumb")] string Thumb,
[property: JsonPropertyName("matched_at")] string MatchedAt,
[property: JsonPropertyName("created_at")] string CreatedAt,
[property: JsonPropertyName("updated_at")] string UpdatedAt
);

View File

@ -0,0 +1,36 @@
namespace View_by_Distance.Shared.Models;
public record MarkerWith(
string MarkerUid,
string FileUid,
string MarkerType,
string MarkerSrc,
string MarkerName,
int MarkerReview,
int MarkerInvalid,
string SubjUid,
string SubjSrc,
string FaceId,
double FaceDist,
string EmbeddingsJson,
string LandmarksJson,
double X,
double Y,
double W,
double H,
int Q,
int Size,
int Score,
string Thumb,
string MatchedAt,
string CreatedAt,
string UpdatedAt,
int FileId,
string FileName,
int? DlibId,
int? Count,
double? Percent,
int? NormalizedRectangle,
long? PersonKey,
string PersonKeyFormatted
);

View File

@ -9,6 +9,6 @@ public interface IFaceDistance
public bool? IsWrongYear { init; get; }
public double? Length { init; get; }
public DateTime? MinimumDateTime { init; get; }
public int? NormalizedPixelPercentage { init; get; }
public int? NormalizedRectangle { init; get; }
}

View File

@ -12,7 +12,7 @@ public interface IItem
public Property? Property { get; }
public string RelativePath { get; }
public FileHolder? ResizedFileHolder { get; }
public string SourceDirectoryFile { get; }
public FileHolder SourceDirectoryFileHolder { get; }
public bool ValidImageFormatExtension { get; }
}

View File

@ -3,6 +3,7 @@ namespace View_by_Distance.Shared.Models.Properties;
public interface IMappingFromItem
{
public DateTime[] ContainerDateTimes { init; get; }
public int Id { init; get; }
public FileHolder ImageFileHolder { init; get; }
public bool? IsWrongYear { init; get; }
@ -18,7 +19,7 @@ public interface IMappingFromLocation
public int AreaPermille { init; get; }
public int ConfidencePercent { init; get; }
public string DeterministicHashCodeKey { init; get; }
public int NormalizedPixelPercentage { init; get; }
public int NormalizedRectangle { init; get; }
}
@ -36,6 +37,7 @@ public interface IMapping
{
public int? By { get; }
public string? SegmentC { get; }
public MappingFromItem MappingFromItem { init; get; }
public MappingFromLocation MappingFromLocation { init; get; }
public MappingFromPerson? MappingFromPerson { get; }

View File

@ -12,7 +12,6 @@ public interface IProperty
public DateTime? GPSDateStamp { get; }
public int? Height { get; }
public int? Id { get; }
public int[] Indices { get; }
public DateTime LastWriteTime { get; }
public string Make { get; }
public string Model { get; }

View File

@ -4,16 +4,17 @@ public interface IPropertyConfiguration
{
public string DateGroup { init; get; }
public string? ModelName { get; }
public int? NumberOfJitters { get; }
public int? NumberOfTimesToUpsample { get; }
public string? PredictorModelName { get; }
public string[] IgnoreExtensions { init; get; }
public string[] PropertyContentCollectionFiles { init; get; }
public string ResultAllInOne { init; get; }
public string ResultCollection { init; get; }
public string ResultContent { init; get; }
public string ResultSingleton { init; get; }
public string RootDirectory { get; }
public string[] VerifyToSeason { init; get; }
public string? ModelName { get; }
public int? NumberOfJitters { get; }
public int? NumberOfTimesToUpsample { get; }
public string? PredictorModelName { get; }
public string RootDirectory { get; }
}

View File

@ -0,0 +1,12 @@
namespace View_by_Distance.Shared.Models.Properties;
public interface IRelativeLocation
{
public double Confidence { init; get; }
public string Height { init; get; }
public string Left { init; get; }
public string Top { init; get; }
public string Width { init; get; }
}

View File

@ -6,7 +6,7 @@ public interface ISorting
public int DaysDelta { init; get; }
public int DistancePermyriad { init; get; }
public int Id { init; get; }
public int NormalizedPixelPercentage { init; get; }
public int NormalizedRectangle { init; get; }
public int WithinRange { init; get; }
}

View File

@ -15,7 +15,6 @@ public class Property : Properties.IProperty
protected DateTime? _GPSDateStamp;
protected int? _Height;
protected int? _Id;
protected int[] _Indices;
protected DateTime _LastWriteTime;
protected string _Make;
protected string _Model;
@ -30,7 +29,6 @@ public class Property : Properties.IProperty
public DateTime? GPSDateStamp => _GPSDateStamp;
public int? Height => _Height;
public int? Id => _Id;
public int[] Indices => _Indices;
public DateTime LastWriteTime => _LastWriteTime;
public string Make => _Make;
public string Model => _Model;
@ -38,7 +36,7 @@ public class Property : Properties.IProperty
public int? Width => _Width;
[JsonConstructor]
public Property(DateTime creationTime, DateTime? dateTime, DateTime? dateTimeDigitized, DateTime? dateTimeFromName, DateTime? dateTimeOriginal, long fileSize, DateTime? gpsDateStamp, int? height, int? id, int[] indices, DateTime lastWriteTime, string make, string model, string orientation, int? width)
public Property(DateTime creationTime, DateTime? dateTime, DateTime? dateTimeDigitized, DateTime? dateTimeFromName, DateTime? dateTimeOriginal, long fileSize, DateTime? gpsDateStamp, int? height, int? id, DateTime lastWriteTime, string make, string model, string orientation, int? width)
{
_DateTimeFromName = dateTimeFromName;
_CreationTime = creationTime;
@ -49,7 +47,6 @@ public class Property : Properties.IProperty
_GPSDateStamp = gpsDateStamp;
_Height = height;
_Id = id;
_Indices = indices;
_LastWriteTime = lastWriteTime;
_Make = make;
_Model = model;

View File

@ -0,0 +1,43 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace View_by_Distance.Shared.Models;
public class RelativeLocation : Properties.IRelativeLocation
{
public double Confidence { init; get; }
public string Height { init; get; }
public string Left { init; get; }
public string Top { init; get; }
public string Width { init; get; }
[JsonConstructor]
public RelativeLocation(double confidence, string height, string left, string top, string width)
{
Confidence = confidence;
Height = height;
Left = left;
Top = top;
Width = width;
}
public bool Match(decimal? height, decimal? left, decimal? top, decimal? width)
{
bool result;
if (height is null || left is null || top is null || width is null)
result = false;
else if (height.Value.ToString() == Height && left.Value.ToString() == Left && top.Value.ToString() == Top && width.Value.ToString() == Width)
result = false;
else
result = true;
return result;
}
public override string ToString()
{
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
return result;
}
}

View File

@ -9,17 +9,17 @@ public record class Sorting : Properties.ISorting
public int DaysDelta { init; get; }
public int DistancePermyriad { init; get; }
public int Id { init; get; }
public int NormalizedPixelPercentage { init; get; }
public int NormalizedRectangle { init; get; }
public bool Older { init; get; }
public int WithinRange { init; get; }
[JsonConstructor]
public Sorting(int daysDelta, int distancePermyriad, int id, int normalizedPixelPercentage, bool older, int withinRange)
public Sorting(int daysDelta, int distancePermyriad, int id, int normalizedRectangle, bool older, int withinRange)
{
DaysDelta = daysDelta;
DistancePermyriad = distancePermyriad;
Id = id;
NormalizedPixelPercentage = normalizedPixelPercentage;
NormalizedRectangle = normalizedRectangle;
Older = older;
WithinRange = withinRange;
}

View File

@ -17,7 +17,7 @@ public record class SortingContainer : Properties.ISortingContainer
public override string ToString()
{
string result = string.Concat(Mapping.MappingFromItem.Id, '\t', Mapping.MappingFromLocation.NormalizedPixelPercentage, '\t', Sorting.Id, '\t', Sorting.NormalizedPixelPercentage, '\t', Sorting.Older, '\t', Sorting.WithinRange, '\t', Sorting.DistancePermyriad, '\t', Sorting.DaysDelta);
string result = string.Concat(Mapping.MappingFromItem.Id, '\t', Mapping.MappingFromLocation.NormalizedRectangle, '\t', Sorting.Id, '\t', Sorting.NormalizedRectangle, '\t', Sorting.Older, '\t', Sorting.WithinRange, '\t', Sorting.DistancePermyriad, '\t', Sorting.DaysDelta);
return result;
}

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;
}

View File

@ -34,7 +34,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
<PackageReference Include="System.Text.Json" Version="7.0.0" />
<PackageReference Include="System.Text.Json" Version="7.0.1" />
<PackageReference Include="MetadataExtractor" Version="2.7.2" />
</ItemGroup>
</Project>