(bool? IsWrongYear, string PersonKey,

TimeSpan? TimeSpan)
This commit is contained in:
2022-08-02 19:41:36 -07:00
parent 62bdc17f7a
commit 2158b4cfc2
7 changed files with 105 additions and 66 deletions

View File

@ -677,21 +677,11 @@ public class DlibDotNet
{
if (outputResolution == _Configuration.OutputResolutions[0] || _Configuration.SaveShortcutsForOutputResolutions.Contains(outputResolution))
{
List<(PropertyHolder, (string, D_Face?, (string, string, string, string))[])> collections = D_Face.GetCollection(configuration, model, predictorModel, propertyLogic, peopleCollection, outputResolution, filteredPropertyHolderCollection, faceCollections);
if (outputResolution == _Configuration.OutputResolutions[0])
{
foreach ((PropertyHolder propertyHolder, (string, D_Face?, (string, string, string, string))[] collection) in collections)
{
foreach ((string personKey, D_Face? face, (string directory, string copyDirectory, string copyFileName, string shortcutFileName)) in collection)
{
if (string.IsNullOrEmpty(personKey) || face is null || string.IsNullOrEmpty(directory))
continue;
propertyHolder.AddNamed(directory, personKey, face);
}
}
}
PropertyHolder.AddToNamed(propertyLogic, filteredPropertyHolderCollection);
for (int i = 0; i < faceCollections.Count; i++)
PropertyHolder.AddToFaces(filteredPropertyHolderCollection, (from l in faceCollections[i] select (object)l).ToArray());
if (_Configuration.SaveShortcutsForOutputResolutions.Contains(outputResolution))
D_Face.SaveShortcuts(_Configuration.JuliePhares, peopleCollection, collections);
D_Face.SaveShortcuts(configuration, model, predictorModel, _Configuration.JuliePhares, peopleCollection, propertyLogic, outputResolution, filteredPropertyHolderCollection, faceCollections);
}
}
if (exceptionCount == 0 && _Configuration.LoadOrCreateThenSaveDistanceResultsForOutputResolutions.Contains(outputResolution))

View File

@ -505,22 +505,21 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
SaveFaces(faceCollection, propertyHolder.ResizedFileInfo, imageFiles);
}
internal static List<(PropertyHolder, (string, D_Face?, (string, string, string, string))[])> GetCollection(Property.Models.Configuration configuration, Model? model, PredictorModel? predictorModel, PropertyLogic propertyLogic, Dictionary<string, List<Person>> peopleCollection, string outputResolution, PropertyHolder[] filteredPropertyHolderCollection, List<List<D_Face>> faceCollections)
private static List<(PropertyHolder, (string, D_Face?, (string, string, string, string))[])> GetCollection(Property.Models.Configuration configuration, Model? model, PredictorModel? predictorModel, PropertyLogic propertyLogic, string outputResolution, PropertyHolder[] filteredPropertyHolderCollection, List<List<D_Face>> faceCollections)
{
List<(PropertyHolder, (string, D_Face?, (string, string, string, string))[])> results = new();
string[] keys;
string personKey;
string directory;
string personKey;
bool? isWrongYear;
TimeSpan timeSpan;
string copyFileName;
DateTime? birthDate;
string copyFileName;
string copyDirectory;
string? relativePath;
string isWrongYearFlag;
string shortcutFileName;
string subDirectoryName;
DateTime minimumDateTime;
List<int> indices = new();
List<D_Face> faceCollection;
PropertyHolder propertyHolder;
@ -550,10 +549,9 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
{
faceCollection = faceCollections[i];
keys = propertyLogic.NamedFaceInfoDeterministicHashCodeIndices[propertyHolder.Property.Id.Value];
minimumDateTime = Property.Models.Stateless.A_Property.GetMinimumDateTime(propertyHolder.Property);
(isWrongYear, _) = propertyHolder.Property.IsWrongYear(propertyHolder.ImageFileInfo.FullName, minimumDateTime);
isWrongYearFlag = isWrongYear is null ? "#" : isWrongYear.Value ? "~" : "=";
subDirectoryName = $"{isWrongYearFlag}{minimumDateTime:yyyy}";
(isWrongYear, _) = propertyHolder.Property.IsWrongYear(propertyHolder.ImageFileInfo.FullName, propertyHolder.MinimumDateTime.Value);
isWrongYearFlag = PropertyHolder.GetWrongYearFlag(isWrongYear);
subDirectoryName = $"{isWrongYearFlag}{propertyHolder.MinimumDateTime.Value:yyyy}";
if (!faceCollection.Any())
directory = Path.Combine(dFacesContentDirectory, $"None{relativePath[2..]}", subDirectoryName);
else if (keys.Length != 1)
@ -569,13 +567,11 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
birthDate = Shared.Models.Stateless.Methods.IPersonBirthday.Get(personKey);
if (birthDate.HasValue)
{
if (minimumDateTime < birthDate.Value)
timeSpan = new(propertyHolder.MinimumDateTime.Value.Ticks - birthDate.Value.Ticks);
if (timeSpan.Ticks < 0)
subDirectoryName = "!---";
else
{
timeSpan = new(minimumDateTime.Ticks - birthDate.Value.Ticks);
subDirectoryName = $"^{Math.Floor(timeSpan.TotalDays / 365):000}";
}
}
}
directory = Path.Combine(dFacesContentDirectory, "Shortcuts", personKey, subDirectoryName);
@ -599,13 +595,14 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
return results;
}
internal static void SaveShortcuts(string[] juliePhares, Dictionary<string, List<Person>> peopleCollection, List<(PropertyHolder, (string, D_Face?, (string Directory, string CopyDirectory, string CopyFileName, string ShortcutFileName))[])> collections)
internal static void SaveShortcuts(Property.Models.Configuration configuration, Model? model, PredictorModel? predictorModel, string[] juliePhares, Dictionary<string, List<Person>> peopleCollection, PropertyLogic propertyLogic, string outputResolution, PropertyHolder[] filteredPropertyHolderCollection, List<List<D_Face>> faceCollections)
{
Person person;
string fileName;
string fullName;
WindowsShortcut windowsShortcut;
const string pattern = @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]";
List<(PropertyHolder, (string, D_Face?, (string, string, string, string))[])> collections = GetCollection(configuration, model, predictorModel, propertyLogic, outputResolution, filteredPropertyHolderCollection, faceCollections);
foreach ((PropertyHolder propertyHolder, (string personKey, D_Face? face, (string, string, string, string))[] collection) in collections)
{
if (collection.Length != 1)

View File

@ -401,10 +401,14 @@ internal class E_Distance
}
}
private static Dictionary<string, List<(string directory, string personKey, D_Face face)>> Convert(string argZero, List<PropertyHolder[]> propertyHolderCollections)
private static Dictionary<string, List<(string personKey, D_Face face)>> Convert(string argZero, List<PropertyHolder[]> propertyHolderCollections)
{
Dictionary<string, List<(string directory, string personKey, D_Face face)>> results = new();
Dictionary<string, List<(string personKey, D_Face face)>> results = new();
string key;
string personKey;
bool? isWrongYear;
TimeSpan? timeSpan;
string isWrongYearFlag;
foreach (PropertyHolder[] propertyHolderCollection in propertyHolderCollections)
{
if (!propertyHolderCollection.Any())
@ -415,16 +419,27 @@ internal class E_Distance
{
if (propertyHolder.ImageFileInfo is null || propertyHolder.Property is null || !propertyHolder.Named.Any())
continue;
foreach ((string directory, string personKey, object @object) in propertyHolder.Named)
if (propertyHolder.Named.Count != 1 || propertyHolder.Faces.Count != 1)
continue;
for (int i = 0; i < propertyHolder.Named.Count; i++)
{
if (string.IsNullOrEmpty(directory) || string.IsNullOrEmpty(personKey) || !directory.Contains(personKey))
if (propertyHolder.MinimumDateTime is null)
continue;
if (@object is not D_Face face || face.FaceEncoding is null)
if (propertyHolder.Faces[i] is not D_Face face)
continue;
key = directory.Split(personKey)[1];
timeSpan = propertyHolder.Named[i].TimeSpan;
personKey = propertyHolder.Named[i].PersonKey;
isWrongYear = propertyHolder.Named[i].IsWrongYear;
isWrongYearFlag = PropertyHolder.GetWrongYearFlag(isWrongYear);
if (timeSpan is null)
key = $"{personKey}\t{isWrongYearFlag}{propertyHolder.MinimumDateTime.Value:yyyy}";
else if (timeSpan.Value.Ticks < 0)
key = $"{personKey}\t{isWrongYearFlag}!---";
else
key = $"{personKey}\t^{Math.Floor(timeSpan.Value.TotalDays / 365):000}";
if (!results.ContainsKey(key))
results.Add(key, new());
results[key].Add(new(directory, personKey, face));
results[key].Add(new(personKey, face));
}
}
}
@ -440,14 +455,14 @@ internal class E_Distance
List<string> checkDirectories = new();
List<Shared.Models.Properties.IFace> collection;
const string pattern = @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]";
Dictionary<string, List<(string personKey, D_Face face)>> keyValuePairs = Convert(argZero, propertyHolderCollections);
string eDistanceCollectionDirectory = Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, model, predictorModel, nameof(E_Distance), outputResolution, includeResizeGroup: true, includeModel: true, includePredictorModel: true), "[_]");
Dictionary<string, List<(string directory, string personKey, D_Face face)>> keyValuePairs = Convert(argZero, propertyHolderCollections);
foreach (KeyValuePair<string, List<(string directory, string personKey, D_Face face)>> keyValuePair in keyValuePairs)
foreach (KeyValuePair<string, List<(string personKey, D_Face face)>> keyValuePair in keyValuePairs)
{
collection = new();
checkDirectories.Clear();
checkFile = string.Empty;
foreach ((string _, string personKey, D_Face face) in keyValuePair.Value)
foreach ((string personKey, D_Face face) in keyValuePair.Value)
{
if (string.IsNullOrEmpty(personKey) || !peopleCollection.ContainsKey(personKey))
continue;