From 7390c13751d673eeec5cd5c7f995df7b753cdfeb Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Thu, 15 Sep 2022 08:23:03 -0700 Subject: [PATCH] Strip old way --- Instance/DlibDotNet.cs | 13 +- Map/Models/MapLogic.cs | 259 +++++------------- .../Stateless/SetByDeterministicHashCode.cs | 87 +++--- Shared/Models/Stateless/IFaceDistance.cs | 7 +- Shared/Models/Stateless/IMapping.cs | 6 - Shared/Models/Stateless/ISorting.cs | 5 +- 6 files changed, 124 insertions(+), 253 deletions(-) diff --git a/Instance/DlibDotNet.cs b/Instance/DlibDotNet.cs index 3e35377..3065081 100644 --- a/Instance/DlibDotNet.cs +++ b/Instance/DlibDotNet.cs @@ -714,15 +714,6 @@ public partial class DlibDotNet return results; } - private void OldMapLogic(long ticks, string dResultsFullGroupDirectory, string d2ResultsFullGroupDirectory, MapLogic mapLogic, string outputResolution, Item[] filteredItems) - { - string dFacesContentDirectory = Path.Combine(dResultsFullGroupDirectory, "()"); - if (_Configuration.SaveShortcutsForOutputResolutions.Contains(outputResolution)) - mapLogic.SaveShortcuts(_Configuration.JuliePhares, filteredItems); - mapLogic.SavePropertyHolders(filteredItems); - _ = LogDeltaInSeconds(ticks, nameof(mapLogic.SavePropertyHolders)); - } - private void Search(Property.Models.Configuration configuration, Model? model, PredictorModel? predictorModel, string argZero, string propertyRoot, Person[] people) { Container[] containers; @@ -765,8 +756,8 @@ public partial class DlibDotNet List distinctFilteredFaces = SetMappingThenGetDistinctFilteredFacesWithMapping(argZero, containers); SortingContainer[] sortingContainers = E_Distance.SetPersonTicksAndSetFaceDistancesAndSetFaceMappingSortingCollectionThenGetSortingContainers(_AppSettings.MaxDegreeOfParallelism, ticks, mapLogic, outputResolution, eDistanceContentFileName, distinctFilteredFaces); mapLogic.CommonWork(_AppSettings.MaxDegreeOfParallelism, dFacesContentDirectory, d2ResultsFullGroupDirectory, distinctFilteredFaces, sortingContainers); - Item[] filteredItems = GetIdSortedFilteredItems(argZero, containers); - OldMapLogic(ticks, dResultsFullGroupDirectory, d2ResultsFullGroupDirectory, mapLogic, outputResolution, filteredItems); + if (_Configuration.SaveShortcutsForOutputResolutions.Contains(outputResolution)) + mapLogic.SaveShortcuts(_Configuration.JuliePhares, distinctFilteredFaces); if (!_Configuration.LoadOrCreateThenSaveImageFacesResultsForOutputResolutions.Any()) break; if (_FileKeyValuePairs.Any()) diff --git a/Map/Models/MapLogic.cs b/Map/Models/MapLogic.cs index b8b0009..d38ce5d 100644 --- a/Map/Models/MapLogic.cs +++ b/Map/Models/MapLogic.cs @@ -14,11 +14,9 @@ public class MapLogic protected readonly List _NotMappedPersonKeys; protected readonly Dictionary _KeyValuePairs; protected readonly Dictionary _IndicesFromNew; - protected readonly Dictionary _SixCharacterNamedFaceInfo; - protected readonly Dictionary _DeterministicHashCodeUnknownFaceKeyValuePairs; - protected readonly Dictionary _IncorrectDeterministicHashCodeKeyValuePairs; protected readonly Dictionary _PersonKeysRanges; protected readonly Dictionary> _IdThenNormalizedPixelPercentageKeyValuePairs; + protected readonly Dictionary> _IncorrectIdThenNormalizedPixelPercentageKeyValuePairs; protected readonly Dictionary _PeopleKeyValuePairs; public Dictionary KeyValuePairs => _KeyValuePairs; @@ -56,16 +54,14 @@ public class MapLogic Dictionary? keyValuePairs; List>? collection; Dictionary indicesFromNew = new(); - Dictionary? sixCharacterNamedFaceInfo; string? rootDirectoryParent = Path.GetDirectoryName(configuration.RootDirectory); - Dictionary? deterministicHashCodeUnknownFaceKeyValuePairs; Dictionary peopleKeyValuePairs = new(); string zPropertyHolderContentDirectory = Path.Combine(zResultsFullGroupDirectory, "()"); - Dictionary incorrectDeterministicHashCodeKeyValuePairs = new(); string zPropertyHolderSingletonDirectory = Path.Combine(zResultsFullGroupDirectory, "{}"); Dictionary> idThenNormalizedPixelPercentageKeyValuePairs = new(); string zPropertyHolderContentTicksDirectory = Path.Combine(zPropertyHolderContentDirectory, $"({ticks})"); string zPropertyHolderPeopleContentDirectory = Path.Combine(peopleDateGroupDirectory, "()", "(KnownPeople)"); + Dictionary> incorrectIdThenNormalizedPixelPercentageKeyValuePairs = new(); string zPropertyHolderSingletonTicksDirectory = Path.Combine(zPropertyHolderSingletonDirectory, string.Concat('{', _Ticks, '}')); if (string.IsNullOrEmpty(rootDirectoryParent)) throw new NullReferenceException(nameof(rootDirectoryParent)); @@ -73,32 +69,9 @@ public class MapLogic _ = Directory.CreateDirectory(zPropertyHolderContentDirectory); if (!Directory.Exists(zPropertyHolderPeopleContentDirectory)) _ = Directory.CreateDirectory(zPropertyHolderPeopleContentDirectory); - files = Directory.GetFiles(rootDirectoryParent, "DeterministicHashCode*.json", SearchOption.TopDirectoryOnly); - if (files.Length != 1) - deterministicHashCodeUnknownFaceKeyValuePairs = new(); - else - { - json = File.ReadAllText(files[zero]); - deterministicHashCodeUnknownFaceKeyValuePairs = GetKeyValuePairs(json); - } - Stateless.ByDeterministicHashCode.SetByRef(maxDegreeOfParallelism, ticks, _ResizeFilenameExtension, people, skipCollection, peopleKeyValuePairs, notMappedTicks, deterministicHashCodeUnknownFaceKeyValuePairs, idThenNormalizedPixelPercentageKeyValuePairs, incorrectDeterministicHashCodeKeyValuePairs, zPropertyHolderContentDirectory, zPropertyHolderPeopleContentDirectory); + Stateless.ByDeterministicHashCode.SetByRef(maxDegreeOfParallelism, ticks, _ResizeFilenameExtension, people, skipCollection, peopleKeyValuePairs, notMappedTicks, idThenNormalizedPixelPercentageKeyValuePairs, incorrectIdThenNormalizedPixelPercentageKeyValuePairs, zPropertyHolderContentDirectory, zPropertyHolderPeopleContentDirectory); if (!Directory.Exists(zPropertyHolderContentTicksDirectory)) _ = Directory.CreateDirectory(zPropertyHolderContentTicksDirectory); - if (!deterministicHashCodeUnknownFaceKeyValuePairs.Any()) - sixCharacterNamedFaceInfo = new(); - else - { - files = Directory.GetFiles(rootDirectoryParent, "*SixCharacter*.json", SearchOption.TopDirectoryOnly); - if (files.Length != 1) - sixCharacterNamedFaceInfo = new(); - else - { - json = File.ReadAllText(files[zero]); - sixCharacterNamedFaceInfo = JsonSerializer.Deserialize>(json); - if (sixCharacterNamedFaceInfo is null) - throw new NullReferenceException(nameof(sixCharacterNamedFaceInfo)); - } - } files = Directory.GetFiles(rootDirectoryParent, "*keyValuePairs-6*.json", SearchOption.TopDirectoryOnly); if (files.Length != 1) keyValuePairs = new(); @@ -132,13 +105,11 @@ public class MapLogic _SkipCollection = skipCollection; _NotMappedPersonKeys = notMappedTicks; _PeopleKeyValuePairs = peopleKeyValuePairs; - _SixCharacterNamedFaceInfo = sixCharacterNamedFaceInfo; _ZPropertyHolderContentDirectory = zPropertyHolderContentDirectory; _ZPropertyHolderContentTicksDirectory = zPropertyHolderContentTicksDirectory; _ZPropertyHolderSingletonTicksDirectory = zPropertyHolderSingletonTicksDirectory; - _IncorrectDeterministicHashCodeKeyValuePairs = incorrectDeterministicHashCodeKeyValuePairs; _IdThenNormalizedPixelPercentageKeyValuePairs = idThenNormalizedPixelPercentageKeyValuePairs; - _DeterministicHashCodeUnknownFaceKeyValuePairs = deterministicHashCodeUnknownFaceKeyValuePairs; + _IncorrectIdThenNormalizedPixelPercentageKeyValuePairs = incorrectIdThenNormalizedPixelPercentageKeyValuePairs; } public MapLogic(int maxDegreeOfParallelism, Configuration configuration, string outputExtension, long ticks, Person[] people, string peopleDateGroupDirectory, string zResultsFullGroupDirectory) : @@ -220,59 +191,50 @@ public class MapLogic return results; } - public void SaveShortcuts(string[] juliePhares, Item[] filteredItems) + public void SaveShortcuts(string[] juliePhares, List distinctFilteredFaces) { string fileName; string fullName; - DateTime minimumDateTime; string personKeyFormatted; PersonBirthday personBirthday; WindowsShortcut windowsShortcut; (string DisplayDirectoryName, int? ApproximateYears, PersonBirthday[] PersonBirthdays, long PersonKey) person; - List<(Item, (long?, Face?, (string, string, string, string))[])> collections = GetCollection(filteredItems); - foreach ((Item item, (long? personKey, Face? _, (string, string, string, string))[] collection) in collections) + List<(Face, long?, (string, string, string, string))> collection = GetCollection(distinctFilteredFaces); + foreach ((Face face, long? personKey, (string directory, string copyDirectory, string copyFileName, string shortcutFileName)) in collection) { - if (collection.Length != 1) + if (personKey is null) continue; - foreach ((long? personKey, Face? _, (string directory, string copyDirectory, string copyFileName, string shortcutFileName)) in collection) + if (face.Mapping is null) + throw new NotSupportedException(); + personBirthday = IPersonBirthday.GetPersonBirthday(personKey.Value); + personKeyFormatted = IPersonBirthday.GetFormatted(Shared.Models.Stateless.IPersonBirthday.Format, personBirthday); + if (juliePhares.Contains(personKeyFormatted) && !string.IsNullOrEmpty(copyDirectory)) { - if (personKey is null) - continue; - if (item.Property?.Id is null || item.ImageFileHolder is null || item.ResizedFileHolder is null) - continue; - minimumDateTime = IProperty.GetMinimumDateTime(item.Property); - if (!Directory.Exists(directory)) - { - _ = Directory.CreateDirectory(directory); - if (personKey is not null && _PeopleKeyValuePairs.ContainsKey(personKey.Value)) - { - person = _PeopleKeyValuePairs[personKey.Value]; - fullName = string.Concat(person.DisplayDirectoryName, ".txt"); - File.WriteAllText(Path.Combine(directory, fullName), string.Empty); - } - } - if (personKey is null) - continue; - personBirthday = IPersonBirthday.GetPersonBirthday(personKey.Value); - personKeyFormatted = IPersonBirthday.GetFormatted(Shared.Models.Stateless.IPersonBirthday.Format, personBirthday); - if (juliePhares.Contains(personKeyFormatted) && !string.IsNullOrEmpty(copyDirectory)) - { - if (!Directory.Exists(copyDirectory)) - _ = Directory.CreateDirectory(copyDirectory); - fileName = Path.Combine(copyDirectory, $"{item.Property.Id.Value}{item.ResizedFileHolder.ExtensionLowered}"); - if (!File.Exists(fileName)) - File.Copy(item.ResizedFileHolder.FullName, fileName); - } - fileName = Path.Combine(directory, $"{item.Property.Id.Value}.lnk"); - if (File.Exists(fileName)) - continue; - windowsShortcut = new() { Path = item.ResizedFileHolder.FullName }; - windowsShortcut.Save(fileName); - windowsShortcut.Dispose(); + if (!Directory.Exists(copyDirectory)) + _ = Directory.CreateDirectory(copyDirectory); + fileName = Path.Combine(copyDirectory, $"{face.Mapping.MappingFromItem.Id}{face.Mapping.MappingFromItem.ResizedFileHolder.ExtensionLowered}"); if (!File.Exists(fileName)) - continue; - File.SetLastWriteTime(fileName, minimumDateTime); + File.Copy(face.Mapping.MappingFromItem.ResizedFileHolder.FullName, fileName); } + if (!Directory.Exists(directory)) + { + _ = Directory.CreateDirectory(directory); + if (personKey is not null && _PeopleKeyValuePairs.ContainsKey(personKey.Value)) + { + person = _PeopleKeyValuePairs[personKey.Value]; + fullName = string.Concat(person.DisplayDirectoryName, ".txt"); + File.WriteAllText(Path.Combine(directory, fullName), string.Empty); + } + } + fileName = Path.Combine(directory, $"{face.Mapping.MappingFromItem.Id}.lnk"); + if (File.Exists(fileName)) + continue; + windowsShortcut = new() { Path = face.Mapping.MappingFromItem.ResizedFileHolder.FullName }; + windowsShortcut.Save(fileName); + windowsShortcut.Dispose(); + if (!File.Exists(fileName)) + continue; + File.SetLastWriteTime(fileName, face.Mapping.MappingFromItem.MinimumDateTime); } } @@ -281,7 +243,7 @@ public class MapLogic Dictionary personKeyAliases = new(); Dictionary> keyValuePairs = new(); List<(PersonBirthday, int, int)> idThenNormalizedPixelPercentageCollection = new(); - List<(PersonBirthday PersonBirthday, double IdAndNormalizedPixelPercentage)> incorrectDeterministicHashCodeCollection = new(); + List<(PersonBirthday, int, int)> incorrectIdThenNormalizedPixelPercentageCollection = new(); foreach (SortingContainer sortingContainer in sortingContainers) { if (sortingContainer.Face.FaceEncoding is null || sortingContainer.Face.Location?.NormalizedPixelPercentage is null) @@ -292,7 +254,7 @@ public class MapLogic keyValuePairs.Add(sortingContainer.Face.Mapping.MappingFromItem.Id, new()); keyValuePairs[sortingContainer.Face.Mapping.MappingFromItem.Id].Add(sortingContainer.Face); } - Stateless.ByDeterministicHashCode.SetCollections(maxDegreeOfParallelism, _Ticks, _ZPropertyHolderContentDirectory, personKeyAliases, idThenNormalizedPixelPercentageCollection, incorrectDeterministicHashCodeCollection, keyValuePairs); + Stateless.ByDeterministicHashCode.SetCollections(maxDegreeOfParallelism, _Ticks, _ZPropertyHolderContentDirectory, personKeyAliases, idThenNormalizedPixelPercentageCollection, incorrectIdThenNormalizedPixelPercentageCollection, keyValuePairs); } private static string GetMappingSegmentB(long ticks, PersonBirthday personBirthday, int? approximateYears, long minimumDateTimeTicks, bool? isWrongYear) @@ -359,7 +321,6 @@ public class MapLogic private int AddToMapping(List distinctFilteredFaces) { - int by; int result = 0; long personKey; const int zero = 0; @@ -370,13 +331,11 @@ public class MapLogic PersonBirthday personBirthday; List personBirthdays = new(); Dictionary keyValuePairs; + int by = Shared.Models.Stateless.ISorting.Mapping; (string DisplayDirectoryName, int? ApproximateYears, PersonBirthday[] PersonBirthdays, long PersonKey) person; foreach (Face face in distinctFilteredFaces) { - by = 2; personBirthdays.Clear(); - if (face.Mapping is null) - throw new NotSupportedException(); if (face.Mapping is null) throw new NotSupportedException(); if (!_IdThenNormalizedPixelPercentageKeyValuePairs.ContainsKey(face.Mapping.MappingFromItem.Id)) @@ -402,23 +361,6 @@ public class MapLogic mappingSegmentB = GetMappingSegmentB(_Ticks, personBirthday, approximateYears, face.Mapping.MappingFromItem); face.Mapping.UpdateMappingFromPerson(approximateYears, by, displayDirectoryName, personBirthday, mappingSegmentB); } - if (!Shared.Models.Stateless.IMapping.UseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToMapping || !_DeterministicHashCodeUnknownFaceKeyValuePairs.ContainsKey(face.Mapping.MappingFromItem.Id)) - continue; - by = 1; - personBirthdays.AddRange(_DeterministicHashCodeUnknownFaceKeyValuePairs[face.Mapping.MappingFromItem.Id]); - for (int i = 0; i < personBirthdays.Count; i++) - { - personKey = personBirthdays[i].Value.Ticks; - if (!_PeopleKeyValuePairs.ContainsKey(personKey)) - continue; - person = _PeopleKeyValuePairs[personKey]; - approximateYears = person.ApproximateYears; - personBirthday = person.PersonBirthdays[zero]; - displayDirectoryName = person.DisplayDirectoryName; - personKeyFormatted = IPersonBirthday.GetFormatted(Shared.Models.Stateless.IPersonBirthday.Format, personBirthday); - mappingSegmentB = GetMappingSegmentB(_Ticks, personBirthday, approximateYears, face.Mapping.MappingFromItem); - face.Mapping.UpdateMappingFromPerson(approximateYears, by, displayDirectoryName, personBirthday, mappingSegmentB); - } } return result; } @@ -498,15 +440,12 @@ public class MapLogic SaveContainers(saveContainers); } - public List<(Item, (long?, Face?, (string, string, string, string))[])> GetCollection(Item[] filteredItems) + public List<(Face, long?, (string, string, string, string))> GetCollection(List distinctFilteredFaces) { - List<(Item, (long?, Face?, (string, string, string, string))[])> results = new(); + List<(Face, long?, (string, string, string, string))> results = new(); int years; - Face face; - Item item; long? personKey; string directory; - bool? isWrongYear; const int zero = 0; TimeSpan? timeSpan; string copyFileName; @@ -515,63 +454,43 @@ public class MapLogic string isWrongYearFlag; string shortcutFileName; string subDirectoryName; - DateTime minimumDateTime; - List indices = new(); - List faceCollection; string personKeyFormatted; PersonBirthday personBirthday; PersonBirthday[] personBirthdays; DateTime dateTime = DateTime.Now; - List<(long?, Face?, (string, string, string, string))> collection; - for (int i = 0; i < filteredItems.Length; i++) + Dictionary keyValuePairs; + foreach (Face face in distinctFilteredFaces) { - indices.Clear(); + if (face.Mapping is null) + throw new NotSupportedException(); copyFileName = string.Empty; copyDirectory = string.Empty; - item = filteredItems[i]; - if (item.ImageFileHolder is null) - continue; - relativePath = Path.GetDirectoryName($"C:{item.RelativePath}"); + relativePath = Path.GetDirectoryName($"C:{face.RelativePath}"); if (string.IsNullOrEmpty(relativePath) || relativePath.Length < 3) continue; - if (item.Property?.Id is null || item.ImageFileHolder is null || item.ResizedFileHolder is null) - continue; - collection = new(); - if (!_DeterministicHashCodeUnknownFaceKeyValuePairs.ContainsKey(item.Property.Id.Value)) + if (!_IdThenNormalizedPixelPercentageKeyValuePairs.ContainsKey(face.Mapping.MappingFromItem.Id)) { - faceCollection = new(); personKey = null; directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, $"Unnamed{relativePath[2..]}"); } else { - faceCollection = item.Faces; - personBirthdays = _DeterministicHashCodeUnknownFaceKeyValuePairs[item.Property.Id.Value]; - minimumDateTime = IProperty.GetMinimumDateTime(item.Property); - (isWrongYear, _) = item.Property.IsWrongYear(item.ImageFileHolder.FullName, minimumDateTime); - isWrongYearFlag = IItem.GetWrongYearFlag(isWrongYear); - subDirectoryName = $"{isWrongYearFlag}{minimumDateTime:yyyy}"; - if (!faceCollection.Any()) - { - personKey = null; - directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, $"None{relativePath[2..]}", subDirectoryName); - } - else if (personBirthdays.Length != 1) + keyValuePairs = _IdThenNormalizedPixelPercentageKeyValuePairs[face.Mapping.MappingFromItem.Id]; + if (!keyValuePairs.ContainsKey(face.Mapping.MappingFromLocation.NormalizedPixelPercentage)) + throw new NotSupportedException(); + personBirthdays = keyValuePairs[face.Mapping.MappingFromLocation.NormalizedPixelPercentage]; + isWrongYearFlag = IItem.GetWrongYearFlag(face.Mapping.MappingFromItem.IsWrongYear); + subDirectoryName = $"{isWrongYearFlag}{face.Mapping.MappingFromItem.MinimumDateTime:yyyy}"; + if (personBirthdays.Length != 1) { personKey = null; directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, $"Not Supported{relativePath[2..]}", subDirectoryName); } - else if (faceCollection.Count != 1) - { - personKey = null; - directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, $"Many{relativePath[2..]}", subDirectoryName); - } else { - indices.Add(zero); personBirthday = personBirthdays[zero]; personKey = personBirthday.Value.Ticks; - timeSpan = IPersonBirthday.GetTimeSpan(minimumDateTime, isWrongYear, personBirthday); + timeSpan = IPersonBirthday.GetTimeSpan(face.Mapping.MappingFromItem.MinimumDateTime, face.Mapping.MappingFromItem.IsWrongYear, personBirthday); if (timeSpan.HasValue) { if (timeSpan.Value.Ticks < 0) @@ -582,51 +501,24 @@ public class MapLogic subDirectoryName = $"^{years:000}"; } } - face = faceCollection[zero]; personKeyFormatted = IPersonBirthday.GetFormatted(Shared.Models.Stateless.IPersonBirthday.Format, personBirthday); directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, "Shortcuts", personKeyFormatted, subDirectoryName); if (face.FaceEncoding is not null && face.Location?.NormalizedPixelPercentage is not null) copyDirectory = Path.Combine(_ZPropertyHolderContentTicksDirectory, "Images", personKeyFormatted, subDirectoryName); else copyDirectory = Path.Combine(_ZPropertyHolderContentTicksDirectory, "ImagesBut", personKeyFormatted, subDirectoryName); - copyFileName = Path.Combine(copyDirectory, $"{item.Property.Id.Value}{item.ResizedFileHolder.ExtensionLowered}"); + copyFileName = Path.Combine(copyDirectory, $"{face.Mapping.MappingFromItem.Id}{face.Mapping.MappingFromItem.ResizedFileHolder.ExtensionLowered}"); } } - shortcutFileName = Path.Combine(directory, $"{item.Property.Id.Value}.lnk"); - if (personKey is null || !indices.Any()) - collection.Add(new(personKey, null, (directory, copyDirectory, copyFileName, shortcutFileName))); + shortcutFileName = Path.Combine(directory, $"{face.Mapping.MappingFromItem.Id}.lnk"); + if (personKey is null) + results.Add(new(face, null, (directory, copyDirectory, copyFileName, shortcutFileName))); else - { - foreach (int index in indices) - collection.Add(new(personKey, faceCollection[index], (directory, copyDirectory, copyFileName, shortcutFileName))); - } - results.Add(new(item, collection.ToArray())); + results.Add(new(face, personKey, (directory, copyDirectory, copyFileName, shortcutFileName))); } return results; } - public void SavePropertyHolders(Item[] items) - { - string json; - FileInfo fileInfo; - bool updateDateWhenMatches = false; - JsonSerializerOptions jsonSerializerOptions = new() { WriteIndented = true }; - foreach (Item item in items) - { - if (item.Property?.Id is null || item.ImageFileHolder is null || item.ResizedFileHolder is null) - continue; - if (!item.Faces.Any()) - continue; - json = JsonSerializer.Serialize(item, jsonSerializerOptions); - fileInfo = new(Path.GetFullPath(string.Concat(_ZPropertyHolderSingletonTicksDirectory, item.RelativePath, ".json"))); - if (fileInfo.Directory is null) - continue; - if (!fileInfo.Directory.Exists) - continue; - _ = IPath.WriteAllText(fileInfo.FullName, json, updateDateWhenMatches, compareBeforeWrite: true); - } - } - private static Dictionary> Convert(List<(int Id, Face Face)> collection) { Dictionary> results = new(); @@ -659,7 +551,6 @@ public class MapLogic Dictionary> results = new(); string key; long personKey; - const int by = 3; const int zero = 0; HashSet hashSet; string mappingSegmentB; @@ -668,6 +559,7 @@ public class MapLogic PersonBirthday personBirthday; PersonBirthday[] personBirthdays; Dictionary keyValuePairs; + const int by = Shared.Models.Stateless.ISorting.Sorting; Dictionary> checkKeyValuePairs = new(); int totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - _Ticks).TotalSeconds); (string DisplayDirectoryName, int? ApproximateYears, PersonBirthday[] PersonBirthdays, long PersonKey) person; @@ -720,12 +612,12 @@ public class MapLogic internal void ForceSingleImage(IEnumerable distinctFilteredFaces) { - int by = 4; long? personKey; const int zero = 0; string mappingSegmentB; int? approximateYears = null; PersonBirthday personBirthday; + int by = Shared.Models.Stateless.ISorting.ForceSingleImage; Face[] orderedDistinctFilteredFaces = (from l in distinctFilteredFaces orderby l.Mapping is not null, l.Mapping?.MappingFromLocation.Confidence descending select l).ToArray(); const string displayDirectoryName = Property.Models.Stateless.IResult.AllInOne; foreach (Face face in orderedDistinctFilteredFaces) @@ -774,26 +666,25 @@ public class MapLogic if (face.Mapping.MappingFromPerson.By is null) by = $"{nameof(Mapping)}Null"; else + { + if (face.Mapping.MappingFromPerson.By == Shared.Models.Stateless.ISorting.Mapping && !Shared.Models.Stateless.IMapping.SaveMapped) + continue; by = face.Mapping.MappingFromPerson.By.Value switch { - 1 => "ByUnknownFaceKey", - 2 => nameof(Mapping), - 3 => nameof(Sorting), - 4 => nameof(MapLogic.ForceSingleImage), + Shared.Models.Stateless.ISorting.Mapping => nameof(Mapping), + Shared.Models.Stateless.ISorting.Sorting => nameof(Sorting), + Shared.Models.Stateless.ISorting.ForceSingleImage => nameof(MapLogic.ForceSingleImage), _ => throw new NotImplementedException() }; - if (face.Mapping.MappingFromPerson.By is not null and not 2) - { - directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, by, personKeyFormatted, face.Mapping.MappingFromPerson.SegmentB); + } + directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, by, personKeyFormatted, face.Mapping.MappingFromPerson.SegmentB); + saveContainer = new(Path.Combine(directory, "!")); + if (face.Mapping.MappingFromPerson.By.HasValue && face.Mapping.MappingFromPerson.By == Shared.Models.Stateless.ISorting.Sorting) + results.Add(saveContainer); + if (face.Mapping.MappingFromPerson.By is not null) personDirectory = Path.Combine(directory, face.Mapping.MappingFromPerson.DisplayDirectoryName, "lnk"); - } else - { - directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, by, personKeyFormatted, face.Mapping.MappingFromPerson.SegmentB); personDirectory = Path.Combine(directory, face.Mapping.MappingFromPerson.DisplayDirectoryName[..1], "lnk"); - if (face.Mapping.MappingFromPerson.By == 2 && !Shared.Models.Stateless.IMapping.SaveMapped) - continue; - } saveContainer = new(personDirectory); results.Add(saveContainer); facesDirectory = string.Concat(dFacesContentDirectory, Path.Combine(directoryName, face.Mapping.MappingFromItem.ImageFileHolder.NameWithoutExtension)); @@ -823,7 +714,7 @@ public class MapLogic public void CommonWork(int maxDegreeOfParallelism, string dFacesContentDirectory, string d2ResultsFullGroupDirectory, List distinctFilteredFaces, SortingContainer[] sortingContainers) { List saveContainers; - if (_DeterministicHashCodeUnknownFaceKeyValuePairs.Any()) + if (!_IdThenNormalizedPixelPercentageKeyValuePairs.Any()) UseKeyValuePairsSaveFaceEncoding(maxDegreeOfParallelism, sortingContainers); int totalNotMapped = AddToMapping(distinctFilteredFaces); if (totalNotMapped == 0) diff --git a/Map/Models/Stateless/SetByDeterministicHashCode.cs b/Map/Models/Stateless/SetByDeterministicHashCode.cs index 0c2880f..3289eef 100644 --- a/Map/Models/Stateless/SetByDeterministicHashCode.cs +++ b/Map/Models/Stateless/SetByDeterministicHashCode.cs @@ -137,7 +137,7 @@ public class ByDeterministicHashCode peopleCollection.Add(new(displayDirectoryName, approximateYears, new PersonBirthday[] { personBirthday }, personKey)); } } - internal static void SetCollections(int maxDegreeOfParallelism, long ticks, string zPropertyHolderContentDirectory, Dictionary personKeyAliases, List<(PersonBirthday, int, int)> idThenNormalizedPixelPercentageCollection, List<(PersonBirthday, double)> incorrectDeterministicHashCodeCollection, Dictionary> keyValuePairs) + internal static void SetCollections(int maxDegreeOfParallelism, long ticks, string zPropertyHolderContentDirectory, Dictionary personKeyAliases, List<(PersonBirthday, int, int)> idThenNormalizedPixelPercentageCollection, List<(PersonBirthday, int, int)> incorrectIdThenNormalizedPixelPercentageCollection, Dictionary> keyValuePairs) { int? id; string[] files; @@ -211,7 +211,10 @@ public class ByDeterministicHashCode (id, normalizedPixelPercentage) = Shared.Models.Stateless.Methods.IMapping.GetReversedDeterministicHashCodeKey(Shared.Models.Stateless.ILocation.Digits, keyValuePairsAny, keyValuePairs, file); if (id is null || normalizedPixelPercentage is null) continue; - idThenNormalizedPixelPercentageCollection.Add(new(personBirthday, id.Value, normalizedPixelPercentage.Value)); + if (personFirstInitial != "!") + idThenNormalizedPixelPercentageCollection.Add(new(personBirthday, id.Value, normalizedPixelPercentage.Value)); + else + incorrectIdThenNormalizedPixelPercentageCollection.Add(new(personBirthday, id.Value, normalizedPixelPercentage.Value)); } personNameLinkDirectories = Directory.GetDirectories(personNameDirectory, "*", SearchOption.TopDirectoryOnly); foreach (string personNameLinkDirectory in personNameLinkDirectories) @@ -239,36 +242,11 @@ public class ByDeterministicHashCode } } - private static List GetPersonKeys(Dictionary deterministicHashCodeUnknownFaceKeyValuePairs) + private static void SetKeyValuePairs(List<(PersonBirthday, int, int)> idThenNormalizedPixelPercentageCollection, List<(PersonBirthday, int, int)> incorrectIdThenNormalizedPixelPercentageCollection, Dictionary> idThenNormalizedPixelPercentageKeyValuePairs, Dictionary> incorrectIdThenNormalizedPixelPercentageKeyValuePairs) { - List results = new(); - long personKey; - foreach (KeyValuePair keyValuePair in deterministicHashCodeUnknownFaceKeyValuePairs) - { - foreach (PersonBirthday personBirthday in keyValuePair.Value) - { - personKey = personBirthday.Value.Ticks; - results.Add(personKey); - } - } - results = results.Distinct().ToList(); - return results; - } - - private static void SetKeyValuePairs(List<(PersonBirthday, int, int)> idThenNormalizedPixelPercentageCollection, List<(PersonBirthday PersonBirthday, double IdAndNormalizedPixelPercentage)> incorrectDeterministicHashCodeCollection, Dictionary incorrectDeterministicHashCodeKeyValuePairs, Dictionary> idThenNormalizedPixelPercentageKeyValuePairs) - { - Dictionary> incorrectDeterministicHashCodeScope = new(); - Dictionary>> idThenNormalizedPixelPercentageScope = new(); - foreach ((PersonBirthday personBirthday, double idAndNormalizedPixelPercentage) in incorrectDeterministicHashCodeCollection) - { - if (!incorrectDeterministicHashCodeScope.ContainsKey(idAndNormalizedPixelPercentage)) - incorrectDeterministicHashCodeScope.Add(idAndNormalizedPixelPercentage, new()); - incorrectDeterministicHashCodeScope[idAndNormalizedPixelPercentage].Add(personBirthday); - } - foreach (KeyValuePair> keyValuePair in incorrectDeterministicHashCodeScope) - incorrectDeterministicHashCodeKeyValuePairs.Add(keyValuePair.Key, keyValuePair.Value.Distinct().ToArray()); string check; int normalizedPixelPercentageInDecimalForm; + Dictionary>> idThenNormalizedPixelPercentageScope = new(); foreach ((PersonBirthday personBirthday, int id, int normalizedPixelPercentage) in idThenNormalizedPixelPercentageCollection) { if (!idThenNormalizedPixelPercentageScope.ContainsKey(id)) @@ -294,30 +272,51 @@ public class ByDeterministicHashCode foreach (KeyValuePair> innerKeyValuePair in keyValuePair.Value) idThenNormalizedPixelPercentageKeyValuePairs[keyValuePair.Key].Add(innerKeyValuePair.Key, innerKeyValuePair.Value.Distinct().ToArray()); } + Dictionary>> incorrectIdThenNormalizedPixelPercentageScope = new(); + foreach ((PersonBirthday personBirthday, int id, int normalizedPixelPercentage) in incorrectIdThenNormalizedPixelPercentageCollection) + { + if (!incorrectIdThenNormalizedPixelPercentageScope.ContainsKey(id)) + incorrectIdThenNormalizedPixelPercentageScope.Add(id, new()); + check = normalizedPixelPercentage.ToString(); + if (check.Length == Shared.Models.Stateless.ILocation.Digits) + { + if (!incorrectIdThenNormalizedPixelPercentageScope[id].ContainsKey(normalizedPixelPercentage)) + incorrectIdThenNormalizedPixelPercentageScope[id].Add(normalizedPixelPercentage, new()); + incorrectIdThenNormalizedPixelPercentageScope[id][normalizedPixelPercentage].Add(personBirthday); + } + else + { + normalizedPixelPercentageInDecimalForm = int.Parse(check.PadRight(Shared.Models.Stateless.ILocation.Digits, '0')); + if (!incorrectIdThenNormalizedPixelPercentageScope[id].ContainsKey(normalizedPixelPercentageInDecimalForm)) + incorrectIdThenNormalizedPixelPercentageScope[id].Add(normalizedPixelPercentageInDecimalForm, new()); + incorrectIdThenNormalizedPixelPercentageScope[id][normalizedPixelPercentageInDecimalForm].Add(personBirthday); + } + } + foreach (KeyValuePair>> keyValuePair in incorrectIdThenNormalizedPixelPercentageScope) + { + incorrectIdThenNormalizedPixelPercentageKeyValuePairs.Add(keyValuePair.Key, new()); + foreach (KeyValuePair> innerKeyValuePair in keyValuePair.Value) + incorrectIdThenNormalizedPixelPercentageKeyValuePairs[keyValuePair.Key].Add(innerKeyValuePair.Key, innerKeyValuePair.Value.Distinct().ToArray()); + } } - internal static void SetByRef(int maxDegreeOfParallelism, long ticks, string resizeFilenameExtension, Person[] people, List skipCollection, Dictionary peopleKeyValuePairs, List notMappedPersonKeys, Dictionary deterministicHashCodeUnknownFaceKeyValuePairs, Dictionary> idThenNormalizedPixelPercentageKeyValuePairs, Dictionary incorrectDeterministicHashCodeKeyValuePairs, string zPropertyHolderContentDirectory, string zPropertyHolderPeopleContentDirectory) + internal static void SetByRef(int maxDegreeOfParallelism, long ticks, string resizeFilenameExtension, Person[] people, List skipCollection, Dictionary peopleKeyValuePairs, List notMappedPersonKeys, Dictionary> idThenNormalizedPixelPercentageKeyValuePairs, Dictionary> incorrectIdThenNormalizedPixelPercentageKeyValuePairs, string zPropertyHolderContentDirectory, string zPropertyHolderPeopleContentDirectory) { Dictionary personKeyAliases = new(); Dictionary> keyValuePairs = new(); List idThenNormalizedPixelPercentagePersonKeys = new(); List<(string, int?, PersonBirthday[], long)> peopleCollection = new(); List<(PersonBirthday, int, int)> idThenNormalizedPixelPercentageCollection = new(); - List deterministicHashCodeUnknownFacePersonKeys = GetPersonKeys(deterministicHashCodeUnknownFaceKeyValuePairs); - List<(PersonBirthday PersonBirthday, double IdAndNormalizedPixelPercentage)> incorrectDeterministicHashCodeCollection = new(); + List<(PersonBirthday, int, int)> incorrectIdThenNormalizedPixelPercentageCollection = new(); SetOther(resizeFilenameExtension, people, zPropertyHolderPeopleContentDirectory, skipCollection, personKeyAliases, peopleCollection); - SetCollections(maxDegreeOfParallelism, ticks, zPropertyHolderContentDirectory, personKeyAliases, idThenNormalizedPixelPercentageCollection, incorrectDeterministicHashCodeCollection, keyValuePairs); - SetKeyValuePairs(idThenNormalizedPixelPercentageCollection, incorrectDeterministicHashCodeCollection, incorrectDeterministicHashCodeKeyValuePairs, idThenNormalizedPixelPercentageKeyValuePairs); - incorrectDeterministicHashCodeCollection = (from l in incorrectDeterministicHashCodeCollection orderby l.IdAndNormalizedPixelPercentage select l).ToList(); + SetCollections(maxDegreeOfParallelism, ticks, zPropertyHolderContentDirectory, personKeyAliases, idThenNormalizedPixelPercentageCollection, incorrectIdThenNormalizedPixelPercentageCollection, keyValuePairs); + SetKeyValuePairs(idThenNormalizedPixelPercentageCollection, incorrectIdThenNormalizedPixelPercentageCollection, idThenNormalizedPixelPercentageKeyValuePairs, incorrectIdThenNormalizedPixelPercentageKeyValuePairs); foreach (KeyValuePair> keyValuePair in idThenNormalizedPixelPercentageKeyValuePairs) { foreach (KeyValuePair keyValue in keyValuePair.Value) idThenNormalizedPixelPercentagePersonKeys.AddRange(from l in keyValue.Value select l.Value.Ticks); } idThenNormalizedPixelPercentagePersonKeys = idThenNormalizedPixelPercentagePersonKeys.Distinct().ToList(); - foreach (KeyValuePair keyValuePair in deterministicHashCodeUnknownFaceKeyValuePairs) - deterministicHashCodeUnknownFacePersonKeys.AddRange(from l in keyValuePair.Value select l.Value.Ticks); - deterministicHashCodeUnknownFacePersonKeys = deterministicHashCodeUnknownFacePersonKeys.Distinct().ToList(); if (peopleCollection.Any()) { foreach ((string displayDirectoryName, int? approximateYears, PersonBirthday[] personBirthdays, long personKey) in peopleCollection) @@ -328,25 +327,17 @@ public class ByDeterministicHashCode continue; throw new NotImplementedException(); } - if (!deterministicHashCodeUnknownFacePersonKeys.Contains(personKey) && !idThenNormalizedPixelPercentagePersonKeys.Contains(personKey)) + if (!idThenNormalizedPixelPercentagePersonKeys.Contains(personKey)) notMappedPersonKeys.Add(personKey); else peopleKeyValuePairs.Add(personKey, new(displayDirectoryName, approximateYears, personBirthdays, personKey)); } } - if (deterministicHashCodeUnknownFacePersonKeys.Any() || idThenNormalizedPixelPercentagePersonKeys.Any()) + if (idThenNormalizedPixelPercentagePersonKeys.Any()) { int? approximateYears = null; PersonBirthday? personBirthday; const string displayDirectoryName = Property.Models.Stateless.IResult.AllInOne; - foreach (long personKey in deterministicHashCodeUnknownFacePersonKeys) - { - if (!peopleKeyValuePairs.ContainsKey(personKey)) - { - personBirthday = Shared.Models.Stateless.Methods.IPersonBirthday.GetPersonBirthday(personKey); - peopleKeyValuePairs.Add(personKey, new(displayDirectoryName, approximateYears, new PersonBirthday[] { personBirthday }, personKey)); - } - } foreach (long personKey in idThenNormalizedPixelPercentagePersonKeys) { if (!peopleKeyValuePairs.ContainsKey(personKey)) diff --git a/Shared/Models/Stateless/IFaceDistance.cs b/Shared/Models/Stateless/IFaceDistance.cs index 4be8356..bb75419 100644 --- a/Shared/Models/Stateless/IFaceDistance.cs +++ b/Shared/Models/Stateless/IFaceDistance.cs @@ -5,10 +5,11 @@ public interface IFaceDistance const int HiddenImageFactor = 2; const int Permyriad = 10000; - const double MinimumConfidence = 0.95d; - const double Tolerance = 0.21d; + const double MinimumConfidence = 1.25d; + const double Tolerance = 0.23d; // (637987888254767613) Tolerance = 0.31d; MinimumConfidence = 0.80d; => 1003 in 20 minutes with 9 failures - // (637987913910140924) Tolerance = 0.21d; MinimumConfidence = 0.95d; + // (637987913910140924) Tolerance = 0.21d; MinimumConfidence = 0.95d; => 0254 in 04 minutes with 1 failures + // (??????????????????) Tolerance = 0.23d; MinimumConfidence = 1.25d; => ____ in __ minutes with _ failures } \ No newline at end of file diff --git a/Shared/Models/Stateless/IMapping.cs b/Shared/Models/Stateless/IMapping.cs index f403ea1..4f84cef 100644 --- a/Shared/Models/Stateless/IMapping.cs +++ b/Shared/Models/Stateless/IMapping.cs @@ -3,12 +3,6 @@ public interface IMapping { - // 637972153144596958 - // const bool UseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToNamed = true; - // const bool OnlyUseNamedWithNormalizedPixelPercentagePopulatedForGetKeyValuePairs = false; - - const bool UseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToMapping = false; - const bool UseDeterministicHashCodeUnknownFaceKeyValuePairsForSaveMapping = false; const bool SaveFaceEncoding = false; const bool SaveMapped = false; diff --git a/Shared/Models/Stateless/ISorting.cs b/Shared/Models/Stateless/ISorting.cs index 5f2f766..ad7ba8f 100644 --- a/Shared/Models/Stateless/ISorting.cs +++ b/Shared/Models/Stateless/ISorting.cs @@ -3,11 +3,14 @@ public interface ISorting { + const int DaysDeltaTolerance = 700; const int FacesToSkipAfterSortBeforeLoad = 0; const int FacesToTakeAfterSortBeforeLoad = 123000; + const int ForceSingleImage = 3; + const int Mapping = 1; const int MaximumPerFaceShouldBeHigh = 1000; - const int DaysDeltaTolerance = 700; const int MaximumPerKey = 27; const int Sigma = 3; + const int Sorting = 2; } \ No newline at end of file