Save Closest is ready again with

all Deterministic Hash Code Key
This commit is contained in:
Mike Phares 2022-08-20 00:57:48 -07:00
parent be7a6abbf4
commit f72fcee1db
16 changed files with 235 additions and 136 deletions

7
.vscode/launch.json vendored
View File

@ -15,14 +15,17 @@
"program": "${workspaceFolder}/Instance/bin/Debug/net6.0/win-x64/Instance.dll", "program": "${workspaceFolder}/Instance/bin/Debug/net6.0/win-x64/Instance.dll",
"programN": "${workspaceFolder}/Not-Copy-Copy/bin/Debug/net6.0/win-x64/Not-Copy-Copy.dll", "programN": "${workspaceFolder}/Not-Copy-Copy/bin/Debug/net6.0/win-x64/Not-Copy-Copy.dll",
"programP": "${workspaceFolder}/PrepareForOld/bin/Debug/net6.0/win-x64/PrepareForOld.dll", "programP": "${workspaceFolder}/PrepareForOld/bin/Debug/net6.0/win-x64/PrepareForOld.dll",
"args": [], "args": [
"s"
],
"env": { "env": {
"ASPNETCORE_ENVIRONMENT": "Development", "ASPNETCORE_ENVIRONMENT": "Development",
}, },
"cwd": "${workspaceFolder}", "cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "externalTerminal", "console": "externalTerminal",
"stopAtEntry": false "stopAtEntry": false,
"requireExactSource": false
} }
] ]
} }

View File

@ -123,6 +123,17 @@ public class DlibDotNet
return result; return result;
} }
private long LogDeltaInSeconds(long ticks, string methodName)
{
long result;
if (_Log is null)
throw new NullReferenceException(nameof(_Log));
double delta = new TimeSpan(DateTime.Now.Ticks - ticks).Seconds;
_Log.Debug($"{methodName} took {Math.Floor(delta)} seconds(s)");
result = DateTime.Now.Ticks;
return result;
}
private long LogDeltaInMinutes(long ticks, string methodName) private long LogDeltaInMinutes(long ticks, string methodName)
{ {
long result; long result;
@ -606,8 +617,8 @@ public class DlibDotNet
} }
_Log.Information(". . ."); _Log.Information(". . .");
} }
if (isSilent && container.SourceDirectory.EndsWith("Bohdi Ray 2016")) // 7#.1 // if (isSilent && container.SourceDirectory.EndsWith("Bohdi Ray 2016")) // 7#.1
break; // break;
// if (isSilent && container.SourceDirectory.EndsWith("Halloween 2013")) // 12#.1 // if (isSilent && container.SourceDirectory.EndsWith("Halloween 2013")) // 12#.1
// break; // break;
// if (isSilent && container.SourceDirectory.EndsWith("zzz =2014.4 Winter Tracy Pictures")) // 30#.2 // if (isSilent && container.SourceDirectory.EndsWith("zzz =2014.4 Winter Tracy Pictures")) // 30#.2
@ -654,17 +665,6 @@ public class DlibDotNet
foreach (string outputResolution in _Configuration.OutputResolutions) foreach (string outputResolution in _Configuration.OutputResolutions)
{ {
(aResultsFullGroupDirectory, bResultsFullGroupDirectory, cResultsFullGroupDirectory, dResultsFullGroupDirectory, d2ResultsFullGroupDirectory, eResultsFullGroupDirectory, zResultsFullGroupDirectory) = GetResultsFullGroupDirectories(configuration, model, predictorModel, outputResolution); (aResultsFullGroupDirectory, bResultsFullGroupDirectory, cResultsFullGroupDirectory, dResultsFullGroupDirectory, d2ResultsFullGroupDirectory, eResultsFullGroupDirectory, zResultsFullGroupDirectory) = GetResultsFullGroupDirectories(configuration, model, predictorModel, outputResolution);
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(Path.Combine(aResultsFullGroupDirectory, "{}"));
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(Path.Combine(bResultsFullGroupDirectory, "{}"));
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(Path.Combine(cResultsFullGroupDirectory, "{}"));
if (_Configuration.LoadOrCreateThenSaveImageFacesResultsForOutputResolutions.Contains(outputResolution))
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(Path.Combine(dResultsFullGroupDirectory, "[]"));
if (_Configuration.LoadOrCreateThenSaveDistanceResultsForOutputResolutions.Contains(outputResolution))
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(Path.Combine(eResultsFullGroupDirectory, "[]"));
if (_Configuration.LoadOrCreateThenSaveDirectoryDistanceResultsForOutputResolutions.Contains(outputResolution))
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(Path.Combine(eResultsFullGroupDirectory, "[]"));
if (_Configuration.SaveFaceLandmarkForOutputResolutions.Contains(outputResolution))
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(Path.Combine(d2ResultsFullGroupDirectory, "[]"));
if (_ArgZeroIsConfigurationRootDirectory && _Exceptions.Count == 0 && outputResolution == _Configuration.OutputResolutions[0] && (propertyLogic.NamedFaceInfoDeterministicHashCodeKeyValuePairs.Any() || propertyLogic.NamedDeterministicHashCodeKeyValuePairs.Any())) if (_ArgZeroIsConfigurationRootDirectory && _Exceptions.Count == 0 && outputResolution == _Configuration.OutputResolutions[0] && (propertyLogic.NamedFaceInfoDeterministicHashCodeKeyValuePairs.Any() || propertyLogic.NamedDeterministicHashCodeKeyValuePairs.Any()))
{ {
if (!string.IsNullOrEmpty(propertyLogic.DeterministicHashCodeRootDirectory) && !propertyLogic.IncorrectDeterministicHashCodeKeyValuePairs.Any()) if (!string.IsNullOrEmpty(propertyLogic.DeterministicHashCodeRootDirectory) && !propertyLogic.IncorrectDeterministicHashCodeKeyValuePairs.Any())
@ -688,11 +688,11 @@ public class DlibDotNet
eDistanceCollectionDirectory = Path.Combine(eResultsFullGroupDirectory, $"[{ticks}]"); eDistanceCollectionDirectory = Path.Combine(eResultsFullGroupDirectory, $"[{ticks}]");
List<(DateTime, bool?, PersonBirthday, FaceRecognitionDotNet.FaceEncoding[])> collection; List<(DateTime, bool?, PersonBirthday, FaceRecognitionDotNet.FaceEncoding[])> collection;
collection = E_Distance.ParallelWork(_AppSettings.MaxDegreeOfParallelism, argZero, propertyLogic, containers); collection = E_Distance.ParallelWork(_AppSettings.MaxDegreeOfParallelism, argZero, propertyLogic, containers);
_ = LogDeltaInMinutes(ticks, nameof(E_Distance.ParallelWork)); _ = LogDeltaInSeconds(ticks, nameof(E_Distance.ParallelWork));
E_Distance.SavePropertyHolders(argZero, containers, zPropertyHolderSingletonDirectory); E_Distance.SavePropertyHolders(argZero, containers, zPropertyHolderSingletonDirectory);
_ = LogDeltaInMinutes(ticks, nameof(E_Distance.SavePropertyHolders)); _ = LogDeltaInSeconds(ticks, nameof(E_Distance.SavePropertyHolders));
E_Distance.SaveThreeSigmaFaceEncodings(collection, peopleCollection, eDistanceCollectionDirectory); E_Distance.SaveThreeSigmaFaceEncodings(collection, peopleCollection, eDistanceCollectionDirectory);
_ = LogDeltaInMinutes(ticks, nameof(E_Distance.SaveThreeSigmaFaceEncodings)); _ = LogDeltaInSeconds(ticks, nameof(E_Distance.SaveThreeSigmaFaceEncodings));
E_Distance.SaveClosest(argZero, containers, peopleCollection, eDistanceContentDirectory, dFacesContentDirectory); E_Distance.SaveClosest(argZero, containers, peopleCollection, eDistanceContentDirectory, dFacesContentDirectory);
_ = LogDeltaInMinutes(ticks, nameof(E_Distance.SaveClosest)); _ = LogDeltaInMinutes(ticks, nameof(E_Distance.SaveClosest));
} }
@ -709,6 +709,17 @@ public class DlibDotNet
if (_Configuration.LoadOrCreateThenSaveIndex && _FilePropertiesKeyValuePairs.Any()) if (_Configuration.LoadOrCreateThenSaveIndex && _FilePropertiesKeyValuePairs.Any())
_Index.SetIndex(configuration, model, predictorModel, _Configuration.OutputResolutions[0], _FilePropertiesKeyValuePairs); _Index.SetIndex(configuration, model, predictorModel, _Configuration.OutputResolutions[0], _FilePropertiesKeyValuePairs);
} }
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(Path.Combine(aResultsFullGroupDirectory, "{}"));
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(Path.Combine(bResultsFullGroupDirectory, "{}"));
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(Path.Combine(cResultsFullGroupDirectory, "{}"));
if (_Configuration.LoadOrCreateThenSaveImageFacesResultsForOutputResolutions.Contains(outputResolution))
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(Path.Combine(dResultsFullGroupDirectory, "[]"));
if (_Configuration.LoadOrCreateThenSaveDistanceResultsForOutputResolutions.Contains(outputResolution))
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(Path.Combine(eResultsFullGroupDirectory, "[]"));
if (_Configuration.LoadOrCreateThenSaveDirectoryDistanceResultsForOutputResolutions.Contains(outputResolution))
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(Path.Combine(eResultsFullGroupDirectory, "[]"));
if (_Configuration.SaveFaceLandmarkForOutputResolutions.Contains(outputResolution))
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(Path.Combine(d2ResultsFullGroupDirectory, "[]"));
} }
} }

View File

@ -3,6 +3,7 @@ using System.Text.Json;
using View_by_Distance.Metadata.Models; using View_by_Distance.Metadata.Models;
using View_by_Distance.Property.Models; using View_by_Distance.Property.Models;
using View_by_Distance.Resize.Models; using View_by_Distance.Resize.Models;
using View_by_Distance.Shared.Models.Properties;
using View_by_Distance.Shared.Models.Stateless; using View_by_Distance.Shared.Models.Stateless;
namespace View_by_Distance.Instance.Models; namespace View_by_Distance.Instance.Models;
@ -44,9 +45,9 @@ internal class D2_FaceLandmarks
{ {
int x; int x;
int y; int y;
D_Face face;
int width; int width;
int height; int height;
D_Face face;
string imageFileFullName; string imageFileFullName;
Bitmap rotated; Bitmap rotated;
string rotatedImageFileFullName; string rotatedImageFileFullName;
@ -104,7 +105,7 @@ internal class D2_FaceLandmarks
#pragma warning restore CA1416 #pragma warning restore CA1416
internal void SaveFaceLandmarkImages(string d2ResultsFullGroupDirectory, string sourceDirectory, List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, Item item, List<D_Face> faceCollections) internal void SaveFaceLandmarkImages(string d2ResultsFullGroupDirectory, string sourceDirectory, List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, Item item, List<D_Face> faceCollection)
{ {
if (_Configuration.PropertyConfiguration is null) if (_Configuration.PropertyConfiguration is null)
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration)); throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
@ -118,6 +119,7 @@ internal class D2_FaceLandmarks
const int pointSize = 2; const int pointSize = 2;
FileInfo rotatedFileInfo; FileInfo rotatedFileInfo;
DateTime? dateTime = null; DateTime? dateTime = null;
double deterministicHashCodeKey;
long ticks = DateTime.Now.Ticks; long ticks = DateTime.Now.Ticks;
List<string[]> imageFiles = new(); List<string[]> imageFiles = new();
bool updateDateWhenMatches = false; bool updateDateWhenMatches = false;
@ -135,14 +137,15 @@ internal class D2_FaceLandmarks
List<DateTime> dateTimes = (from l in subFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList(); List<DateTime> dateTimes = (from l in subFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList();
if (!Directory.Exists(facesDirectory)) if (!Directory.Exists(facesDirectory))
_ = Directory.CreateDirectory(facesDirectory); _ = Directory.CreateDirectory(facesDirectory);
for (int i = 0; i < faceCollections.Count; i++) foreach (IFace face in faceCollection)
{ {
if (!faceCollections[i].Populated) if (!face.Populated || face.Location?.NormalizedPixelPercentage is null)
{ {
imageFiles.Add(Array.Empty<string>()); imageFiles.Add(Array.Empty<string>());
continue; continue;
} }
fileInfo = new FileInfo(Path.Combine(facesDirectory, $"{i} - {item.ImageFileHolder.NameWithoutExtension}.png")); deterministicHashCodeKey = Named.GetDeterministicHashCodeKey(item, face);
fileInfo = new FileInfo(Path.Combine(facesDirectory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}.png"));
if (!fileInfo.Exists) if (!fileInfo.Exists)
{ {
if (fileInfo.Directory?.Parent is null) if (fileInfo.Directory?.Parent is null)
@ -153,7 +156,7 @@ internal class D2_FaceLandmarks
} }
if (string.IsNullOrEmpty(fileInfo.DirectoryName)) if (string.IsNullOrEmpty(fileInfo.DirectoryName))
continue; continue;
rotatedFileInfo = new FileInfo(Path.Combine(fileInfo.DirectoryName, string.Concat(Path.GetFileNameWithoutExtension(fileInfo.FullName), " - ", i, " - R", Path.GetExtension(fileInfo.FullName)))); rotatedFileInfo = new FileInfo(Path.Combine(fileInfo.DirectoryName, $"{deterministicHashCodeKey} - R{item.ImageFileHolder.ExtensionLowered}"));
imageFiles.Add(new string[] { fileInfo.FullName, rotatedFileInfo.FullName }); imageFiles.Add(new string[] { fileInfo.FullName, rotatedFileInfo.FullName });
if (check) if (check)
continue; continue;
@ -172,7 +175,7 @@ internal class D2_FaceLandmarks
} }
} }
if (check) if (check)
SaveFaceLandmarkImages(faceCollections, imageFiles, pointSize, item.ResizedFileHolder); SaveFaceLandmarkImages(faceCollection, imageFiles, pointSize, item.ResizedFileHolder);
} }
} }

View File

@ -8,7 +8,7 @@ using View_by_Distance.Metadata.Models;
using View_by_Distance.Property.Models; using View_by_Distance.Property.Models;
using View_by_Distance.Resize.Models; using View_by_Distance.Resize.Models;
using View_by_Distance.Shared.Models; using View_by_Distance.Shared.Models;
using View_by_Distance.Shared.Models.Methods; using View_by_Distance.Shared.Models.Properties;
using View_by_Distance.Shared.Models.Stateless; using View_by_Distance.Shared.Models.Stateless;
using WindowsShortcutFactory; using WindowsShortcutFactory;
@ -17,7 +17,7 @@ namespace View_by_Distance.Instance.Models;
/// <summary> /// <summary>
// List<D_Faces> // List<D_Faces>
/// </summary> /// </summary>
public class D_Face : Shared.Models.Properties.IFace, IFace public class D_Face : IFace, Shared.Models.Methods.IFace
{ {
internal List<string> AngleBracketCollection { get; } internal List<string> AngleBracketCollection { get; }
@ -116,7 +116,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
_RelativePath = relativePath; _RelativePath = relativePath;
} }
private D_Face(int outputResolutionWidth, int outputResolutionHeight, int outputResolutionOrientation, Shared.Models.Properties.IFace face) private D_Face(int outputResolutionWidth, int outputResolutionHeight, int outputResolutionOrientation, IFace face)
{ {
_Α = face.α; _Α = face.α;
_DateTime = face.DateTime; _DateTime = face.DateTime;
@ -290,6 +290,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
D_Face? face = null; D_Face? face = null;
Rectangle rectangle; Rectangle rectangle;
double[] rawEncoding; double[] rawEncoding;
double deterministicHashCodeKey;
Shared.Models.FaceEncoding faceEncoding; Shared.Models.FaceEncoding faceEncoding;
FaceRecognitionDotNet.Image? knownImage; FaceRecognitionDotNet.Image? knownImage;
FaceRecognitionDotNet.Image? rotatedImage; FaceRecognitionDotNet.Image? rotatedImage;
@ -368,7 +369,8 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
faceEncoding = new(rawEncoding, faceEncodings[0].Size); faceEncoding = new(rawEncoding, faceEncodings[0].Size);
face.Update(α, faceEncoding, populated: true); face.Update(α, faceEncoding, populated: true);
} }
faceFile = Path.Combine(facesDirectory, $"{i} - {item.ImageFileHolder.NameWithoutExtension}.png"); deterministicHashCodeKey = Named.GetDeterministicHashCodeKey(item, face);
faceFile = Path.Combine(facesDirectory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}.png");
preRotated.Save(faceFile, System.Drawing.Imaging.ImageFormat.Png); preRotated.Save(faceFile, System.Drawing.Imaging.ImageFormat.Png);
results.Add(face); results.Add(face);
} }
@ -508,6 +510,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
FileInfo fileInfo; FileInfo fileInfo;
bool check = false; bool check = false;
string parentCheck; string parentCheck;
double deterministicHashCodeKey;
List<string> imageFiles = new(); List<string> imageFiles = new();
string[] changesFrom = new string[] { nameof(A_Property), nameof(B_Metadata), nameof(C_Resize) }; string[] changesFrom = new string[] { nameof(A_Property), nameof(B_Metadata), nameof(C_Resize) };
string facesDirectory = Path.Combine(AngleBracketCollection[0].Replace("<>", "()"), item.ImageFileHolder.NameWithoutExtension); string facesDirectory = Path.Combine(AngleBracketCollection[0].Replace("<>", "()"), item.ImageFileHolder.NameWithoutExtension);
@ -515,14 +518,15 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
bool facesDirectoryExisted = Directory.Exists(facesDirectory); bool facesDirectoryExisted = Directory.Exists(facesDirectory);
if (!facesDirectoryExisted) if (!facesDirectoryExisted)
_ = Directory.CreateDirectory(facesDirectory); _ = Directory.CreateDirectory(facesDirectory);
for (int i = 0; i < faceCollection.Count; i++) foreach (IFace face in faceCollection)
{ {
if (!faceCollection[i].Populated || faceCollection[i]?.Location is null) if (!face.Populated || face.Location?.NormalizedPixelPercentage is null)
{ {
imageFiles.Add(string.Empty); imageFiles.Add(string.Empty);
continue; continue;
} }
fileInfo = new FileInfo(Path.Combine(facesDirectory, $"{i} - {item.ImageFileHolder.NameWithoutExtension}.png")); deterministicHashCodeKey = Named.GetDeterministicHashCodeKey(item, face);
fileInfo = new FileInfo(Path.Combine(facesDirectory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}.png"));
if (!fileInfo.Exists) if (!fileInfo.Exists)
{ {
if (fileInfo.Directory?.Parent is null) if (fileInfo.Directory?.Parent is null)
@ -552,12 +556,12 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
WindowsShortcut windowsShortcut; WindowsShortcut windowsShortcut;
const string pattern = @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]"; const string pattern = @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]";
string dFacesContentDirectory = Path.Combine(dResultsFullGroupDirectory, $"({ticks})"); string dFacesContentDirectory = Path.Combine(dResultsFullGroupDirectory, $"({ticks})");
List<(Item, (string, Shared.Models.Properties.IFace?, (string, string, string, string))[])> collections = Item.GetCollection(propertyLogic, items, dFacesContentDirectory); List<(Item, (string, IFace?, (string, string, string, string))[])> collections = Item.GetCollection(propertyLogic, items, dFacesContentDirectory);
foreach ((Item item, (string personKey, Shared.Models.Properties.IFace? _, (string, string, string, string))[] collection) in collections) foreach ((Item item, (string personKey, IFace? _, (string, string, string, string))[] collection) in collections)
{ {
if (collection.Length != 1) if (collection.Length != 1)
continue; continue;
foreach ((string personKey, Shared.Models.Properties.IFace? _, (string directory, string copyDirectory, string copyFileName, string shortcutFileName)) in collection) foreach ((string personKey, IFace? _, (string directory, string copyDirectory, string copyFileName, string shortcutFileName)) in collection)
{ {
if (string.IsNullOrEmpty(personKey)) if (string.IsNullOrEmpty(personKey))
continue; continue;

View File

@ -91,7 +91,7 @@ internal class E_Distance
for (int i = 0; i < distanceHolders.Count; i++) for (int i = 0; i < distanceHolders.Count; i++)
{ {
distanceHolder = distanceHolders[i]; distanceHolder = distanceHolders[i];
if (distanceHolder.Face.Location.NormalizedPixelPercentage is null) if (distanceHolder.Face.Location?.NormalizedPixelPercentage is null)
continue; continue;
check = Path.Combine(distanceHolder.JSONDirectory, $"{zero} - {distanceHolder.FileHolder.NameWithoutExtension}.json"); check = Path.Combine(distanceHolder.JSONDirectory, $"{zero} - {distanceHolder.FileHolder.NameWithoutExtension}.json");
jsonFile = Path.Combine(distanceHolder.JSONDirectory, $"{distanceHolder.Id}.{zero}{distanceHolder.FileHolder.ExtensionLowered}.json"); jsonFile = Path.Combine(distanceHolder.JSONDirectory, $"{distanceHolder.Id}.{zero}{distanceHolder.FileHolder.ExtensionLowered}.json");
@ -149,7 +149,7 @@ internal class E_Distance
locationIndex = 0; locationIndex = 0;
else else
locationIndex = distanceHolder.Face.LocationIndex.Value; locationIndex = distanceHolder.Face.LocationIndex.Value;
if (!distanceHolder.Face.Populated || distanceHolder.Face.Location.NormalizedPixelPercentage is null) if (!distanceHolder.Face.Populated || distanceHolder.Face.Location?.NormalizedPixelPercentage is null)
normalizedPixelPercentage = 0; normalizedPixelPercentage = 0;
else else
normalizedPixelPercentage = distanceHolder.Face.Location.NormalizedPixelPercentage.Value; normalizedPixelPercentage = distanceHolder.Face.Location.NormalizedPixelPercentage.Value;
@ -266,8 +266,6 @@ internal class E_Distance
check = true; check = true;
else if (hasPopulatedFace && !directoryInfo.Exists) else if (hasPopulatedFace && !directoryInfo.Exists)
check = true; check = true;
else if (hasPopulatedFace && !tvsDirectoryInfo.Exists)
check = true;
else if (dateTimes.Any() && dateTimes.Max() > directoryInfo.LastWriteTime) else if (dateTimes.Any() && dateTimes.Max() > directoryInfo.LastWriteTime)
check = true; check = true;
if (check && !updateDateWhenMatches) if (check && !updateDateWhenMatches)
@ -541,7 +539,7 @@ internal class E_Distance
else else
{ {
List<double> faceDistances = FaceRecognition.FaceDistances(tuple.FaceEncodings, faceEncoding); List<double> faceDistances = FaceRecognition.FaceDistances(tuple.FaceEncodings, faceEncoding);
result = new(face.LocationIndex, tuple.MinimumDateTime, tuple.IsWrongYear, tuple.PersonBirthday, faceDistances); result = new(face.Location?.NormalizedPixelPercentage, tuple.MinimumDateTime, tuple.IsWrongYear, tuple.PersonBirthday, faceDistances);
if (result.Minimum > Closest.MaximumMinimum) if (result.Minimum > Closest.MaximumMinimum)
result = null; result = null;
} }
@ -563,7 +561,7 @@ internal class E_Distance
if (itemIsWrongYear.HasValue && !itemIsWrongYear.Value && itemMinimumDateTime < personBirthday.Value) if (itemIsWrongYear.HasValue && !itemIsWrongYear.Value && itemMinimumDateTime < personBirthday.Value)
continue; continue;
faceDistances = FaceRecognition.FaceDistances(faceEncodings, faceEncoding); faceDistances = FaceRecognition.FaceDistances(faceEncodings, faceEncoding);
closest = new(face.LocationIndex, minimumDateTime, isWrongYear, personBirthday, faceDistances); closest = new(face.Location?.NormalizedPixelPercentage, minimumDateTime, isWrongYear, personBirthday, faceDistances);
if (closest.Minimum > Closest.MaximumMinimum) if (closest.Minimum > Closest.MaximumMinimum)
continue; continue;
closestCollection.Add(closest); closestCollection.Add(closest);
@ -596,7 +594,7 @@ internal class E_Distance
bool? itemIsWrongYear; bool? itemIsWrongYear;
Closest[] closestCollection; Closest[] closestCollection;
DateTime? itemMinimumDateTime; DateTime? itemMinimumDateTime;
float deterministicHashCodeKey; double deterministicHashCodeKey;
Dictionary<string, int> results = new(); Dictionary<string, int> results = new();
foreach (Container container in containers) foreach (Container container in containers)
{ {
@ -618,7 +616,7 @@ internal class E_Distance
for (int i = 0; i < item.Faces.Count; i++) for (int i = 0; i < item.Faces.Count; i++)
{ {
face = item.Faces[i]; face = item.Faces[i];
closest = new(face.LocationIndex, itemMinimumDateTime.Value, itemIsWrongYear); closest = new(face.Location?.NormalizedPixelPercentage, itemMinimumDateTime.Value, itemIsWrongYear);
item.Closest.Add(closest); item.Closest.Add(closest);
if (!face.Populated) if (!face.Populated)
continue; continue;
@ -728,7 +726,7 @@ internal class E_Distance
string facesDirectory; string facesDirectory;
string personDirectory; string personDirectory;
Shared.Models.Person person; Shared.Models.Person person;
float deterministicHashCodeKey; double deterministicHashCodeKey;
const string facePopulatedKey = "Closest"; const string facePopulatedKey = "Closest";
const string pattern = @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]"; const string pattern = @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]";
foreach (Container container in containers) foreach (Container container in containers)
@ -758,17 +756,17 @@ internal class E_Distance
{ {
person = peopleCollection[personKey][0]; person = peopleCollection[personKey][0];
personName = Shared.Models.Stateless.Methods.IPersonName.GetFullName(person.Name); personName = Shared.Models.Stateless.Methods.IPersonName.GetFullName(person.Name);
personDirectory = Path.Combine(directory, Regex.Replace(personName, pattern, string.Empty)); personDirectory = Path.Combine(directory, Regex.Replace(personName, pattern, string.Empty), "lnk");
results.Add(new(null, personDirectory, null, string.Empty, string.Empty)); results.Add(new(null, personDirectory, null, string.Empty, string.Empty));
} }
facesDirectory = string.Concat(dFacesContentDirectory, Path.Combine(directoryName, item.ImageFileHolder.NameWithoutExtension)); facesDirectory = string.Concat(dFacesContentDirectory, Path.Combine(directoryName, item.ImageFileHolder.NameWithoutExtension));
faceFileInfo = new(Path.Combine(facesDirectory, $"{closest.NormalizedPixelPercentage.Value} - {item.ImageFileHolder.NameWithoutExtension}.png"));
deterministicHashCodeKey = Named.GetDeterministicHashCodeKey(item, closest); deterministicHashCodeKey = Named.GetDeterministicHashCodeKey(item, closest);
checkFile = Path.Combine(directory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}"); checkFile = Path.Combine(directory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}");
faceFileInfo = new(Path.Combine(facesDirectory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}.png"));
if (string.IsNullOrEmpty(personDirectory)) if (string.IsNullOrEmpty(personDirectory))
shortcutFile = string.Empty; shortcutFile = string.Empty;
else else
shortcutFile = Path.Combine(personDirectory, $"{item.ImageFileHolder.ExtensionLowered}.lnk"); shortcutFile = Path.Combine(personDirectory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}.lnk");
results.Add(new(item.ResizedFileHolder, directory, faceFileInfo, checkFile, shortcutFile)); results.Add(new(item.ResizedFileHolder, directory, faceFileInfo, checkFile, shortcutFile));
} }
} }
@ -799,11 +797,11 @@ internal class E_Distance
else else
File.Copy(resizedFileHolder.FullName, checkFile); File.Copy(resizedFileHolder.FullName, checkFile);
} }
foreach ((FileHolder? resizedFileHolder, string directory, FileInfo? faceFileInfo, string checkFile, string shortcutFile) in collection) foreach ((FileHolder? resizedFileHolder, string directory, FileInfo? _, string checkFile, string shortcutFile) in collection)
{ {
if (string.IsNullOrEmpty(directory) || string.IsNullOrEmpty(checkFile) || resizedFileHolder is null || faceFileInfo is null) if (string.IsNullOrEmpty(directory) || string.IsNullOrEmpty(checkFile) || resizedFileHolder is null)
continue; continue;
if (string.IsNullOrEmpty(shortcutFile)) if (string.IsNullOrEmpty(shortcutFile) || !resizedFileHolder.Exists)
continue; continue;
try try
{ {

View File

@ -50,11 +50,12 @@
"WorkingDirectoryName": "PharesApps", "WorkingDirectoryName": "PharesApps",
"Windows": { "Windows": {
"Configuration": { "Configuration": {
"CheckJsonForDistanceResults": true, "CheckJsonForDistanceResults": false,
"CrossDirectoryMaxItemsInDistanceCollection": 7, "CrossDirectoryMaxItemsInDistanceCollection": 7,
"DateGroup": "2022-08-14", "DateGroup": "2022-08-14",
"DistanceFactor": 8, "DistanceFactor": 8,
"FileNameDirectorySeparator": ".Z.", "FileNameDirectorySeparator": ".Z.",
"ForceFaceLastWriteTimeToCreationTime": false,
"ForceMetadataLastWriteTimeToCreationTime": false, "ForceMetadataLastWriteTimeToCreationTime": false,
"ForcePropertyLastWriteTimeToCreationTime": false, "ForcePropertyLastWriteTimeToCreationTime": false,
"ForceResizeLastWriteTimeToCreationTime": false, "ForceResizeLastWriteTimeToCreationTime": false,

View File

@ -50,7 +50,7 @@
"WorkingDirectoryName": "PharesApps", "WorkingDirectoryName": "PharesApps",
"Windows": { "Windows": {
"Configuration": { "Configuration": {
"CheckJsonForDistanceResults": true, "CheckJsonForDistanceResults": false,
"CrossDirectoryMaxItemsInDistanceCollection": 7, "CrossDirectoryMaxItemsInDistanceCollection": 7,
"DateGroup": "2022-08-14", "DateGroup": "2022-08-14",
"DistanceFactor": 8, "DistanceFactor": 8,

View File

@ -50,7 +50,7 @@
"WorkingDirectoryName": "PharesApps", "WorkingDirectoryName": "PharesApps",
"Windows": { "Windows": {
"Configuration": { "Configuration": {
"CheckJsonForDistanceResults": true, "CheckJsonForDistanceResults": false,
"CrossDirectoryMaxItemsInDistanceCollection": 7, "CrossDirectoryMaxItemsInDistanceCollection": 7,
"DateGroup": "2022-08-14", "DateGroup": "2022-08-14",
"DistanceFactor": 8, "DistanceFactor": 8,

View File

@ -96,7 +96,7 @@ public class Item
bool? isWrongYear; bool? isWrongYear;
DateTime minimumDateTime; DateTime minimumDateTime;
PersonBirthday? personBirthday; PersonBirthday? personBirthday;
float deterministicHashCodeKey; double deterministicHashCodeKey;
List<string> personKeys = new(); List<string> personKeys = new();
foreach (Item item in items) foreach (Item item in items)
{ {
@ -300,7 +300,7 @@ public class Item
continue; continue;
if (named.PersonBirthday is null) if (named.PersonBirthday is null)
continue; continue;
if (named.NormalizedPixelPercentage.HasValue && named.NormalizedPixelPercentage.Value != face.Location.NormalizedPixelPercentage) if (named.NormalizedPixelPercentage.HasValue && named.NormalizedPixelPercentage.Value != face.Location?.NormalizedPixelPercentage)
continue; continue;
key = GetKey(named.MinimumDateTime, named.IsWrongYear, named.PersonBirthday); key = GetKey(named.MinimumDateTime, named.IsWrongYear, named.PersonBirthday);
if (!results.ContainsKey(key)) if (!results.ContainsKey(key))

View File

@ -29,57 +29,114 @@ public class Named
this(isWrongYear, minimumDateTime, null, personBirthday) this(isWrongYear, minimumDateTime, null, personBirthday)
{ } { }
private static float GetDeterministicHashCodeFileName(int id, int normalizedPixelPercentage) private static double GetDeterministicHashCodeFileName(int id, int normalizedPixelPercentage)
=> float.Parse($"{id}.{normalizedPixelPercentage}"); => double.Parse($"{id}.{normalizedPixelPercentage}");
public static float GetDeterministicHashCodeKey(Item item, Closest closest) public static double GetDeterministicHashCodeKey(Item item, Closest closest)
{ {
float result; double result;
if (item.Property?.Id is null || item.ImageFileHolder is null || closest.NormalizedPixelPercentage is null) if (item.Property?.Id is null || item.ImageFileHolder is null || closest.NormalizedPixelPercentage is null)
throw new NullReferenceException(); throw new NullReferenceException();
result = GetDeterministicHashCodeFileName(item.Property.Id.Value, closest.NormalizedPixelPercentage.Value); result = GetDeterministicHashCodeFileName(item.Property.Id.Value, closest.NormalizedPixelPercentage.Value);
return result; return result;
} }
public static float GetDeterministicHashCodeKey(Item item, IFace face) public static double GetDeterministicHashCodeKey(Item item, IFace face)
{ {
float result; double result;
if (item.Property?.Id is null || item.ImageFileHolder is null || face.Location?.NormalizedPixelPercentage is null) if (item.Property?.Id is null || item.ImageFileHolder is null || face.Location?.NormalizedPixelPercentage is null)
throw new NullReferenceException(); throw new NullReferenceException();
result = GetDeterministicHashCodeFileName(item.Property.Id.Value, face.Location.NormalizedPixelPercentage.Value); result = GetDeterministicHashCodeFileName(item.Property.Id.Value, face.Location.NormalizedPixelPercentage.Value);
return result; return result;
} }
public static float? GetReversedDeterministicHashCode(Dictionary<int, List<IFace>> keyValuePairs, string fileName) public static double? GetReversedDeterministicHashCode(string fileName)
{
double? result;
if (fileName.Length < 2 || fileName[1..].Contains('-'))
result = null;
else
{ {
float? result;
string[] segments = fileName.Split('.'); string[] segments = fileName.Split('.');
if (segments.Length < 2) if (segments.Length < 2)
throw new Exception(); throw new Exception();
string id = segments[0]; string id = segments[0];
string normalizedPixelPercentage; string normalizedPixelPercentage = segments[1];
if (!id.Contains('-')) if (!double.TryParse(string.Concat(id, '.', normalizedPixelPercentage), out double resultValue))
normalizedPixelPercentage = segments[1];
else
{
segments = fileName.Split(' ');
if (segments.Length < 3)
throw new Exception();
id = segments[2];
string locationIdex = segments[0];
if (int.TryParse(id, out int idValue) && int.TryParse(locationIdex, out int locationIndexValue) && keyValuePairs.ContainsKey(idValue) && keyValuePairs[idValue].Count > locationIndexValue)
normalizedPixelPercentage = string.Concat(keyValuePairs[idValue][locationIndexValue].Location.NormalizedPixelPercentage);
else
{
id = string.Empty;
normalizedPixelPercentage = string.Empty;
}
}
if (!float.TryParse(string.Concat(id, '.', normalizedPixelPercentage), out float resultValue))
result = null; result = null;
else else
result = resultValue; result = resultValue;
}
return result; return result;
} }
public static (string?, double?) GetReversedDeterministicHashCode(Dictionary<int, List<IFace>> keyValuePairs, string file)
{
double? result;
string? check;
string fileName = Path.GetFileName(file);
if (!fileName.Contains('-'))
{
check = null;
result = null;
}
else
{
string id;
int? normalizedPixelPercentage;
if (!keyValuePairs.Any())
{
check = null;
id = string.Empty;
normalizedPixelPercentage = null;
}
else
{
string[] segments = fileName.Split(' ');
if (segments.Length < 3)
throw new Exception();
id = segments[2].Split('.')[0];
string locationIdex = segments[0];
if (!int.TryParse(id, out int idValue) || !int.TryParse(locationIdex, out int locationIndexValue) || !keyValuePairs.ContainsKey(idValue))
{
check = null;
id = string.Empty;
normalizedPixelPercentage = null;
}
else
{
List<IFace> faces = keyValuePairs[idValue];
if (faces.Count <= locationIndexValue)
{
check = null;
id = string.Empty;
normalizedPixelPercentage = null;
}
else
{
IFace face = faces[locationIndexValue];
if (face.Location?.NormalizedPixelPercentage is null)
{
check = null;
id = string.Empty;
normalizedPixelPercentage = null;
}
else
{
string extensionLowered = Path.GetExtension(file).ToLower();
normalizedPixelPercentage = face.Location.NormalizedPixelPercentage.Value;
double deterministicHashCodeKey = GetDeterministicHashCodeFileName(idValue, normalizedPixelPercentage.Value);
check = Path.Combine(string.Concat(Path.GetDirectoryName(file)), $"{deterministicHashCodeKey}{extensionLowered}");
}
}
}
}
if (normalizedPixelPercentage is null || !double.TryParse(string.Concat(id, '.', normalizedPixelPercentage.Value), out double resultValue))
result = null;
else
result = resultValue;
}
return new(check, result);
}
} }

View File

@ -22,8 +22,8 @@ public class PropertyLogic
protected readonly string _DeterministicHashCodeRootDirectory; protected readonly string _DeterministicHashCodeRootDirectory;
protected readonly Dictionary<int, string[]> _SixCharacterNamedFaceInfo; protected readonly Dictionary<int, string[]> _SixCharacterNamedFaceInfo;
protected readonly Dictionary<int, string[]> _NamedFaceInfoDeterministicHashCodeKeyValuePairs; protected readonly Dictionary<int, string[]> _NamedFaceInfoDeterministicHashCodeKeyValuePairs;
protected readonly Dictionary<float, string[]> _NamedDeterministicHashCodeKeyValuePairs; protected readonly Dictionary<double, string[]> _NamedDeterministicHashCodeKeyValuePairs;
protected readonly Dictionary<float, string[]> _IncorrectDeterministicHashCodeKeyValuePairs; protected readonly Dictionary<double, string[]> _IncorrectDeterministicHashCodeKeyValuePairs;
public bool Reverse { get; } public bool Reverse { get; }
public List<string> AngleBracketCollection { get; } public List<string> AngleBracketCollection { get; }
@ -31,8 +31,8 @@ public class PropertyLogic
public Dictionary<int, int[]> IndicesFromNew => _IndicesFromNew; public Dictionary<int, int[]> IndicesFromNew => _IndicesFromNew;
public List<string> ExceptionsDirectories => _ExceptionsDirectories; public List<string> ExceptionsDirectories => _ExceptionsDirectories;
public string DeterministicHashCodeRootDirectory => _DeterministicHashCodeRootDirectory; public string DeterministicHashCodeRootDirectory => _DeterministicHashCodeRootDirectory;
public Dictionary<float, string[]> NamedDeterministicHashCodeKeyValuePairs => _NamedDeterministicHashCodeKeyValuePairs; public Dictionary<double, string[]> NamedDeterministicHashCodeKeyValuePairs => _NamedDeterministicHashCodeKeyValuePairs;
public Dictionary<float, string[]> IncorrectDeterministicHashCodeKeyValuePairs => _IncorrectDeterministicHashCodeKeyValuePairs; public Dictionary<double, string[]> IncorrectDeterministicHashCodeKeyValuePairs => _IncorrectDeterministicHashCodeKeyValuePairs;
public Dictionary<int, string[]> NamedFaceInfoDeterministicHashCodeKeyValuePairs => _NamedFaceInfoDeterministicHashCodeKeyValuePairs; public Dictionary<int, string[]> NamedFaceInfoDeterministicHashCodeKeyValuePairs => _NamedFaceInfoDeterministicHashCodeKeyValuePairs;
private readonly Model? _Model; private readonly Model? _Model;
@ -69,8 +69,8 @@ public class PropertyLogic
List<KeyValuePair<int, int[]>>? collection; List<KeyValuePair<int, int[]>>? collection;
Dictionary<int, int[]> indicesFromNew = new(); Dictionary<int, int[]> indicesFromNew = new();
Dictionary<int, string[]>? sixCharacterNamedFaceInfo; Dictionary<int, string[]>? sixCharacterNamedFaceInfo;
Dictionary<float, string[]> namedDeterministicHashCode = new(); Dictionary<double, string[]> namedDeterministicHashCode = new();
Dictionary<float, string[]> incorrectDeterministicHashCode = new(); Dictionary<double, string[]> incorrectDeterministicHashCode = new();
string? rootDirectoryParent = Path.GetDirectoryName(configuration.RootDirectory); string? rootDirectoryParent = Path.GetDirectoryName(configuration.RootDirectory);
if (string.IsNullOrEmpty(rootDirectoryParent)) if (string.IsNullOrEmpty(rootDirectoryParent))
throw new NullReferenceException(nameof(rootDirectoryParent)); throw new NullReferenceException(nameof(rootDirectoryParent));
@ -84,9 +84,19 @@ public class PropertyLogic
if (namedFaceInfoDeterministicHashCode is null) if (namedFaceInfoDeterministicHashCode is null)
throw new NullReferenceException(nameof(namedFaceInfoDeterministicHashCode)); throw new NullReferenceException(nameof(namedFaceInfoDeterministicHashCode));
} }
if (namedFaceInfoDeterministicHashCode.Any()) string[] directories = Directory.GetDirectories(rootDirectoryParent, "*DeterministicHashCode*", SearchOption.TopDirectoryOnly);
{ if (!directories.Any())
deterministicHashCodeRootDirectory = string.Empty; deterministicHashCodeRootDirectory = string.Empty;
else
{
Dictionary<int, List<IFace>> faces = new();
deterministicHashCodeRootDirectory = directories[0];
SetKeyValuePairs(deterministicHashCodeRootDirectory, namedDeterministicHashCode, incorrectDeterministicHashCode, faces);
}
if (!namedFaceInfoDeterministicHashCode.Any())
sixCharacterNamedFaceInfo = new();
else
{
files = Directory.GetFiles(rootDirectoryParent, "*SixCharacter*.json", SearchOption.TopDirectoryOnly); files = Directory.GetFiles(rootDirectoryParent, "*SixCharacter*.json", SearchOption.TopDirectoryOnly);
if (files.Length != 1) if (files.Length != 1)
sixCharacterNamedFaceInfo = new(); sixCharacterNamedFaceInfo = new();
@ -98,19 +108,6 @@ public class PropertyLogic
throw new NullReferenceException(nameof(sixCharacterNamedFaceInfo)); throw new NullReferenceException(nameof(sixCharacterNamedFaceInfo));
} }
} }
else
{
sixCharacterNamedFaceInfo = new();
string[] directories = Directory.GetDirectories(rootDirectoryParent, "*DeterministicHashCode*", SearchOption.TopDirectoryOnly);
if (!directories.Any())
deterministicHashCodeRootDirectory = string.Empty;
else
{
Dictionary<int, List<IFace>> faces = new();
deterministicHashCodeRootDirectory = directories[0];
SetKeyValuePairs(deterministicHashCodeRootDirectory, namedDeterministicHashCode, incorrectDeterministicHashCode, faces);
}
}
files = Directory.GetFiles(rootDirectoryParent, "*keyValuePairs*.json", SearchOption.TopDirectoryOnly); files = Directory.GetFiles(rootDirectoryParent, "*keyValuePairs*.json", SearchOption.TopDirectoryOnly);
if (files.Length != 1) if (files.Length != 1)
keyValuePairs = new(); keyValuePairs = new();
@ -148,15 +145,16 @@ public class PropertyLogic
_NamedFaceInfoDeterministicHashCodeKeyValuePairs = namedFaceInfoDeterministicHashCode; _NamedFaceInfoDeterministicHashCodeKeyValuePairs = namedFaceInfoDeterministicHashCode;
} }
private static void SetKeyValuePairs(string deterministicHashCodeRootDirectory, List<(string, float)> named, List<(string, float)> incorrect, Dictionary<int, List<IFace>> keyValuePairs) private static void SetKeyValuePairs(string deterministicHashCodeRootDirectory, List<(string, double)> named, List<(string, double)> incorrect, Dictionary<int, List<IFace>> keyValuePairs)
{ {
string[] files; string[] files;
string fileName; string fileName;
string personKey; string personKey;
string? checkFile;
string[] yearDirectories; string[] yearDirectories;
string[] personKeyDirectories; string[] personKeyDirectories;
string[] personNameDirectories; string[] personNameDirectories;
float? idAndNormalizedPixelPercentage; double? idAndNormalizedPixelPercentage;
string[] ticksDirectories = Directory.GetDirectories(deterministicHashCodeRootDirectory, "*", SearchOption.TopDirectoryOnly); string[] ticksDirectories = Directory.GetDirectories(deterministicHashCodeRootDirectory, "*", SearchOption.TopDirectoryOnly);
foreach (string ticksDirectory in ticksDirectories) foreach (string ticksDirectory in ticksDirectories)
{ {
@ -176,9 +174,15 @@ public class PropertyLogic
if (file.EndsWith(".lnk")) if (file.EndsWith(".lnk"))
continue; continue;
fileName = Path.GetFileName(file); fileName = Path.GetFileName(file);
idAndNormalizedPixelPercentage = Named.GetReversedDeterministicHashCode(keyValuePairs, fileName); idAndNormalizedPixelPercentage = Named.GetReversedDeterministicHashCode(fileName);
if (idAndNormalizedPixelPercentage is null)
{
(checkFile, idAndNormalizedPixelPercentage) = Named.GetReversedDeterministicHashCode(keyValuePairs, file);
if (idAndNormalizedPixelPercentage is null) if (idAndNormalizedPixelPercentage is null)
break; break;
if (!string.IsNullOrEmpty(checkFile))
File.Move(file, checkFile);
}
incorrect.Add(new(personKey, idAndNormalizedPixelPercentage.Value)); incorrect.Add(new(personKey, idAndNormalizedPixelPercentage.Value));
} }
foreach (string personNameDirectory in personNameDirectories) foreach (string personNameDirectory in personNameDirectories)
@ -188,10 +192,16 @@ public class PropertyLogic
{ {
if (file.EndsWith(".lnk")) if (file.EndsWith(".lnk"))
continue; continue;
fileName = Path.GetFileNameWithoutExtension(file); fileName = Path.GetFileName(file);
idAndNormalizedPixelPercentage = Named.GetReversedDeterministicHashCode(keyValuePairs, fileName); idAndNormalizedPixelPercentage = Named.GetReversedDeterministicHashCode(fileName);
if (idAndNormalizedPixelPercentage is null)
{
(checkFile, idAndNormalizedPixelPercentage) = Named.GetReversedDeterministicHashCode(keyValuePairs, file);
if (idAndNormalizedPixelPercentage is null) if (idAndNormalizedPixelPercentage is null)
break; break;
if (!string.IsNullOrEmpty(checkFile))
File.Move(file, checkFile);
}
named.Add(new(personKey, idAndNormalizedPixelPercentage.Value)); named.Add(new(personKey, idAndNormalizedPixelPercentage.Value));
} }
} }
@ -200,51 +210,57 @@ public class PropertyLogic
} }
} }
private static void SetKeyValuePairs(string deterministicHashCodeRootDirectory, Dictionary<float, string[]> namedDeterministicHashCode, Dictionary<float, string[]> incorrectDeterministicHashCode, Dictionary<int, List<IFace>> keyValuePairs) private static void SetKeyValuePairs(string deterministicHashCodeRootDirectory, Dictionary<double, string[]> namedDeterministicHashCode, Dictionary<double, string[]> incorrectDeterministicHashCode, Dictionary<int, List<IFace>> keyValuePairs)
{ {
Dictionary<float, List<string>> namedKeyValuePairs = new(); Dictionary<double, List<string>> namedKeyValuePairs = new();
Dictionary<float, List<string>> incorrectKeyValuePairs = new(); Dictionary<double, List<string>> incorrectKeyValuePairs = new();
List<(string PersonKey, float IdAndNormalizedPixelPercentage)> named = new(); List<(string PersonKey, double IdAndNormalizedPixelPercentage)> named = new();
List<(string PersonKey, float IdAndNormalizedPixelPercentage)> incorrect = new(); List<(string PersonKey, double IdAndNormalizedPixelPercentage)> incorrect = new();
SetKeyValuePairs(deterministicHashCodeRootDirectory, named, incorrect, keyValuePairs); SetKeyValuePairs(deterministicHashCodeRootDirectory, named, incorrect, keyValuePairs);
named = (from l in named orderby l.IdAndNormalizedPixelPercentage select l).ToList(); named = (from l in named orderby l.IdAndNormalizedPixelPercentage select l).ToList();
incorrect = (from l in incorrect orderby l.IdAndNormalizedPixelPercentage select l).ToList(); incorrect = (from l in incorrect orderby l.IdAndNormalizedPixelPercentage select l).ToList();
foreach ((string personKey, float idAndNormalizedPixelPercentage) in named) foreach ((string personKey, double idAndNormalizedPixelPercentage) in named)
{ {
if (!namedKeyValuePairs.ContainsKey(idAndNormalizedPixelPercentage)) if (!namedKeyValuePairs.ContainsKey(idAndNormalizedPixelPercentage))
namedKeyValuePairs.Add(idAndNormalizedPixelPercentage, new()); namedKeyValuePairs.Add(idAndNormalizedPixelPercentage, new());
namedKeyValuePairs[idAndNormalizedPixelPercentage].Add(personKey); namedKeyValuePairs[idAndNormalizedPixelPercentage].Add(personKey);
} }
foreach ((string personKey, float idAndNormalizedPixelPercentage) in incorrect) foreach ((string personKey, double idAndNormalizedPixelPercentage) in incorrect)
{ {
if (!incorrectKeyValuePairs.ContainsKey(idAndNormalizedPixelPercentage)) if (!incorrectKeyValuePairs.ContainsKey(idAndNormalizedPixelPercentage))
incorrectKeyValuePairs.Add(idAndNormalizedPixelPercentage, new()); incorrectKeyValuePairs.Add(idAndNormalizedPixelPercentage, new());
incorrectKeyValuePairs[idAndNormalizedPixelPercentage].Add(personKey); incorrectKeyValuePairs[idAndNormalizedPixelPercentage].Add(personKey);
} }
foreach (KeyValuePair<float, List<string>> keyValuePair in namedKeyValuePairs) foreach (KeyValuePair<double, List<string>> keyValuePair in namedKeyValuePairs)
namedDeterministicHashCode.Add(keyValuePair.Key, keyValuePair.Value.Distinct().ToArray()); namedDeterministicHashCode.Add(keyValuePair.Key, keyValuePair.Value.Distinct().ToArray());
foreach (KeyValuePair<float, List<string>> keyValuePair in incorrectKeyValuePairs) foreach (KeyValuePair<double, List<string>> keyValuePair in incorrectKeyValuePairs)
incorrectDeterministicHashCode.Add(keyValuePair.Key, keyValuePair.Value.Distinct().ToArray()); incorrectDeterministicHashCode.Add(keyValuePair.Key, keyValuePair.Value.Distinct().ToArray());
} }
public void UpdateKeyValuePairs(List<Container> containers) public void UpdateKeyValuePairs(List<Container> containers)
{ {
Dictionary<int, List<IFace>> keyValuePairs = new(); Dictionary<int, List<IFace>> keyValuePairs = new();
Dictionary<float, string[]> namedDeterministicHashCode = new(); Dictionary<double, string[]> namedDeterministicHashCode = new();
Dictionary<float, string[]> incorrectDeterministicHashCode = new(); Dictionary<double, string[]> incorrectDeterministicHashCode = new();
foreach (Container container in containers) foreach (Container container in containers)
{ {
foreach (Item item in container.Items) foreach (Item item in container.Items)
{ {
if (item.ImageFileHolder is null || item.Property?.Id is null || !item.Faces.Any()) if (item.ImageFileHolder is null || item.Property?.Id is null || !item.Faces.Any())
continue; continue;
if (keyValuePairs.ContainsKey(item.Property.Id.Value))
{
if (keyValuePairs[item.Property.Id.Value].Count != item.Faces.Count)
throw new Exception();
continue;
}
keyValuePairs.Add(item.Property.Id.Value, item.Faces); keyValuePairs.Add(item.Property.Id.Value, item.Faces);
} }
} }
SetKeyValuePairs(_DeterministicHashCodeRootDirectory, namedDeterministicHashCode, incorrectDeterministicHashCode, keyValuePairs); SetKeyValuePairs(_DeterministicHashCodeRootDirectory, namedDeterministicHashCode, incorrectDeterministicHashCode, keyValuePairs);
foreach (KeyValuePair<float, string[]> keyValuePair in namedDeterministicHashCode) foreach (KeyValuePair<double, string[]> keyValuePair in namedDeterministicHashCode)
_NamedDeterministicHashCodeKeyValuePairs.Add(keyValuePair.Key, keyValuePair.Value); _NamedDeterministicHashCodeKeyValuePairs.Add(keyValuePair.Key, keyValuePair.Value);
foreach (KeyValuePair<float, string[]> keyValuePair in incorrectDeterministicHashCode) foreach (KeyValuePair<double, string[]> keyValuePair in incorrectDeterministicHashCode)
_IncorrectDeterministicHashCodeKeyValuePairs.Add(keyValuePair.Key, keyValuePair.Value); _IncorrectDeterministicHashCodeKeyValuePairs.Add(keyValuePair.Key, keyValuePair.Value);
} }

View File

@ -23,6 +23,8 @@ public class Location : Properties.ILocation, ILocation, IEquatable<Location>
[JsonConstructor] [JsonConstructor]
public Location(int bottom, double confidence, int left, int? normalizedPixelPercentage, int right, int top) public Location(int bottom, double confidence, int left, int? normalizedPixelPercentage, int right, int top)
{ {
if (normalizedPixelPercentage < 0)
normalizedPixelPercentage = 3;
_Confidence = confidence; _Confidence = confidence;
_Bottom = bottom; _Bottom = bottom;
_Left = left; _Left = left;
@ -63,11 +65,15 @@ public class Location : Properties.ILocation, ILocation, IEquatable<Location>
public static int GetNormalizedPixelPercentage(int bottom, int height, int left, int right, int top, int width) public static int GetNormalizedPixelPercentage(int bottom, int height, int left, int right, int top, int width)
{ {
double result; int result;
double value;
double xCenter = left + ((right - left) / 2); double xCenter = left + ((right - left) / 2);
double yCenter = top + ((bottom - top) / 2); double yCenter = top + ((bottom - top) / 2);
result = ((yCenter * width) + xCenter) / (width * height); value = ((yCenter * width) + xCenter) / (width * height);
return (int)(Math.Round((decimal)result, 4) * Stateless.Methods.ILocation.Factor); if (value < 0)
value = 3;
result = (int)(Math.Round((decimal)value, 4) * Stateless.Methods.ILocation.Factor);
return result;
} }
public bool Equals(Location? location) public bool Equals(Location? location)

View File

@ -50,7 +50,7 @@
"WorkingDirectoryName": "PharesApps", "WorkingDirectoryName": "PharesApps",
"Windows": { "Windows": {
"Configuration": { "Configuration": {
"CheckJsonForDistanceResults": true, "CheckJsonForDistanceResults": false,
"CrossDirectoryMaxItemsInDistanceCollection": 7, "CrossDirectoryMaxItemsInDistanceCollection": 7,
"DateGroup": "2022-08-14", "DateGroup": "2022-08-14",
"DistanceFactor": 8, "DistanceFactor": 8,

View File

@ -50,7 +50,7 @@
"WorkingDirectoryName": "PharesApps", "WorkingDirectoryName": "PharesApps",
"Windows": { "Windows": {
"Configuration": { "Configuration": {
"CheckJsonForDistanceResults": true, "CheckJsonForDistanceResults": false,
"CrossDirectoryMaxItemsInDistanceCollection": 7, "CrossDirectoryMaxItemsInDistanceCollection": 7,
"DateGroup": "2022-08-14", "DateGroup": "2022-08-14",
"DistanceFactor": 8, "DistanceFactor": 8,

View File

@ -50,7 +50,7 @@
"WorkingDirectoryName": "PharesApps", "WorkingDirectoryName": "PharesApps",
"Windows": { "Windows": {
"Configuration": { "Configuration": {
"CheckJsonForDistanceResults": true, "CheckJsonForDistanceResults": false,
"CrossDirectoryMaxItemsInDistanceCollection": 7, "CrossDirectoryMaxItemsInDistanceCollection": 7,
"DateGroup": "2022-08-14", "DateGroup": "2022-08-14",
"DistanceFactor": 8, "DistanceFactor": 8,

View File

@ -50,7 +50,7 @@
"WorkingDirectoryName": "PharesApps", "WorkingDirectoryName": "PharesApps",
"Windows": { "Windows": {
"Configuration": { "Configuration": {
"CheckJsonForDistanceResults": true, "CheckJsonForDistanceResults": false,
"CrossDirectoryMaxItemsInDistanceCollection": 7, "CrossDirectoryMaxItemsInDistanceCollection": 7,
"DateGroup": "2022-08-14", "DateGroup": "2022-08-14",
"DistanceFactor": 8, "DistanceFactor": 8,