diff --git a/Distance/Models/_E_Distance.cs b/Distance/Models/_E_Distance.cs index 4873f34..bede9d6 100644 --- a/Distance/Models/_E_Distance.cs +++ b/Distance/Models/_E_Distance.cs @@ -50,8 +50,8 @@ public partial class E_Distance private FaceDistanceContainer[] GetFaceDistanceContainers(MappingFromItem mappingFromItem, List intersectFaces) { FaceDistanceContainer[] results; + int wholePercentages; int confidencePercent; - int normalizedRectangle; FaceDistance faceDistance; FaceDistanceContainer faceDistanceContainer; List collection = new(); @@ -60,13 +60,13 @@ public partial class E_Distance if (face.FaceEncoding is null || face.Location is null || face.OutputResolution is null) throw new NotSupportedException(); confidencePercent = Shared.Models.Stateless.Methods.ILocation.GetConfidencePercent(_FaceConfidencePercent, _RangeFaceConfidence, face.Location.Confidence); - normalizedRectangle = Shared.Models.Stateless.Methods.ILocation.GetNormalizedRectangle(face.Location, Shared.Models.Stateless.ILocation.Digits, face.OutputResolution); + wholePercentages = Shared.Models.Stateless.Methods.ILocation.GetWholePercentages(face.Location, Shared.Models.Stateless.ILocation.Digits, face.OutputResolution); if (face.FaceDistance?.Encoding is not null && face.FaceDistance.Encoding is FaceRecognitionDotNet.FaceEncoding faceEncoding) - faceDistance = new(confidencePercent, mappingFromItem.GetDateTimeOriginalThenMinimumDateTime(), faceEncoding, mappingFromItem.Id, mappingFromItem.IsWrongYear, normalizedRectangle); + faceDistance = new(confidencePercent, mappingFromItem.GetDateTimeOriginalThenMinimumDateTime(), faceEncoding, mappingFromItem.Id, mappingFromItem.IsWrongYear, wholePercentages); else { faceEncoding = FaceRecognition.LoadFaceEncoding(face.FaceEncoding.RawEncoding); - faceDistance = new(confidencePercent, mappingFromItem.GetDateTimeOriginalThenMinimumDateTime(), faceEncoding, mappingFromItem.Id, mappingFromItem.IsWrongYear, normalizedRectangle); + faceDistance = new(confidencePercent, mappingFromItem.GetDateTimeOriginalThenMinimumDateTime(), faceEncoding, mappingFromItem.Id, mappingFromItem.IsWrongYear, wholePercentages); lock (intersectFaces) face.SetFaceDistance(faceDistance); } @@ -244,7 +244,7 @@ public partial class E_Distance throw new NotSupportedException(); if (filteredFaces.Any()) { - intersectFaces = Shared.Models.Stateless.Methods.ILocation.FilterByIntersect(filteredFaces, locationContainer.NormalizedRectangle, _RectangleIntersectMinimum); + intersectFaces = Shared.Models.Stateless.Methods.ILocation.FilterByIntersect(filteredFaces, _RectangleIntersectMinimum, locationContainer.WholePercentages); if (intersectFaces.Any()) checkFaces.AddRange(GetClosestFaceByDistanceIgnoringTolerance(mappingFromItem, intersectFaces, modelsFaceEncoding)); } @@ -313,18 +313,18 @@ public partial class E_Distance _DuplicateMappedFaceFiles.Clear(); } - public List GetMissingFaceDistanceContainer(int maxDegreeOfParallelism, long ticks, string dFacesCollectionDirectory, Dictionary> missingIdThenNormalizedRectangleToPersonContainers) + public List GetMissingFaceDistanceContainer(int maxDegreeOfParallelism, long ticks, string dFacesCollectionDirectory, Dictionary> missingIdThenWholePercentagesToPersonContainers) { List results = new(); string[] files; List? faces; + int wholePercentages; int confidencePercent; - int normalizedRectangle; bool? isWrongYear = null; FaceDistance faceDistance; List<(int id, string json)> collection = new(); FaceDistanceContainer faceDistanceContainer; - foreach (KeyValuePair> keyValuePair in missingIdThenNormalizedRectangleToPersonContainers) + foreach (KeyValuePair> keyValuePair in missingIdThenWholePercentagesToPersonContainers) { files = Directory.GetFiles(dFacesCollectionDirectory, $"{keyValuePair.Key}*.json", SearchOption.TopDirectoryOnly); if (files.Length != 1) @@ -349,13 +349,13 @@ public partial class E_Distance if (face.FaceEncoding is null || face.Location is null || face.OutputResolution is null) continue; confidencePercent = Shared.Models.Stateless.Methods.ILocation.GetConfidencePercent(_FaceConfidencePercent, _RangeFaceConfidence, face.Location.Confidence); - normalizedRectangle = Shared.Models.Stateless.Methods.ILocation.GetNormalizedRectangle(face.Location, Shared.Models.Stateless.ILocation.Digits, face.OutputResolution); + wholePercentages = Shared.Models.Stateless.Methods.ILocation.GetWholePercentages(face.Location, Shared.Models.Stateless.ILocation.Digits, face.OutputResolution); if (face.FaceDistance?.Encoding is not null && face.FaceDistance.Encoding is FaceRecognitionDotNet.FaceEncoding faceEncoding) - faceDistance = new(confidencePercent, face.DateTime, faceEncoding, id, isWrongYear, normalizedRectangle); + faceDistance = new(confidencePercent, face.DateTime, faceEncoding, id, isWrongYear, wholePercentages); else { faceEncoding = FaceRecognition.LoadFaceEncoding(face.FaceEncoding.RawEncoding); - faceDistance = new(confidencePercent, face.DateTime, faceEncoding, id, isWrongYear, normalizedRectangle); + faceDistance = new(confidencePercent, face.DateTime, faceEncoding, id, isWrongYear, wholePercentages); face.SetFaceDistance(faceDistance); } faceDistanceContainer = new(face, faceDistance); @@ -394,7 +394,7 @@ public partial class E_Distance return; progressBar.Tick(); faceEncoding = FaceRecognition.LoadFaceEncoding(face.FaceEncoding.RawEncoding); - FaceDistance faceDistance = new(face.Mapping.MappingFromLocation.ConfidencePercent, face.Mapping.MappingFromItem.GetDateTimeOriginalThenMinimumDateTime(), faceEncoding, face.Mapping.MappingFromItem.Id, face.Mapping.MappingFromItem.IsWrongYear, face.Mapping.MappingFromLocation.NormalizedRectangle); + FaceDistance faceDistance = new(face.Mapping.MappingFromLocation.ConfidencePercent, face.Mapping.MappingFromItem.GetDateTimeOriginalThenMinimumDateTime(), faceEncoding, face.Mapping.MappingFromItem.Id, face.Mapping.MappingFromItem.IsWrongYear, face.Mapping.MappingFromLocation.WholePercentages); lock (face) face.SetFaceDistance(faceDistance); }); @@ -408,7 +408,7 @@ public partial class E_Distance Sorting[] collection = Shared.Models.Stateless.Methods.ISorting.Sort(sortingCollection); foreach (Sorting sorting in collection) { - if (face.Mapping?.MappingFromLocation is null || faceDistanceEncoding.NormalizedRectangle is null) + if (face.Mapping?.MappingFromLocation is null || faceDistanceEncoding.WholePercentages is null) throw new NotSupportedException(); if (!mapConfiguration.SaveSortingWithoutPerson && face.Mapping.MappingFromPerson is null) continue; @@ -451,7 +451,7 @@ public partial class E_Distance throw new NotSupportedException(); if (face.FaceDistance?.Encoding is not FaceRecognitionDotNet.FaceEncoding faceEncoding) continue; - faceDistance = new(face.Mapping.MappingFromLocation.ConfidencePercent, face.Mapping.MappingFromItem.GetDateTimeOriginalThenMinimumDateTime(), faceEncoding, face.Mapping.MappingFromItem.Id, face.Mapping.MappingFromItem.IsWrongYear, face.Mapping.MappingFromLocation.NormalizedRectangle); + faceDistance = new(face.Mapping.MappingFromLocation.ConfidencePercent, face.Mapping.MappingFromItem.GetDateTimeOriginalThenMinimumDateTime(), faceEncoding, face.Mapping.MappingFromItem.Id, face.Mapping.MappingFromItem.IsWrongYear, face.Mapping.MappingFromLocation.WholePercentages); faceDistanceContainer = new(face, faceDistance); collection.Add(faceDistanceContainer); } diff --git a/Face/Models/_D_Face.cs b/Face/Models/_D_Face.cs index 2792e2f..0693201 100644 --- a/Face/Models/_D_Face.cs +++ b/Face/Models/_D_Face.cs @@ -307,13 +307,13 @@ public class D_Face { if (face.Location is null || face.OutputResolution is null) continue; - skip.Add(Shared.Models.Stateless.Methods.ILocation.GetNormalizedRectangle(face.Location, ILocation.Digits, face.OutputResolution)); + skip.Add(Shared.Models.Stateless.Methods.ILocation.GetWholePercentages(face.Location, ILocation.Digits, face.OutputResolution)); } foreach (LocationContainer locationContainer in collection) { if (locationContainer.Directories is null) continue; - if (skip.Contains(locationContainer.NormalizedRectangle)) + if (skip.Contains(locationContainer.WholePercentages)) continue; foreach (Shared.Models.Face face in faces) { @@ -325,14 +325,14 @@ public class D_Face outputResolutionCheck = JsonSerializer.Deserialize(json); if (outputResolutionCheck is null || outputResolutionCheck.Width != outputResolutionWidth || outputResolutionCheck.Height != outputResolutionHeight) continue; - rectangle = Shared.Models.Stateless.Methods.ILocation.GetRectangle(ILocation.Digits, locationContainer.NormalizedRectangle, outputResolutionCheck); + rectangle = Shared.Models.Stateless.Methods.ILocation.GetRectangle(ILocation.Digits, outputResolutionCheck, locationContainer.WholePercentages); if (rectangle is null) continue; location = Shared.Models.Stateless.Methods.ILocation.GetLocation(outputResolutionHeight, rectangle.Value, outputResolutionWidth); if (location is null) continue; - if (!results.Any(l => l.NormalizedRectangle == locationContainer.NormalizedRectangle)) - results.Add(new(locationContainer.FromDistanceContent, locationContainer.File, locationContainer.PersonKey, locationContainer.Id, locationContainer.NormalizedRectangle, locationContainer.Directories, rectangle.Value, location)); + if (!results.Any(l => l.WholePercentages == locationContainer.WholePercentages)) + results.Add(new(locationContainer.FromDistanceContent, locationContainer.File, locationContainer.PersonKey, locationContainer.Id, locationContainer.WholePercentages, locationContainer.Directories, rectangle.Value, location)); } } if (results.Any()) diff --git a/Instance/DlibDotNet.cs b/Instance/DlibDotNet.cs index 084e4a6..319c3a6 100644 --- a/Instance/DlibDotNet.cs +++ b/Instance/DlibDotNet.cs @@ -292,7 +292,7 @@ public partial class DlibDotNet int faceAreaPermyriad; int confidencePercent; bool? inSkipCollection; - int normalizedRectangle; + int wholePercentRectangle; string deterministicHashCodeKey; MappingFromFilter mappingFromFilter; MappingFromLocation? mappingFromLocation; @@ -309,9 +309,9 @@ public partial class DlibDotNet { confidencePercent = Shared.Models.Stateless.Methods.ILocation.GetConfidencePercent(_Configuration.FaceConfidencePercent, _Configuration.RangeFaceConfidence, face.Location.Confidence); faceAreaPermyriad = Shared.Models.Stateless.Methods.IMapping.GetAreaPermyriad(_Configuration.FaceAreaPermyriad, face.Location, face.OutputResolution); - normalizedRectangle = Shared.Models.Stateless.Methods.ILocation.GetNormalizedRectangle(face.Location, Shared.Models.Stateless.ILocation.Digits, face.OutputResolution); + wholePercentRectangle = Shared.Models.Stateless.Methods.ILocation.GetWholePercentages(face.Location, Shared.Models.Stateless.ILocation.Digits, face.OutputResolution); deterministicHashCodeKey = Shared.Models.Stateless.Methods.IMapping.GetDeterministicHashCodeKey(item.Property.Id.Value, face.Location, Shared.Models.Stateless.ILocation.Digits, face.OutputResolution); - mappingFromLocation = new(faceAreaPermyriad, confidencePercent, deterministicHashCodeKey, normalizedRectangle); + mappingFromLocation = new(faceAreaPermyriad, confidencePercent, deterministicHashCodeKey, wholePercentRectangle); inSkipCollection = mapLogic.InSkipCollection(item.Property.Id.Value, mappingFromLocation); mappingFromFilter = new(isFocusModel, isFocusRelativePath, isIgnoreRelativePath, inSkipCollection); } @@ -325,7 +325,7 @@ public partial class DlibDotNet { Mapping result; bool? inSkipCollection; - int normalizedRectangle; + int wholePercentRectangle; int faceAreaPermyriad = 0; int confidencePercent = 0; string deterministicHashCodeKey; @@ -340,9 +340,9 @@ public partial class DlibDotNet } else { - normalizedRectangle = Shared.Models.Stateless.Methods.ILocation.GetNormalizedRectangle(Shared.Models.Stateless.ILocation.Digits); + wholePercentRectangle = Shared.Models.Stateless.Methods.ILocation.GetWholePercentages(Shared.Models.Stateless.ILocation.Digits); deterministicHashCodeKey = Shared.Models.Stateless.Methods.IMapping.GetDeterministicHashCodeKey(item.Property.Id.Value, Shared.Models.Stateless.ILocation.Digits); - mappingFromLocation = new(faceAreaPermyriad, confidencePercent, deterministicHashCodeKey, normalizedRectangle); + mappingFromLocation = new(faceAreaPermyriad, confidencePercent, deterministicHashCodeKey, wholePercentRectangle); inSkipCollection = mapLogic.InSkipCollection(item.Property.Id.Value, mappingFromLocation); mappingFromFilter = new(isFocusModel, isFocusRelativePath, isIgnoreRelativePath, inSkipCollection); } @@ -717,7 +717,7 @@ public partial class DlibDotNet } } - private void SaveFaceDistances(long ticks, MapLogic mapLogic, Mapping[] mappingCollection, string dFacesContentDirectory, string d2FacePartsContentDirectory, string d2FacePartsContentCollectionDirectory, Dictionary> idToNormalizedRectangleToMapping, List faceDistanceEncodings, FaceDistanceContainer[] faceDistanceContainers) + private void SaveFaceDistances(long ticks, MapLogic mapLogic, Mapping[] mappingCollection, string dFacesContentDirectory, string d2FacePartsContentDirectory, string d2FacePartsContentCollectionDirectory, Dictionary> idToWholePercentagesToMapping, List faceDistanceEncodings, FaceDistanceContainer[] faceDistanceContainers) { if (_Log is null) throw new NullReferenceException(nameof(_Log)); @@ -753,21 +753,21 @@ public partial class DlibDotNet if (filteredFaceDistanceContainers.Length > 0) { int updated = mapLogic.UpdateFromSortingContainers(_Configuration.SaveIndividually, distanceLimits, sortingContainers); - List saveContainers = mapLogic.GetSaveContainers(_Configuration.SaveIndividually, dFacesContentDirectory, d2FacePartsContentDirectory, d2FacePartsContentCollectionDirectory, mappingCollection, idToNormalizedRectangleToMapping, useFiltersCounter, sortingContainers.Any()); + List saveContainers = mapLogic.GetSaveContainers(_Configuration.SaveIndividually, dFacesContentDirectory, d2FacePartsContentDirectory, d2FacePartsContentCollectionDirectory, mappingCollection, idToWholePercentagesToMapping, useFiltersCounter, sortingContainers.Any()); mapLogic.SaveContainers(_Configuration.SaveIndividually, filteredFaceDistanceContainers.Length, updated, saveContainers); } } } - private void SaveFaceDistances(long ticks, MapLogic mapLogic, List distinctFilteredFaces, Mapping[] mappingCollection, string dFacesContentDirectory, string d2FacePartsContentDirectory, string d2FacePartsContentCollectionDirectory, string dFacesCollectionDirectory, Dictionary> idToNormalizedRectangleToMapping) + private void SaveFaceDistances(long ticks, MapLogic mapLogic, List distinctFilteredFaces, Mapping[] mappingCollection, string dFacesContentDirectory, string d2FacePartsContentDirectory, string d2FacePartsContentCollectionDirectory, string dFacesCollectionDirectory, Dictionary> idToWholePercentagesToMapping) { E_Distance.SetFaceDistances(_AppSettings.MaxDegreeOfParallelism, ticks, distinctFilteredFaces); FaceDistanceContainer[] faceDistanceContainers = E_Distance.GetFaceDistanceContainers(distinctFilteredFaces); - Dictionary> missingIdThenNormalizedRectangleToPersonContainers = mapLogic.GetMissing(idToNormalizedRectangleToMapping); - List missingFaceDistanceContainers = _Distance.GetMissingFaceDistanceContainer(_AppSettings.MaxDegreeOfParallelism, ticks, dFacesCollectionDirectory, missingIdThenNormalizedRectangleToPersonContainers); + Dictionary> missingIdThenWholePercentagesToPersonContainers = mapLogic.GetMissing(idToWholePercentagesToMapping); + List missingFaceDistanceContainers = _Distance.GetMissingFaceDistanceContainer(_AppSettings.MaxDegreeOfParallelism, ticks, dFacesCollectionDirectory, missingIdThenWholePercentagesToPersonContainers); List faceDistanceEncodings = E_Distance.GetFaceDistanceEncodings(faceDistanceContainers, missingFaceDistanceContainers); if (faceDistanceContainers.Any()) - SaveFaceDistances(ticks, mapLogic, mappingCollection, dFacesContentDirectory, d2FacePartsContentDirectory, d2FacePartsContentCollectionDirectory, idToNormalizedRectangleToMapping, faceDistanceEncodings, faceDistanceContainers); + SaveFaceDistances(ticks, mapLogic, mappingCollection, dFacesContentDirectory, d2FacePartsContentDirectory, d2FacePartsContentCollectionDirectory, idToWholePercentagesToMapping, faceDistanceEncodings, faceDistanceContainers); } private void MapLogic(long ticks, Container[] containers, string a2PeopleSingletonDirectory, string dResultsFullGroupDirectory, string d2ResultsFullGroupDirectory, string fPhotoPrismContentDirectory, MapLogic mapLogic, string outputResolution, Dictionary> personKeyToIds, List distinctFilteredFaces, Mapping[] distinctFilteredMappingCollection, int totalNotMapped) @@ -781,7 +781,7 @@ public partial class DlibDotNet Shared.Models.Stateless.Methods.IPath.ChangeDateForEmptyDirectories(d2FacePartsContentDirectory, ticks); Shared.Models.Stateless.Methods.IPath.MakeHiddenIfAllItemsAreHidden(d2FacePartsContentCollectionDirectory); } - Dictionary> idToNormalizedRectangleToMapping = Map.Models.Stateless.Methods.IMapLogic.GetIdToNormalizedRectangleToFace(distinctFilteredMappingCollection); + Dictionary> idToWholePercentagesToMapping = Map.Models.Stateless.Methods.IMapLogic.GetIdToWholePercentagesToFace(distinctFilteredMappingCollection); if (Directory.Exists(fPhotoPrismContentDirectory)) F_PhotoPrism.WriteMatches(fPhotoPrismContentDirectory, _Configuration.MappingDefaultName, _Configuration.PersonBirthdayFormat, _Configuration.RectangleIntersectMinimums, ticks, distinctFilteredFaces, mapLogic); if (_Configuration.SaveShortcutsForOutputResolutions.Contains(outputResolution)) @@ -792,11 +792,11 @@ public partial class DlibDotNet mapLogic.CopyAtLeastOneMappedFiles(_Configuration.PersonCharactersCopyCount, dFacesContentDirectory, a2PeopleSingletonDirectory, distinctFilteredMappingCollection); mapLogic.SavePersonKeyToCount(dFacesContentDirectory, a2PeopleSingletonDirectory, distinctFilteredMappingCollection); } - mapLogic.CopyManualFiles(dFacesContentDirectory, idToNormalizedRectangleToMapping); + mapLogic.CopyManualFiles(dFacesContentDirectory, idToWholePercentagesToMapping); if (_Configuration.SaveMappedForOutputResolutions.Contains(outputResolution)) - mapLogic.SaveMapped(dFacesContentDirectory, d2FacePartsContentDirectory, d2FacePartsContentCollectionDirectory, personKeyToIds, distinctFilteredMappingCollection, idToNormalizedRectangleToMapping, totalNotMapped); + mapLogic.SaveMapped(dFacesContentDirectory, d2FacePartsContentDirectory, d2FacePartsContentCollectionDirectory, personKeyToIds, distinctFilteredMappingCollection, idToWholePercentagesToMapping, totalNotMapped); if (_Configuration.SaveFaceDistancesForOutputResolutions.Contains(outputResolution)) - SaveFaceDistances(ticks, mapLogic, distinctFilteredFaces, distinctFilteredMappingCollection, dFacesContentDirectory, d2FacePartsContentDirectory, d2FacePartsContentCollectionDirectory, dFacesCollectionDirectory, idToNormalizedRectangleToMapping); + SaveFaceDistances(ticks, mapLogic, distinctFilteredFaces, distinctFilteredMappingCollection, dFacesContentDirectory, d2FacePartsContentDirectory, d2FacePartsContentCollectionDirectory, dFacesCollectionDirectory, idToWholePercentagesToMapping); } private string SaveUrlAndGetNewRootDirectory(Container container) diff --git a/Map/Models/MapLogic.cs b/Map/Models/MapLogic.cs index d77f5bb..3061d1d 100644 --- a/Map/Models/MapLogic.cs +++ b/Map/Models/MapLogic.cs @@ -18,7 +18,7 @@ public class MapLogic : Shared.Models.Methods.IMapLogic protected readonly ReadOnlyDictionary> _SkipNotSkipCollection; protected readonly ReadOnlyDictionary _PersonKeyToPersonContainer; protected readonly List> _LocationContainers; - protected readonly ReadOnlyDictionary> _IdThenNormalizedRectangleToPersonContainers; + protected readonly ReadOnlyDictionary> _IdThenWholePercentagesToPersonContainers; private readonly long _Ticks; private readonly Serilog.ILogger? _Log; @@ -44,7 +44,7 @@ public class MapLogic : Shared.Models.Methods.IMapLogic List> locationContainers = new(); string? rootDirectoryParent = Path.GetDirectoryName(propertyConfiguration.RootDirectory); string eDistanceContentTicksDirectory = Path.Combine(eDistanceContentDirectory, $"({ticks})"); - Dictionary> idThenNormalizedRectangleToPersonContainers = new(); + Dictionary> idThenWholePercentagesToPersonContainers = new(); Dictionary>> idToLocationContainers = new(); if (string.IsNullOrEmpty(rootDirectoryParent)) throw new NullReferenceException(nameof(rootDirectoryParent)); @@ -63,7 +63,7 @@ public class MapLogic : Shared.Models.Methods.IMapLogic skipCollection, skipNotSkipCollection, locationContainers, - idThenNormalizedRectangleToPersonContainers); + idThenWholePercentagesToPersonContainers); } foreach (string propertyContentCollectionFile in propertyConfiguration.PropertyContentCollectionFiles) { @@ -83,7 +83,7 @@ public class MapLogic : Shared.Models.Methods.IMapLogic _PersonKeyToPersonContainer = new(personKeyToPersonContainer); _EDistanceContentTicksDirectory = eDistanceContentTicksDirectory; _NotMappedPersonContainers = notMappedPersonContainers.OrderByDescending(l => l.Key).ToList(); - _IdThenNormalizedRectangleToPersonContainers = new(idThenNormalizedRectangleToPersonContainers); + _IdThenWholePercentagesToPersonContainers = new(idThenWholePercentagesToPersonContainers); } public override string ToString() @@ -113,11 +113,11 @@ public class MapLogic : Shared.Models.Methods.IMapLogic List? collection; PersonBirthday personBirthday; List shouldMove = new(); - foreach (KeyValuePair> idToCollection in _IdThenNormalizedRectangleToPersonContainers) + foreach (KeyValuePair> idToCollection in _IdThenWholePercentagesToPersonContainers) { - foreach (KeyValuePair normalizedRectangleToPersonContainers in idToCollection.Value) + foreach (KeyValuePair wholePercentagesToPersonContainers in idToCollection.Value) { - foreach (PersonContainer personContainer in normalizedRectangleToPersonContainers.Value) + foreach (PersonContainer personContainer in wholePercentagesToPersonContainers.Value) { if (personContainer.Key is null || personContainer.Birthdays is null || !personContainer.Birthdays.Any()) continue; @@ -142,10 +142,10 @@ public class MapLogic : Shared.Models.Methods.IMapLogic return results; } - (bool, Dictionary?) Shared.Models.Methods.IMapLogic.GetNormalizedRectangleToPersonContainers(int id) + (bool, Dictionary?) Shared.Models.Methods.IMapLogic.GetWholePercentagesToPersonContainers(int id) { - bool result = _IdThenNormalizedRectangleToPersonContainers.TryGetValue(id, out Dictionary? normalizedRectangleToPersonContainers); - return new(result, normalizedRectangleToPersonContainers); + bool result = _IdThenWholePercentagesToPersonContainers.TryGetValue(id, out Dictionary? wholePercentagesToPersonContainers); + return new(result, wholePercentagesToPersonContainers); } public int UpdateMappingFromPerson(Mapping mapping) @@ -158,19 +158,19 @@ public class MapLogic : Shared.Models.Methods.IMapLogic string mappingSegmentB; PersonBirthday personBirthday; PersonContainer[]? personContainers; - Dictionary? normalizedRectangleToPersonContainers; + Dictionary? wholePercentagesToPersonContainers; for (int i = 1; i < 2; i++) { if (mapping.MappingFromLocation is null) continue; - if (!_IdThenNormalizedRectangleToPersonContainers.TryGetValue(mapping.MappingFromItem.Id, out normalizedRectangleToPersonContainers)) + if (!_IdThenWholePercentagesToPersonContainers.TryGetValue(mapping.MappingFromItem.Id, out wholePercentagesToPersonContainers)) { if (mapping.MappingFromFilter.InSkipCollection is not null && mapping.MappingFromFilter.InSkipCollection.Value) continue; result += 1; continue; } - if (!normalizedRectangleToPersonContainers.TryGetValue(mapping.MappingFromLocation.NormalizedRectangle, out personContainers)) + if (!wholePercentagesToPersonContainers.TryGetValue(mapping.MappingFromLocation.WholePercentages, out personContainers)) { if (mapping.MappingFromFilter.InSkipCollection is not null && mapping.MappingFromFilter.InSkipCollection.Value) continue; @@ -359,7 +359,7 @@ public class MapLogic : Shared.Models.Methods.IMapLogic string personKeyFormatted; PersonBirthday personBirthday; PersonContainer personContainer; - result = Path.Combine(_EDistanceContentTicksDirectory, by, sortingContainer.Sorting.Id.ToString(), sortingContainer.Sorting.NormalizedRectangle.ToString()); + result = Path.Combine(_EDistanceContentTicksDirectory, by, sortingContainer.Sorting.Id.ToString(), sortingContainer.Sorting.WholePercentages.ToString()); for (int i = _NotMappedPersonContainers.Count - 1; i > 0; i--) { personContainer = _NotMappedPersonContainers[i]; @@ -378,7 +378,7 @@ public class MapLogic : Shared.Models.Methods.IMapLogic return result; } - private List GetSaveContainers(string dFacesContentDirectory, string d2FacePartsContentDirectory, string d2FacePartsContentCollectionDirectory, Mapping[] mappingCollection, Dictionary> idToNormalizedRectangleToMapping, Dictionary> personKeyToIds, int? useFiltersCounter, bool saveMapped, bool saveIndividually, bool sortingContainersAny) + private List GetSaveContainers(string dFacesContentDirectory, string d2FacePartsContentDirectory, string d2FacePartsContentCollectionDirectory, Mapping[] mappingCollection, Dictionary> idToWholePercentagesToMapping, Dictionary> personKeyToIds, int? useFiltersCounter, bool saveMapped, bool saveIndividually, bool sortingContainersAny) { if (_Configuration is null) throw new NullReferenceException(nameof(_Configuration)); @@ -404,7 +404,7 @@ public class MapLogic : Shared.Models.Methods.IMapLogic FileHolder facePartsFileHolder; FileHolder hiddenFaceFileHolder; string? facePartsContentCollectionFile; - Dictionary? normalizedRectangleToMapping; + Dictionary? wholePercentagesToMapping; int padLeft = _Configuration.FaceDistancePermyriad.ToString().Length; string forceSingleImageHumanized = nameof(Shared.Models.Stateless.IMapLogic.ForceSingleImage).Humanize(LetterCasing.Title); foreach (Mapping mapping in mappingCollection) @@ -479,14 +479,14 @@ public class MapLogic : Shared.Models.Methods.IMapLogic keyMapping = null; else { - if (!idToNormalizedRectangleToMapping.TryGetValue(mapping.SortingContainer.Sorting.Id, out normalizedRectangleToMapping)) + if (!idToWholePercentagesToMapping.TryGetValue(mapping.SortingContainer.Sorting.Id, out wholePercentagesToMapping)) continue; - if (!normalizedRectangleToMapping.ContainsKey(mapping.SortingContainer.Sorting.NormalizedRectangle)) + if (!wholePercentagesToMapping.ContainsKey(mapping.SortingContainer.Sorting.WholePercentages)) continue; - keyMapping = normalizedRectangleToMapping[mapping.SortingContainer.Sorting.NormalizedRectangle]; + keyMapping = wholePercentagesToMapping[mapping.SortingContainer.Sorting.WholePercentages]; if (keyMapping.MappingFromLocation is null) continue; - if (saveIndividually && keyMapping.MappingFromLocation.NormalizedRectangle == mapping.MappingFromLocation.NormalizedRectangle) + if (saveIndividually && keyMapping.MappingFromLocation.WholePercentages == mapping.MappingFromLocation.WholePercentages) results.Add(new(Path.Combine(directory, "Maybe"))); } facesDirectory = Stateless.MapLogic.GetFacesDirectory(dFacesContentDirectory, mapping.MappingFromItem); @@ -545,18 +545,18 @@ public class MapLogic : Shared.Models.Methods.IMapLogic return results; } - public List GetSaveContainers(bool saveIndividually, string dFacesContentDirectory, string d2FacePartsContentDirectory, string d2FacePartsContentCollectionDirectory, Mapping[] mappingCollection, Dictionary> idToNormalizedRectangleToMapping, int? useFiltersCounter, bool sortingContainersAny) + public List GetSaveContainers(bool saveIndividually, string dFacesContentDirectory, string d2FacePartsContentDirectory, string d2FacePartsContentCollectionDirectory, Mapping[] mappingCollection, Dictionary> idToWholePercentagesToMapping, int? useFiltersCounter, bool sortingContainersAny) { if (_Configuration is null) throw new NullReferenceException(nameof(_Configuration)); List results; bool saveMapped = false; Dictionary> personKeyToIds = new(); - results = GetSaveContainers(dFacesContentDirectory, d2FacePartsContentDirectory, d2FacePartsContentCollectionDirectory, mappingCollection, idToNormalizedRectangleToMapping, personKeyToIds, useFiltersCounter, saveMapped, saveIndividually, sortingContainersAny); + results = GetSaveContainers(dFacesContentDirectory, d2FacePartsContentDirectory, d2FacePartsContentCollectionDirectory, mappingCollection, idToWholePercentagesToMapping, personKeyToIds, useFiltersCounter, saveMapped, saveIndividually, sortingContainersAny); return results; } - public void SaveMapped(string dFacesContentDirectory, string d2FacePartsContentDirectory, string d2FacePartsContentCollectionDirectory, Dictionary> personKeyToIds, Mapping[] mappingCollection, Dictionary> idToNormalizedRectangleToMapping, int totalNotMapped) + public void SaveMapped(string dFacesContentDirectory, string d2FacePartsContentDirectory, string d2FacePartsContentCollectionDirectory, Dictionary> personKeyToIds, Mapping[] mappingCollection, Dictionary> idToWholePercentagesToMapping, int totalNotMapped) { if (_Configuration is null) throw new NullReferenceException(nameof(_Configuration)); @@ -565,7 +565,7 @@ public class MapLogic : Shared.Models.Methods.IMapLogic int? useFiltersCounter = null; bool saveIndividually = false; string mappingDirectory = Path.Combine(_EDistanceContentTicksDirectory, nameof(Shared.Models.Stateless.IMapLogic.Mapping)); - List saveContainers = GetSaveContainers(dFacesContentDirectory, d2FacePartsContentDirectory, d2FacePartsContentCollectionDirectory, mappingCollection, idToNormalizedRectangleToMapping, personKeyToIds, useFiltersCounter, saveMapped, sortingContainersAny: true, saveIndividually: false); + List saveContainers = GetSaveContainers(dFacesContentDirectory, d2FacePartsContentDirectory, d2FacePartsContentCollectionDirectory, mappingCollection, idToWholePercentagesToMapping, personKeyToIds, useFiltersCounter, saveMapped, sortingContainersAny: true, saveIndividually: false); SaveContainers(saveIndividually, totalNotMapped, updated, saveContainers); if (!string.IsNullOrEmpty(_EDistanceContentTicksDirectory) && Directory.Exists(mappingDirectory)) Stateless.MapLogic.SaveMappingShortcuts(mappingDirectory); @@ -574,15 +574,15 @@ public class MapLogic : Shared.Models.Methods.IMapLogic public bool Used(FaceDistance faceDistanceEncoding) { bool result = false; - if (faceDistanceEncoding.NormalizedRectangle is null) + if (faceDistanceEncoding.WholePercentages is null) throw new NotSupportedException(); - List? normalizedRectangles; - Dictionary? normalizedRectangleToPersonContainers; - if (_SkipCollection.TryGetValue(faceDistanceEncoding.Id, out normalizedRectangles) && normalizedRectangles.Contains(faceDistanceEncoding.NormalizedRectangle.Value)) + List? wholePercentagesCollection; + Dictionary? wholePercentagesToPersonContainers; + if (_SkipCollection.TryGetValue(faceDistanceEncoding.Id, out wholePercentagesCollection) && wholePercentagesCollection.Contains(faceDistanceEncoding.WholePercentages.Value)) result = true; - if (!result && _IdThenNormalizedRectangleToPersonContainers.TryGetValue(faceDistanceEncoding.Id, out normalizedRectangleToPersonContainers)) + if (!result && _IdThenWholePercentagesToPersonContainers.TryGetValue(faceDistanceEncoding.Id, out wholePercentagesToPersonContainers)) { - if (normalizedRectangleToPersonContainers.ContainsKey(faceDistanceEncoding.NormalizedRectangle.Value)) + if (wholePercentagesToPersonContainers.ContainsKey(faceDistanceEncoding.WholePercentages.Value)) result = true; } return result; @@ -595,26 +595,26 @@ public class MapLogic : Shared.Models.Methods.IMapLogic List results = new(); Sorting sorting; FaceDistance faceDistanceLength; - List? normalizedRectangles; + List? wholePercentagesCollection; bool skipNotSkipCollectionAny = _SkipNotSkipCollection.Any(); - Dictionary? normalizedRectangleToPersonContainers; + Dictionary? wholePercentagesToPersonContainers; for (int j = 0; j < faceDistanceLengths.Count; j++) { - if (faceDistanceEncoding.NormalizedRectangle is null) + if (faceDistanceEncoding.WholePercentages is null) throw new NotSupportedException(); if (j == i) continue; - if (_SkipCollection.TryGetValue(faceDistanceEncoding.Id, out normalizedRectangles) && normalizedRectangles.Contains(faceDistanceEncoding.NormalizedRectangle.Value)) + if (_SkipCollection.TryGetValue(faceDistanceEncoding.Id, out wholePercentagesCollection) && wholePercentagesCollection.Contains(faceDistanceEncoding.WholePercentages.Value)) continue; - if (skipNotSkipCollectionAny && (!_SkipNotSkipCollection.TryGetValue(faceDistanceEncoding.Id, out normalizedRectangles) || !normalizedRectangles.Contains(faceDistanceEncoding.NormalizedRectangle.Value))) + if (skipNotSkipCollectionAny && (!_SkipNotSkipCollection.TryGetValue(faceDistanceEncoding.Id, out wholePercentagesCollection) || !wholePercentagesCollection.Contains(faceDistanceEncoding.WholePercentages.Value))) continue; - if (_IdThenNormalizedRectangleToPersonContainers.TryGetValue(faceDistanceEncoding.Id, out normalizedRectangleToPersonContainers)) + if (_IdThenWholePercentagesToPersonContainers.TryGetValue(faceDistanceEncoding.Id, out wholePercentagesToPersonContainers)) { - if (normalizedRectangleToPersonContainers.ContainsKey(faceDistanceEncoding.NormalizedRectangle.Value)) + if (wholePercentagesToPersonContainers.ContainsKey(faceDistanceEncoding.WholePercentages.Value)) continue; } faceDistanceLength = faceDistanceLengths[j]; - if (faceDistanceLength.NormalizedRectangle is null || faceDistanceLength.Length is null) + if (faceDistanceLength.WholePercentages is null || faceDistanceLength.Length is null) throw new NotSupportedException(); if (faceDistanceLength.Length == 0) continue; @@ -623,7 +623,7 @@ public class MapLogic : Shared.Models.Methods.IMapLogic continue; if (sorting.Id == faceDistanceEncoding.Id) { - if (sorting.NormalizedRectangle == faceDistanceEncoding.NormalizedRectangle.Value) + if (sorting.WholePercentages == faceDistanceEncoding.WholePercentages.Value) continue; continue; } @@ -648,13 +648,13 @@ public class MapLogic : Shared.Models.Methods.IMapLogic string personKeyFormatted; PersonBirthday personBirthday; PersonContainer[]? personContainers; + List wholePercentagesCollectionForA; + List wholePercentagesCollectionForB; Dictionary keyToCount = new(); - List normalizedRectangleCollectionForA; - List normalizedRectangleCollectionForB; Dictionary keyToSegmentC = new(); - Dictionary> idToNormalizedRectangleCollectionForA = new(); - Dictionary> idToNormalizedRectangleCollectionForB = new(); - Dictionary? normalizedRectangleToPersonContainers; + Dictionary> idToWholePercentagesCollectionForA = new(); + Dictionary> idToWholePercentagesCollectionForB = new(); + Dictionary? wholePercentagesToPersonContainers; int totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - _Ticks).TotalSeconds); string message = $") {sortingContainers.Length:000} Update From Sorting Container(s) - {totalSeconds} total second(s)"; ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true }; @@ -664,25 +664,25 @@ public class MapLogic : Shared.Models.Methods.IMapLogic progressBar.Tick(); if (sortingContainer.Mapping?.MappingFromLocation is null) throw new NotSupportedException(); - if (!idToNormalizedRectangleCollectionForA.ContainsKey(sortingContainer.Mapping.MappingFromItem.Id)) - idToNormalizedRectangleCollectionForA.Add(sortingContainer.Mapping.MappingFromItem.Id, new()); - normalizedRectangleCollectionForA = idToNormalizedRectangleCollectionForA[sortingContainer.Mapping.MappingFromItem.Id]; - if (!idToNormalizedRectangleCollectionForB.ContainsKey(sortingContainer.Mapping.MappingFromItem.Id)) - idToNormalizedRectangleCollectionForB.Add(sortingContainer.Mapping.MappingFromItem.Id, new()); - normalizedRectangleCollectionForB = idToNormalizedRectangleCollectionForB[sortingContainer.Mapping.MappingFromItem.Id]; - if (!_IdThenNormalizedRectangleToPersonContainers.TryGetValue(sortingContainer.Sorting.Id, out normalizedRectangleToPersonContainers) || !normalizedRectangleToPersonContainers.TryGetValue(sortingContainer.Sorting.NormalizedRectangle, out personContainers)) + if (!idToWholePercentagesCollectionForA.ContainsKey(sortingContainer.Mapping.MappingFromItem.Id)) + idToWholePercentagesCollectionForA.Add(sortingContainer.Mapping.MappingFromItem.Id, new()); + wholePercentagesCollectionForA = idToWholePercentagesCollectionForA[sortingContainer.Mapping.MappingFromItem.Id]; + if (!idToWholePercentagesCollectionForB.ContainsKey(sortingContainer.Mapping.MappingFromItem.Id)) + idToWholePercentagesCollectionForB.Add(sortingContainer.Mapping.MappingFromItem.Id, new()); + wholePercentagesCollectionForB = idToWholePercentagesCollectionForB[sortingContainer.Mapping.MappingFromItem.Id]; + if (!_IdThenWholePercentagesToPersonContainers.TryGetValue(sortingContainer.Sorting.Id, out wholePercentagesToPersonContainers) || !wholePercentagesToPersonContainers.TryGetValue(sortingContainer.Sorting.WholePercentages, out personContainers)) { if (!_Configuration.SaveSortingWithoutPerson) continue; - if (normalizedRectangleCollectionForA.Contains(sortingContainer.Mapping.MappingFromLocation.NormalizedRectangle)) + if (wholePercentagesCollectionForA.Contains(sortingContainer.Mapping.MappingFromLocation.WholePercentages)) continue; sortingContainer.Mapping.UpdateMappingFromUnknownPerson(saveIndividually, sortingContainer); - normalizedRectangleCollectionForA.Add(sortingContainer.Mapping.MappingFromLocation.NormalizedRectangle); + wholePercentagesCollectionForA.Add(sortingContainer.Mapping.MappingFromLocation.WholePercentages); result += 1; } else { - if (normalizedRectangleCollectionForB.Contains(sortingContainer.Mapping.MappingFromLocation.NormalizedRectangle)) + if (wholePercentagesCollectionForB.Contains(sortingContainer.Mapping.MappingFromLocation.WholePercentages)) continue; foreach (PersonContainer personContainer in personContainers) { @@ -705,7 +705,7 @@ public class MapLogic : Shared.Models.Methods.IMapLogic keyToSegmentC[key] = sortingContainer.Sorting.DistancePermyriad.ToString(); } sortingContainer.Mapping.UpdateMappingFromPerson(personContainer.ApproximateYears, personContainer.DisplayDirectoryName, personBirthday, mappingSegmentB, keyToSegmentC[key], sortingContainer); - normalizedRectangleCollectionForB.Add(sortingContainer.Mapping.MappingFromLocation.NormalizedRectangle); + wholePercentagesCollectionForB.Add(sortingContainer.Mapping.MappingFromLocation.WholePercentages); result += 1; break; } @@ -714,7 +714,7 @@ public class MapLogic : Shared.Models.Methods.IMapLogic return result; } - public void CopyManualFiles(string dFacesContentDirectory, Dictionary> idToNormalizedRectangleToMapping) + public void CopyManualFiles(string dFacesContentDirectory, Dictionary> idToWholePercentagesToMapping) { if (_Configuration is null) throw new NullReferenceException(nameof(_Configuration)); @@ -727,19 +727,19 @@ public class MapLogic : Shared.Models.Methods.IMapLogic const int zero = 0; string faceFileName; string shortcutFile; + int? wholePercentages; string? directoryName; string mappingSegmentB; string personDirectory; string? facesDirectory; - int? normalizedRectangle; string personKeyFormatted; string personDisplayFileName; PersonBirthday personBirthday; string? personDisplayDirectory; WindowsShortcut windowsShortcut; - Dictionary? normalizedRectangleToMapping; + Dictionary? wholePercentagesToMapping; string by = nameof(Shared.Models.Stateless.IMapLogic.ManualCopy); - Dictionary? normalizedRectangleToPeronContainerCollection; + Dictionary? wholePercentagesToPeronContainerCollection; string successful = $"_ {nameof(Shared.Models.Stateless.IMapLogic.ManualCopy).Humanize(LetterCasing.Title)} Successful"; foreach (KeyValuePair personKeyToPersonContainer in _PersonKeyToPersonContainer) { @@ -750,8 +750,8 @@ public class MapLogic : Shared.Models.Methods.IMapLogic { if (!personDisplayDirectoryAllFile.EndsWith(_Configuration.FacesFileNameExtension)) continue; - (id, normalizedRectangle) = IMapping.GetConverted(_Configuration.FacesFileNameExtension, personDisplayDirectoryAllFile); - if (id is null || normalizedRectangle is null) + (id, wholePercentages) = IMapping.GetConverted(_Configuration.FacesFileNameExtension, personDisplayDirectoryAllFile); + if (id is null || wholePercentages is null) continue; fileInfo = new(personDisplayDirectoryAllFile); if (!fileInfo.Exists) @@ -762,11 +762,11 @@ public class MapLogic : Shared.Models.Methods.IMapLogic mappingSegmentB = Stateless.MapLogic.GetMappingSegmentB(_Ticks, personBirthday, personKeyToPersonContainer.Value.ApproximateYears, fileInfo.CreationTime, isWrongYear: null); directory = Path.Combine(_EDistanceContentTicksDirectory, by, personKeyFormatted, mappingSegmentB); personDirectory = Path.Combine(directory, personKeyToPersonContainer.Value.DisplayDirectoryName, "lnk"); - if (!idToNormalizedRectangleToMapping.TryGetValue(id.Value, out normalizedRectangleToMapping)) + if (!idToWholePercentagesToMapping.TryGetValue(id.Value, out wholePercentagesToMapping)) continue; - if (!normalizedRectangleToMapping.ContainsKey(normalizedRectangle.Value)) + if (!wholePercentagesToMapping.ContainsKey(wholePercentages.Value)) continue; - mapping = normalizedRectangleToMapping[normalizedRectangle.Value]; + mapping = wholePercentagesToMapping[wholePercentages.Value]; if (mapping.MappingFromLocation is null) continue; if (string.IsNullOrEmpty(personDisplayDirectory)) @@ -780,7 +780,7 @@ public class MapLogic : Shared.Models.Methods.IMapLogic continue; faceFileName = $"{mapping.MappingFromLocation.DeterministicHashCodeKey}{mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}{_Configuration.FacesFileNameExtension}"; checkFile = Path.Combine(directory, fileInfo.Name); - if (!_IdThenNormalizedRectangleToPersonContainers.TryGetValue(id.Value, out normalizedRectangleToPeronContainerCollection) || !normalizedRectangleToPeronContainerCollection.ContainsKey(normalizedRectangle.Value)) + if (!_IdThenWholePercentagesToPersonContainers.TryGetValue(id.Value, out wholePercentagesToPeronContainerCollection) || !wholePercentagesToPeronContainerCollection.ContainsKey(wholePercentages.Value)) { if (!Directory.Exists(personDirectory)) _ = Directory.CreateDirectory(personDirectory); @@ -1366,12 +1366,12 @@ public class MapLogic : Shared.Models.Methods.IMapLogic } } - public Dictionary> GetMissing(Dictionary> idToNormalizedRectangleToMapping) + public Dictionary> GetMissing(Dictionary> idToWholePercentagesToMapping) { Dictionary> results = new(); - foreach (KeyValuePair> idToCollection in _IdThenNormalizedRectangleToPersonContainers) + foreach (KeyValuePair> idToCollection in _IdThenWholePercentagesToPersonContainers) { - if (idToNormalizedRectangleToMapping.ContainsKey(idToCollection.Key)) + if (idToWholePercentagesToMapping.ContainsKey(idToCollection.Key)) continue; results.Add(idToCollection.Key, idToCollection.Value); } @@ -1381,7 +1381,7 @@ public class MapLogic : Shared.Models.Methods.IMapLogic public bool InSkipCollection(int id, MappingFromLocation mappingFromLocation) { bool result; - result = _SkipCollection.TryGetValue(id, out List? normalizedRectangles) && normalizedRectangles.Contains(mappingFromLocation.NormalizedRectangle); + result = _SkipCollection.TryGetValue(id, out List? wholePercentagesCollection) && wholePercentagesCollection.Contains(mappingFromLocation.WholePercentages); return result; } diff --git a/Map/Models/Stateless/MapLogic.cs b/Map/Models/Stateless/MapLogic.cs index 3c7aedf..65eda08 100644 --- a/Map/Models/Stateless/MapLogic.cs +++ b/Map/Models/Stateless/MapLogic.cs @@ -16,7 +16,7 @@ internal abstract class MapLogic private static void SetPersonCollections(Configuration configuration, ReadOnlyCollection personContainers, string? a2PeopleSingletonDirectory, Dictionary personKeyFormattedToNewestPersonKeyFormatted, List personKeyFormattedCollection, Dictionary> skipCollection, Dictionary> skipNotSkipCollection) { int? id; - int? normalizedRectangle; + int? wholePercentages; string personKeyFormatted; string newestPersonKeyFormatted; bool skipNotSkipDirectoriesAny = configuration.SkipNotSkipDirectories.Any(); @@ -27,20 +27,20 @@ internal abstract class MapLogic { if (!personDisplayDirectoryAllFile.EndsWith(configuration.FacesFileNameExtension)) continue; - (id, normalizedRectangle) = IMapping.GetConverted(configuration.FacesFileNameExtension, personDisplayDirectoryAllFile); - if (id is null || normalizedRectangle is null) + (id, wholePercentages) = IMapping.GetConverted(configuration.FacesFileNameExtension, personDisplayDirectoryAllFile); + if (id is null || wholePercentages is null) continue; if (!skipNotSkipDirectoriesAny || !checkDirectories.Any(l => personDisplayDirectoryAllFile.StartsWith(l))) { if (!skipCollection.ContainsKey(id.Value)) skipCollection.Add(id.Value, new()); - skipCollection[id.Value].Add(normalizedRectangle.Value); + skipCollection[id.Value].Add(wholePercentages.Value); } else { if (!skipNotSkipCollection.ContainsKey(id.Value)) skipNotSkipCollection.Add(id.Value, new()); - skipNotSkipCollection[id.Value].Add(normalizedRectangle.Value); + skipNotSkipCollection[id.Value].Add(wholePercentages.Value); } } if (personContainer.Person is null || personContainer.Key is null || personContainer.Birthdays is null || !personContainer.Birthdays.Any()) @@ -157,8 +157,8 @@ internal abstract class MapLogic string[] files; string fileName; const int zero = 0; + int? wholePercentages; string[] yearDirectories; - int? normalizedRectangle; string personKeyFormatted; string ticksDirectoryName; string? personFirstInitial; @@ -235,8 +235,8 @@ internal abstract class MapLogic { if (file.EndsWith(".lnk")) continue; - (id, normalizedRectangle) = IMapping.GetConverted(configuration.FacesFileNameExtension, file); - if (id is null || normalizedRectangle is null) + (id, wholePercentages) = IMapping.GetConverted(configuration.FacesFileNameExtension, file); + if (id is null || wholePercentages is null) continue; fileName = Path.GetFileName(file); if (distinct.Contains(fileName)) @@ -285,21 +285,21 @@ internal abstract class MapLogic return results.ToArray(); } - private static void SetKeyValuePairs(Configuration configuration, ReadOnlyCollection personContainers, Dictionary> personKeyToPersonContainerCollection, Dictionary personKeyFormattedToPersonContainer, List<(string, string[], int, int)> personKeyFormattedIdThenNormalizedRectangleCollection, Dictionary personKeyToPersonContainer, Dictionary> idThenNormalizedRectangleToPersonContainers, List<(string[], PersonContainer)> possiblyNewPersonDisplayDirectoryNamesAndPersonContainer) + private static void SetKeyValuePairs(Configuration configuration, ReadOnlyCollection personContainers, Dictionary> personKeyToPersonContainerCollection, Dictionary personKeyFormattedToPersonContainer, List<(string, string[], int, int)> personKeyFormattedIdThenWholePercentagesCollection, Dictionary personKeyToPersonContainer, Dictionary> idThenWholePercentagesToPersonContainers, List<(string[], PersonContainer)> possiblyNewPersonDisplayDirectoryNamesAndPersonContainer) { PersonBirthday? personBirthday; PersonContainer[] distinctPersonContainers; (long, PersonContainer)[] collection = GetDistinctCollection(configuration, personContainers, personKeyToPersonContainerCollection, personKeyFormattedToPersonContainer); foreach ((long personKey, PersonContainer personContainer) in collection) personKeyToPersonContainer.Add(personKey, personContainer); - Dictionary>> idThenNormalizedRectangleToPersonContainerCollection = new(); - if (personKeyFormattedIdThenNormalizedRectangleCollection.Any()) + Dictionary>> idThenWholePercentagesToPersonContainerCollection = new(); + if (personKeyFormattedIdThenWholePercentagesCollection.Any()) { string personDisplayDirectory; PersonContainer personContainer; string personDisplayDirectoryName; Dictionary personDisplayDirectoryTo = new(); - foreach ((string personKeyFormatted, string[] personDisplayDirectoryNames, int id, int normalizedRectangle) in personKeyFormattedIdThenNormalizedRectangleCollection) + foreach ((string personKeyFormatted, string[] personDisplayDirectoryNames, int id, int wholePercentages) in personKeyFormattedIdThenWholePercentagesCollection) { personBirthday = IPersonBirthday.GetPersonBirthday(configuration.PersonBirthdayFormat, personKeyFormatted); if (personBirthday is null) @@ -313,22 +313,22 @@ internal abstract class MapLogic } if (personDisplayDirectoryName.Length != 1 && personDisplayDirectoryName != configuration.MappingDefaultName && !personDisplayDirectoryTo.ContainsKey(personDisplayDirectory)) personDisplayDirectoryTo.Add(personDisplayDirectory, new(personDisplayDirectoryNames, personKeyFormattedToPersonContainer[personKeyFormatted])); - if (!idThenNormalizedRectangleToPersonContainerCollection.ContainsKey(id)) - idThenNormalizedRectangleToPersonContainerCollection.Add(id, new()); - if (!idThenNormalizedRectangleToPersonContainerCollection[id].ContainsKey(normalizedRectangle)) - idThenNormalizedRectangleToPersonContainerCollection[id].Add(normalizedRectangle, new()); - idThenNormalizedRectangleToPersonContainerCollection[id][normalizedRectangle].Add(personKeyFormattedToPersonContainer[personKeyFormatted]); + if (!idThenWholePercentagesToPersonContainerCollection.ContainsKey(id)) + idThenWholePercentagesToPersonContainerCollection.Add(id, new()); + if (!idThenWholePercentagesToPersonContainerCollection[id].ContainsKey(wholePercentages)) + idThenWholePercentagesToPersonContainerCollection[id].Add(wholePercentages, new()); + idThenWholePercentagesToPersonContainerCollection[id][wholePercentages].Add(personKeyFormattedToPersonContainer[personKeyFormatted]); } foreach (KeyValuePair keyValuePair in personDisplayDirectoryTo) possiblyNewPersonDisplayDirectoryNamesAndPersonContainer.Add(keyValuePair.Value); } - foreach (KeyValuePair>> keyValuePair in idThenNormalizedRectangleToPersonContainerCollection) + foreach (KeyValuePair>> keyValuePair in idThenWholePercentagesToPersonContainerCollection) { - idThenNormalizedRectangleToPersonContainers.Add(keyValuePair.Key, new()); + idThenWholePercentagesToPersonContainers.Add(keyValuePair.Key, new()); foreach (KeyValuePair> innerKeyValuePair in keyValuePair.Value) { distinctPersonContainers = GetDistinctPersonContainers(innerKeyValuePair.Value); - idThenNormalizedRectangleToPersonContainers[keyValuePair.Key].Add(innerKeyValuePair.Key, distinctPersonContainers); + idThenWholePercentagesToPersonContainers[keyValuePair.Key].Add(innerKeyValuePair.Key, distinctPersonContainers); } }; } @@ -363,15 +363,15 @@ internal abstract class MapLogic return results; } - private static int SetCollectionsAndGetUnableToConvertCount(Configuration configuration, long ticks, Dictionary personKeyFormattedToNewestPersonKeyFormatted, List<(string, string[], int, int)> personKeyFormattedIdThenNormalizedRectangleCollection, List<(string, string[], string)> collection) + private static int SetCollectionsAndGetUnableToConvertCount(Configuration configuration, long ticks, Dictionary personKeyFormattedToNewestPersonKeyFormatted, List<(string, string[], int, int)> personKeyFormattedIdThenWholePercentagesCollection, List<(string, string[], string)> collection) { int result = 0; int? id; - int? normalizedRectangle; - List normalizedRectangles; + int? wholePercentages; string? newestPersonKeyFormatted; string personDisplayDirectoryName; - Dictionary> idToNormalizedRectangles = new(); + List wholePercentagesCollection; + Dictionary> idToWholePercentagesCollection = new(); int totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds); string message = $") {collection.Count:000} join from ticks Director(ies) - C - {totalSeconds} total second(s)"; ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true }; @@ -385,21 +385,21 @@ internal abstract class MapLogic continue; newestPersonKeyFormatted = personKeyFormatted; } - (id, normalizedRectangle) = IMapping.GetConverted(configuration.FacesFileNameExtension, mappedFaceFile); - if (id is null || normalizedRectangle is null) + (id, wholePercentages) = IMapping.GetConverted(configuration.FacesFileNameExtension, mappedFaceFile); + if (id is null || wholePercentages is null) { result++; continue; } - if (!idToNormalizedRectangles.ContainsKey(id.Value)) - idToNormalizedRectangles.Add(id.Value, new()); - normalizedRectangles = idToNormalizedRectangles[id.Value]; - normalizedRectangles.Add(normalizedRectangle.Value); - idToNormalizedRectangles[id.Value].Add(normalizedRectangle.Value); + if (!idToWholePercentagesCollection.ContainsKey(id.Value)) + idToWholePercentagesCollection.Add(id.Value, new()); + wholePercentagesCollection = idToWholePercentagesCollection[id.Value]; + wholePercentagesCollection.Add(wholePercentages.Value); + idToWholePercentagesCollection[id.Value].Add(wholePercentages.Value); personDisplayDirectoryName = personDisplayDirectoryNames[^1]; if (string.IsNullOrEmpty(personDisplayDirectoryName)) continue; - personKeyFormattedIdThenNormalizedRectangleCollection.Add(new(newestPersonKeyFormatted, personDisplayDirectoryNames, id.Value, normalizedRectangle.Value)); + personKeyFormattedIdThenWholePercentagesCollection.Add(new(newestPersonKeyFormatted, personDisplayDirectoryNames, id.Value, wholePercentages.Value)); } return result; } @@ -610,22 +610,22 @@ internal abstract class MapLogic private static void ParallelFor(Configuration configuration, string eDistanceContentDirectory, List> collection, long personKey, string file) { const string lnk = ".lnk"; - int? id, normalizedRectangle; + int? id, wholePercentages; IReadOnlyList directories; bool fromDistanceContent = !file.EndsWith(lnk) && file.Contains(eDistanceContentDirectory); if (!file.EndsWith(lnk)) - (id, normalizedRectangle) = IMapping.GetConverted(configuration.FacesFileNameExtension, file); + (id, wholePercentages) = IMapping.GetConverted(configuration.FacesFileNameExtension, file); else - (id, normalizedRectangle) = IMapping.GetConverted(configuration.FacesFileNameExtension, file[..^4]); - if (id is null || normalizedRectangle is null) + (id, wholePercentages) = IMapping.GetConverted(configuration.FacesFileNameExtension, file[..^4]); + if (id is null || wholePercentages is null) return; if (file.EndsWith(lnk) || (!configuration.DistanceMoveUnableToMatch && !configuration.DistanceRenameToMatch)) directories = new List(); else directories = MetadataExtractor.ImageMetadataReader.ReadMetadata(file); - Rectangle? rectangle = ILocation.GetNormalizedRectangle(configuration.LocationDigits, normalizedRectangle.Value); + Rectangle? rectangle = ILocation.GetWholePercentages(configuration.LocationDigits, wholePercentages.Value); lock (collection) - collection.Add(new(fromDistanceContent, file, personKey, id.Value, normalizedRectangle.Value, directories, rectangle, null)); + collection.Add(new(fromDistanceContent, file, personKey, id.Value, wholePercentages.Value, directories, rectangle, null)); } private static void OpenPossibleDuplicates(Configuration configuration, List<(long, int, string, double?)> duplicates) @@ -661,7 +661,7 @@ internal abstract class MapLogic Rectangle? rectangle; List delete = new(); Rectangle intersectRectangle; - (string File, int NormalizedRectangle) item; + (string File, int WholePercentages) item; Dictionary distinct = new(); List<(long, int, string, double?)> duplicates = new(); foreach (LocationContainer locationContainer in collection) @@ -669,13 +669,13 @@ internal abstract class MapLogic key = string.Concat(locationContainer.PersonKey, locationContainer.Id); if (distinct.TryGetValue(key, out item)) { - if (item.NormalizedRectangle == locationContainer.NormalizedRectangle) + if (item.WholePercentages == locationContainer.WholePercentages) continue; if (locationContainer.Rectangle is null) percent = null; else { - rectangle = ILocation.GetNormalizedRectangle(configuration.LocationDigits, item.NormalizedRectangle); + rectangle = ILocation.GetWholePercentages(configuration.LocationDigits, item.WholePercentages); if (locationContainer.Rectangle is null || rectangle is null) percent = null; else @@ -689,7 +689,7 @@ internal abstract class MapLogic duplicates.Add(new(locationContainer.PersonKey, locationContainer.Id, locationContainer.File, percent)); continue; } - distinct.Add(key, new(locationContainer.File, locationContainer.NormalizedRectangle)); + distinct.Add(key, new(locationContainer.File, locationContainer.WholePercentages)); } if (!configuration.DeletePossibleDuplicates && duplicates.Any()) OpenPossibleDuplicates(configuration, duplicates); @@ -726,7 +726,7 @@ internal abstract class MapLogic return results; } - internal static void Set(int maxDegreeOfParallelism, Configuration configuration, long ticks, ReadOnlyCollection personContainers, string? a2PeopleSingletonDirectory, string eDistanceContentDirectory, Dictionary personKeyToPersonContainer, List notMappedPersonContainers, Dictionary> skipCollection, Dictionary> skipNotSkipCollection, List> locationContainers, Dictionary> idThenNormalizedRectangleToPersonContainers) + internal static void Set(int maxDegreeOfParallelism, Configuration configuration, long ticks, ReadOnlyCollection personContainers, string? a2PeopleSingletonDirectory, string eDistanceContentDirectory, Dictionary personKeyToPersonContainer, List notMappedPersonContainers, Dictionary> skipCollection, Dictionary> skipNotSkipCollection, List> locationContainers, Dictionary> idThenWholePercentagesToPersonContainers) { string message; int totalSeconds; @@ -736,7 +736,7 @@ internal abstract class MapLogic Dictionary personKeyFormattedToPersonContainer = new(); Dictionary> personKeyToPersonContainerCollection = new(); string[] ticksDirectories = UpdateDateVerifyAndGetTicksDirectories(eDistanceContentDirectory); - List<(string, string[], int, int)> personKeyFormattedIdThenNormalizedRectangleCollection = new(); + List<(string, string[], int, int)> personKeyFormattedIdThenWholePercentagesCollection = new(); List<(string[], PersonContainer)> possiblyNewPersonDisplayDirectoryNamesAndPersonContainer = new(); SetPersonCollections(configuration, personContainers, a2PeopleSingletonDirectory, personKeyFormattedToNewestPersonKeyFormatted, personKeyFormattedCollection, skipCollection, skipNotSkipCollection); // personContainers.AddRange(GetNonSpecificPeopleCollection(configuration, ticks, personKeys)); @@ -744,14 +744,14 @@ internal abstract class MapLogic message = $") {ticksDirectories.Length:000} compile from and clean ticks Director(ies) - B - {totalSeconds} total second(s)"; List<(string, string[], string)> collection = DeleteEmptyDirectoriesAndGetCollection(configuration, personKeyFormattedCollection, ticksDirectories, message); locationContainers.AddRange(GetLocationContainers(maxDegreeOfParallelism, configuration, ticks, personContainers, eDistanceContentDirectory, collection)); - int unableToMatchCount = SetCollectionsAndGetUnableToConvertCount(configuration, ticks, personKeyFormattedToNewestPersonKeyFormatted, personKeyFormattedIdThenNormalizedRectangleCollection, collection); - SetKeyValuePairs(configuration, personContainers, personKeyToPersonContainerCollection, personKeyFormattedToPersonContainer, personKeyFormattedIdThenNormalizedRectangleCollection, personKeyToPersonContainer, idThenNormalizedRectangleToPersonContainers, possiblyNewPersonDisplayDirectoryNamesAndPersonContainer); + int unableToMatchCount = SetCollectionsAndGetUnableToConvertCount(configuration, ticks, personKeyFormattedToNewestPersonKeyFormatted, personKeyFormattedIdThenWholePercentagesCollection, collection); + SetKeyValuePairs(configuration, personContainers, personKeyToPersonContainerCollection, personKeyFormattedToPersonContainer, personKeyFormattedIdThenWholePercentagesCollection, personKeyToPersonContainer, idThenWholePercentagesToPersonContainers, possiblyNewPersonDisplayDirectoryNamesAndPersonContainer); totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds); message = $") {collection.Count:000} message from ticks Director(ies) - D - {unableToMatchCount} Unable To Match Count / {collection.Count} Collection - {totalSeconds} total second(s)"; ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true }; using (ProgressBar progressBar = new(collection.Count, message, options)) { - foreach (KeyValuePair> keyValuePair in idThenNormalizedRectangleToPersonContainers) + foreach (KeyValuePair> keyValuePair in idThenWholePercentagesToPersonContainers) { progressBar.Tick(); foreach (KeyValuePair keyValue in keyValuePair.Value) @@ -841,7 +841,7 @@ internal abstract class MapLogic SaveContainer result; if (sortingContainer.Mapping.MappingFromLocation is null) throw new NullReferenceException(nameof(sortingContainer.Mapping.MappingFromLocation)); - FileHolder faceFileHolder = new($"C:/{sortingContainer.Sorting.Id}.{sortingContainer.Sorting.NormalizedRectangle}"); + FileHolder faceFileHolder = new($"C:/{sortingContainer.Sorting.Id}.{sortingContainer.Sorting.WholePercentages}"); string shortcutFile; if (mappingFromPerson is null) shortcutFile = Path.Combine(directory, $"{sortingContainer.Mapping.MappingFromLocation.DeterministicHashCodeKey}{sortingContainer.Mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}.{sortingContainer.Sorting.DistancePermyriad}.lnk"); @@ -1019,7 +1019,7 @@ internal abstract class MapLogic return results; } - internal static Dictionary> GetIdToNormalizedRectangleToFace(Mapping[] mappingCollection) + internal static Dictionary> GetIdToWholePercentagesToFace(Mapping[] mappingCollection) { Dictionary> results = new(); Dictionary? keyValuePairs; @@ -1033,9 +1033,9 @@ internal abstract class MapLogic if (!results.TryGetValue(mapping.MappingFromItem.Id, out keyValuePairs)) throw new Exception(); } - if (keyValuePairs.ContainsKey(mapping.MappingFromLocation.NormalizedRectangle)) + if (keyValuePairs.ContainsKey(mapping.MappingFromLocation.WholePercentages)) continue; - keyValuePairs.Add(mapping.MappingFromLocation.NormalizedRectangle, mapping); + keyValuePairs.Add(mapping.MappingFromLocation.WholePercentages, mapping); } return results; } diff --git a/Map/Models/Stateless/Methods/IMapLogic.cs b/Map/Models/Stateless/Methods/IMapLogic.cs index 84f322b..9aee655 100644 --- a/Map/Models/Stateless/Methods/IMapLogic.cs +++ b/Map/Models/Stateless/Methods/IMapLogic.cs @@ -23,9 +23,9 @@ public interface IMapLogic static Shared.Models.Mapping[] GetSelectedMappingCollection(List faces) => MapLogic.GetSelectedMappingCollection(faces); - Dictionary> TestStatic_GetIdToNormalizedRectangleToFace(Shared.Models.Mapping[] mappingCollection) => - GetIdToNormalizedRectangleToFace(mappingCollection); - static Dictionary> GetIdToNormalizedRectangleToFace(Shared.Models.Mapping[] mappingCollection) => - MapLogic.GetIdToNormalizedRectangleToFace(mappingCollection); + Dictionary> TestStatic_GetIdToWholePercentagesToFace(Shared.Models.Mapping[] mappingCollection) => + GetIdToWholePercentagesToFace(mappingCollection); + static Dictionary> GetIdToWholePercentagesToFace(Shared.Models.Mapping[] mappingCollection) => + MapLogic.GetIdToWholePercentagesToFace(mappingCollection); } \ No newline at end of file diff --git a/PhotoPrism/Models/_F_PhotoPrism.cs b/PhotoPrism/Models/_F_PhotoPrism.cs index e5d3511..6a6c730 100644 --- a/PhotoPrism/Models/_F_PhotoPrism.cs +++ b/PhotoPrism/Models/_F_PhotoPrism.cs @@ -174,7 +174,7 @@ public class F_PhotoPrism string file; string text; double percent; - int? normalizedRectangle; + int? wholePercentages; List subjects = new(); PersonContainer[]? personContainers; StringBuilder stringBuilder = new(); @@ -182,21 +182,21 @@ public class F_PhotoPrism System.Drawing.Rectangle? prismRectangle; System.Drawing.Rectangle intersectRectangle; float rectangleIntersectMinimum = rectangleIntersectMinimums.Min(); - Dictionary? normalizedRectangleToPersonContainers; + Dictionary? wholePercentagesToPersonContainers; (MappingFromPhotoPrism MappingFromPhotoPrism, Shared.Models.Marker Marker, double Percent)[] sortedCollection; List<(MappingFromPhotoPrism MappingFromPhotoPrism, Shared.Models.Marker Marker, double Percent)> collection = new(); foreach (Face face in distinctFilteredFaces) { collection.Clear(); - normalizedRectangle = face.Mapping?.MappingFromLocation?.NormalizedRectangle; - if (normalizedRectangle is null) + wholePercentages = face.Mapping?.MappingFromLocation?.WholePercentages; + if (wholePercentages is null) continue; if (face.FaceEncoding is null || face.Location is null || face.OutputResolution is null || face.Mapping is null) continue; if (face.Mapping.MappingFromPhotoPrismCollection is null) continue; - (_, normalizedRectangleToPersonContainers) = mapLogic.GetNormalizedRectangleToPersonContainers(face.Mapping.MappingFromItem.Id); - if (normalizedRectangleToPersonContainers is null || !normalizedRectangleToPersonContainers.TryGetValue(normalizedRectangle.Value, out personContainers)) + (_, wholePercentagesToPersonContainers) = mapLogic.GetWholePercentagesToPersonContainers(face.Mapping.MappingFromItem.Id); + if (wholePercentagesToPersonContainers is null || !wholePercentagesToPersonContainers.TryGetValue(wholePercentages.Value, out personContainers)) continue; dlibRectangle = new(face.Location.Left, face.Location.Top, face.Location.Right - face.Location.Left, face.Location.Bottom - face.Location.Top); foreach (MappingFromPhotoPrism mappingFromPhotoPrism in face.Mapping.MappingFromPhotoPrismCollection) diff --git a/Shared/Models/FaceDistance.cs b/Shared/Models/FaceDistance.cs index ea4c194..1752103 100644 --- a/Shared/Models/FaceDistance.cs +++ b/Shared/Models/FaceDistance.cs @@ -12,10 +12,10 @@ public record class FaceDistance : Properties.IFaceDistance public int Id { init; get; } public bool? IsWrongYear { init; get; } public double? Length { init; get; } - public int? NormalizedRectangle { init; get; } + public int? WholePercentages { init; get; } [JsonConstructor] - public FaceDistance(int? confidencePercent, DateTime dateTimeOriginalThenMinimumDateTime, object? encoding, int id, bool? isWrongYear, double? length, int? normalizedRectangle) + public FaceDistance(int? confidencePercent, DateTime dateTimeOriginalThenMinimumDateTime, object? encoding, int id, bool? isWrongYear, double? length, int? wholePercentages) { ConfidencePercent = confidencePercent; DateTimeOriginalThenMinimumDateTime = dateTimeOriginalThenMinimumDateTime; @@ -23,15 +23,15 @@ public record class FaceDistance : Properties.IFaceDistance Id = id; IsWrongYear = isWrongYear; Length = length; - NormalizedRectangle = normalizedRectangle; + WholePercentages = wholePercentages; } - public FaceDistance(int? confidencePercent, DateTime dateTimeOriginalThenMinimumDateTime, object? encoding, int id, bool? isWrongYear, int? normalizedRectangle) : - this(confidencePercent, dateTimeOriginalThenMinimumDateTime, encoding, id, isWrongYear, null, normalizedRectangle) + public FaceDistance(int? confidencePercent, DateTime dateTimeOriginalThenMinimumDateTime, object? encoding, int id, bool? isWrongYear, int? wholePercentages) : + this(confidencePercent, dateTimeOriginalThenMinimumDateTime, encoding, id, isWrongYear, null, wholePercentages) { } public FaceDistance(FaceDistance faceDistance, double length) : - this(faceDistance.ConfidencePercent, faceDistance.DateTimeOriginalThenMinimumDateTime, null, faceDistance.Id, faceDistance.IsWrongYear, length, faceDistance.NormalizedRectangle) + this(faceDistance.ConfidencePercent, faceDistance.DateTimeOriginalThenMinimumDateTime, null, faceDistance.Id, faceDistance.IsWrongYear, length, faceDistance.WholePercentages) { } public FaceDistance(object encoding) => Encoding = encoding; diff --git a/Shared/Models/LocationContainer.cs b/Shared/Models/LocationContainer.cs index b3d92be..c0e3c09 100644 --- a/Shared/Models/LocationContainer.cs +++ b/Shared/Models/LocationContainer.cs @@ -2,5 +2,5 @@ using System.Drawing; namespace View_by_Distance.Shared.Models; -public record LocationContainer(bool FromDistanceContent, string File, long PersonKey, int Id, int NormalizedRectangle, IReadOnlyList Directories, Rectangle? Rectangle, Location? Location) +public record LocationContainer(bool FromDistanceContent, string File, long PersonKey, int Id, int WholePercentages, IReadOnlyList Directories, Rectangle? Rectangle, Location? Location) { } \ No newline at end of file diff --git a/Shared/Models/MappingFromLocation.cs b/Shared/Models/MappingFromLocation.cs index 485801f..ea65b53 100644 --- a/Shared/Models/MappingFromLocation.cs +++ b/Shared/Models/MappingFromLocation.cs @@ -9,15 +9,15 @@ public class MappingFromLocation : Properties.IMappingFromLocation public int AreaPermyriad { init; get; } public int ConfidencePercent { init; get; } public string DeterministicHashCodeKey { init; get; } - public int NormalizedRectangle { init; get; } + public int WholePercentages { init; get; } [JsonConstructor] - public MappingFromLocation(int areaPermyriad, int confidencePercent, string deterministicHashCodeKey, int normalizedRectangle) + public MappingFromLocation(int areaPermyriad, int confidencePercent, string deterministicHashCodeKey, int wholePercentages) { AreaPermyriad = areaPermyriad; ConfidencePercent = confidencePercent; DeterministicHashCodeKey = deterministicHashCodeKey; - NormalizedRectangle = normalizedRectangle; + WholePercentages = wholePercentages; } public override string ToString() diff --git a/Shared/Models/Methods/IMapLogic.cs b/Shared/Models/Methods/IMapLogic.cs index 80603cb..93a33a2 100644 --- a/Shared/Models/Methods/IMapLogic.cs +++ b/Shared/Models/Methods/IMapLogic.cs @@ -3,6 +3,6 @@ namespace View_by_Distance.Shared.Models.Methods; public interface IMapLogic { - (bool, Dictionary?) GetNormalizedRectangleToPersonContainers(int id); + (bool, Dictionary?) GetWholePercentagesToPersonContainers(int id); } \ No newline at end of file diff --git a/Shared/Models/Properties/IFaceDistance.cs b/Shared/Models/Properties/IFaceDistance.cs index 4d2b511..1cd9b87 100644 --- a/Shared/Models/Properties/IFaceDistance.cs +++ b/Shared/Models/Properties/IFaceDistance.cs @@ -9,6 +9,6 @@ public interface IFaceDistance public int Id { init; get; } public bool? IsWrongYear { init; get; } public double? Length { init; get; } - public int? NormalizedRectangle { init; get; } + public int? WholePercentages { init; get; } } \ No newline at end of file diff --git a/Shared/Models/Properties/IMappingFromLocation.cs b/Shared/Models/Properties/IMappingFromLocation.cs index a192a6d..f86df94 100644 --- a/Shared/Models/Properties/IMappingFromLocation.cs +++ b/Shared/Models/Properties/IMappingFromLocation.cs @@ -6,6 +6,6 @@ public interface IMappingFromLocation public int AreaPermyriad { init; get; } public int ConfidencePercent { init; get; } public string DeterministicHashCodeKey { init; get; } - public int NormalizedRectangle { init; get; } + public int WholePercentages { init; get; } } diff --git a/Shared/Models/Properties/ISorting.cs b/Shared/Models/Properties/ISorting.cs index b15d408..c685e91 100644 --- a/Shared/Models/Properties/ISorting.cs +++ b/Shared/Models/Properties/ISorting.cs @@ -6,6 +6,7 @@ public interface ISorting public int DaysDelta { init; get; } public int DistancePermyriad { init; get; } public int Id { init; get; } - public int NormalizedRectangle { init; get; } + public bool Older { init; get; } + public int WholePercentages { init; get; } } \ No newline at end of file diff --git a/Shared/Models/Sorting.cs b/Shared/Models/Sorting.cs index eb9e14c..2e64359 100644 --- a/Shared/Models/Sorting.cs +++ b/Shared/Models/Sorting.cs @@ -9,21 +9,21 @@ public record class Sorting : Properties.ISorting public int DaysDelta { init; get; } public int DistancePermyriad { init; get; } public int Id { init; get; } - public int NormalizedRectangle { init; get; } public bool Older { init; get; } + public int WholePercentages { init; get; } [JsonConstructor] - public Sorting(int daysDelta, int distancePermyriad, int id, int normalizedRectangle, bool older) + public Sorting(int daysDelta, int distancePermyriad, int id, bool older, int wholePercentages) { DaysDelta = daysDelta; DistancePermyriad = distancePermyriad; Id = id; - NormalizedRectangle = normalizedRectangle; + WholePercentages = wholePercentages; Older = older; } public Sorting(Mapping mapping, MappingFromLocation mappingFromLocation) : - this(0, 0, mapping.MappingFromItem.Id, mappingFromLocation.NormalizedRectangle, false) + this(0, 0, mapping.MappingFromItem.Id, false, mappingFromLocation.WholePercentages) { } public override string ToString() diff --git a/Shared/Models/SortingContainer.cs b/Shared/Models/SortingContainer.cs index e73687f..44629b2 100644 --- a/Shared/Models/SortingContainer.cs +++ b/Shared/Models/SortingContainer.cs @@ -17,7 +17,7 @@ public record class SortingContainer : Properties.ISortingContainer public override string ToString() { - string result = string.Concat(Mapping.MappingFromItem.Id, '\t', Mapping.MappingFromLocation?.NormalizedRectangle, '\t', Sorting.Id, '\t', Sorting.NormalizedRectangle, '\t', Sorting.Older, '\t', '\t', Sorting.DistancePermyriad, '\t', Sorting.DaysDelta); + string result = string.Concat(Mapping.MappingFromItem.Id, '\t', Mapping.MappingFromLocation?.WholePercentages, '\t', Sorting.Id, '\t', Sorting.WholePercentages, '\t', Sorting.Older, '\t', '\t', Sorting.DistancePermyriad, '\t', Sorting.DaysDelta); return result; } diff --git a/Shared/Models/Stateless/Methods/ILocation.cs b/Shared/Models/Stateless/Methods/ILocation.cs index 4fbe6bf..0a79980 100644 --- a/Shared/Models/Stateless/Methods/ILocation.cs +++ b/Shared/Models/Stateless/Methods/ILocation.cs @@ -10,10 +10,10 @@ public interface ILocation static Models.Location? GetLocation(int height, Rectangle rectangle, int width) => Location.GetLocation(height, rectangle, width); - List TestStatic_FilterByIntersect(Models.Face[] faces, int normalizedRectangle, float rectangleIntersectMinimum) => - FilterByIntersect(faces, normalizedRectangle, rectangleIntersectMinimum); - static List FilterByIntersect(Models.Face[] faces, int normalizedRectangle, float rectangleIntersectMinimum) => - Location.FilterByIntersect(faces, normalizedRectangle, rectangleIntersectMinimum); + List TestStatic_FilterByIntersect(Models.Face[] faces, float rectangleIntersectMinimum, int wholePercentages) => + FilterByIntersect(faces, rectangleIntersectMinimum, wholePercentages); + static List FilterByIntersect(Models.Face[] faces, float rectangleIntersectMinimum, int wholePercentages) => + Location.FilterByIntersect(faces, rectangleIntersectMinimum, wholePercentages); Rectangle? TestStatic_GetRectangle(DatabaseFile databaseFile, Marker marker, Models.OutputResolution outputResolution) => GetRectangle(databaseFile, marker, outputResolution); @@ -30,15 +30,15 @@ public interface ILocation static List GetLocations(List mappingFromPhotoPrismCollection, List faces, List> containers) => Location.GetLocations(mappingFromPhotoPrismCollection, faces, containers); - Rectangle? TestStatic_GetNormalizedRectangle(int locationDigits, int normalizedRectangle) => - GetNormalizedRectangle(locationDigits, normalizedRectangle); - static Rectangle? GetNormalizedRectangle(int locationDigits, int normalizedRectangle) => - Location.GetNormalizedRectangle(locationDigits, normalizedRectangle.ToString()); + Rectangle? TestStatic_GetWholePercentages(int locationDigits, int wholePercentages) => + GetWholePercentages(locationDigits, wholePercentages); + static Rectangle? GetWholePercentages(int locationDigits, int wholePercentages) => + Location.GetWholePercentages(locationDigits, wholePercentages.ToString()); - Rectangle? TestStatic_GetRectangle(int locationDigits, int normalizedRectangle, Models.OutputResolution outputResolution) => - GetRectangle(locationDigits, normalizedRectangle, outputResolution); - static Rectangle? GetRectangle(int locationDigits, int normalizedRectangle, Models.OutputResolution outputResolution) => - Location.GetRectangle(locationDigits, normalizedRectangle.ToString(), outputResolution); + Rectangle? TestStatic_GetRectangle(int locationDigits, Models.OutputResolution outputResolution, int wholePercentages) => + GetRectangle(locationDigits, outputResolution, wholePercentages); + static Rectangle? GetRectangle(int locationDigits, Models.OutputResolution outputResolution, int wholePercentages) => + Location.GetRectangle(locationDigits, outputResolution, wholePercentages.ToString()); string TestStatic_GetLeftPadded(int locationDigits, string value) => GetLeftPadded(locationDigits, value); @@ -80,20 +80,20 @@ public interface ILocation static (decimal?, decimal?, decimal?, decimal?) GetHeightLeftTopWidth(Models.Location location, Models.OutputResolution outputResolution) => Location.GetHeightLeftTopWidth(location.Bottom, OutputResolution.Get(outputResolution).Height, location.Left, location.Right, location.Top, OutputResolution.Get(outputResolution).Width, zCount: 1); - int TestStatic_GetNormalizedRectangle(Models.Location location, int locationDigits, Models.OutputResolution outputResolution) => - GetNormalizedRectangle(location, locationDigits, outputResolution); - static int GetNormalizedRectangle(Models.Location location, int locationDigits, Models.OutputResolution outputResolution) => - Location.GetNormalizedRectangle(location.Bottom, OutputResolution.Get(outputResolution).Height, location.Left, locationDigits, location.Right, location.Top, OutputResolution.Get(outputResolution).Width, zCount: 1); + int TestStatic_GetWholePercentages(Models.Location location, int locationDigits, Models.OutputResolution outputResolution) => + GetWholePercentages(location, locationDigits, outputResolution); + static int GetWholePercentages(Models.Location location, int locationDigits, Models.OutputResolution outputResolution) => + Location.GetWholePercentages(location.Bottom, OutputResolution.Get(outputResolution).Height, location.Left, locationDigits, location.Right, location.Top, OutputResolution.Get(outputResolution).Width, zCount: 1); - int TestStatic_GetNormalizedRectangle(int locationDigits) => - GetNormalizedRectangle(locationDigits); - static int GetNormalizedRectangle(int locationDigits) => - Location.GetNormalizedRectangle(1, 1, 0, locationDigits, 1, 0, 1, zCount: 1); + int TestStatic_GetWholePercentages(int locationDigits) => + GetWholePercentages(locationDigits); + static int GetWholePercentages(int locationDigits) => + Location.GetWholePercentages(1, 1, 0, locationDigits, 1, 0, 1, zCount: 1); - int TestStatic_GetNormalizedRectangle(int bottom, int height, int left, int locationDigits, int right, int top, int width) => - GetNormalizedRectangle(bottom, height, left, locationDigits, right, top, width); - static int GetNormalizedRectangle(int bottom, int height, int left, int locationDigits, int right, int top, int width) => - Location.GetNormalizedRectangle(bottom, height, left, locationDigits, right, top, width, zCount: 1); + int TestStatic_GetWholePercentages(int bottom, int height, int left, int locationDigits, int right, int top, int width) => + GetWholePercentages(bottom, height, left, locationDigits, right, top, width); + static int GetWholePercentages(int bottom, int height, int left, int locationDigits, int right, int top, int width) => + Location.GetWholePercentages(bottom, height, left, locationDigits, right, top, width, zCount: 1); Models.Location TestStatic_GetTrimBound(double detectionConfidence, Rectangle rectangle, int width, int height, int facesCount) => TrimBound(detectionConfidence, rectangle, width, height, facesCount); diff --git a/Shared/Models/Stateless/Methods/IMapping.cs b/Shared/Models/Stateless/Methods/IMapping.cs index e988ffd..9e366ff 100644 --- a/Shared/Models/Stateless/Methods/IMapping.cs +++ b/Shared/Models/Stateless/Methods/IMapping.cs @@ -26,12 +26,12 @@ public interface IMapping string TestStatic_GetDeterministicHashCodeKey(int id, Models.Location location, int locationDigits, Models.OutputResolution outputResolution) => GetDeterministicHashCodeKey(id, location, locationDigits, outputResolution); static string GetDeterministicHashCodeKey(int id, Models.Location location, int locationDigits, Models.OutputResolution outputResolution) - => $"{id}.{ILocation.GetLeftPadded(locationDigits, ILocation.GetNormalizedRectangle(location, locationDigits, outputResolution))}"; + => $"{id}.{ILocation.GetLeftPadded(locationDigits, ILocation.GetWholePercentages(location, locationDigits, outputResolution))}"; string TestStatic_GetDeterministicHashCodeKey(int id, int locationDigits) => GetDeterministicHashCodeKey(id, locationDigits); static string GetDeterministicHashCodeKey(int id, int locationDigits) - => $"{id}.{ILocation.GetLeftPadded(locationDigits, ILocation.GetNormalizedRectangle(locationDigits))}"; + => $"{id}.{ILocation.GetLeftPadded(locationDigits, ILocation.GetWholePercentages(locationDigits))}"; (int?, int?) TestStatic_GetConverted(string facesFileNameExtension, string file) => GetConverted(facesFileNameExtension, file); diff --git a/Shared/Models/Stateless/Methods/Location.cs b/Shared/Models/Stateless/Methods/Location.cs index ae5c3dd..828d1d7 100644 --- a/Shared/Models/Stateless/Methods/Location.cs +++ b/Shared/Models/Stateless/Methods/Location.cs @@ -78,7 +78,7 @@ internal abstract class Location return result; } - internal static int GetNormalizedRectangle(int bottom, int height, int left, int locationDigits, int right, int top, int width, int zCount) + internal static int GetWholePercentages(int bottom, int height, int left, int locationDigits, int right, int top, int width, int zCount) { int result; string check; @@ -114,34 +114,37 @@ internal abstract class Location return result; } - internal static Rectangle? GetNormalizedRectangle(int locationDigits, string normalizedRectangle) + internal static Rectangle? GetWholePercentages(int locationDigits, string wholePercentages) { Rectangle? result; int length = (locationDigits - 1) / 4; string[] segments = new string[] { - normalizedRectangle[..1], - normalizedRectangle.Substring(1, length), - normalizedRectangle.Substring(3, length), - normalizedRectangle.Substring(5, length), - normalizedRectangle.Substring(7, length) + wholePercentages[..1], + wholePercentages.Substring(1, length), + wholePercentages.Substring(3, length), + wholePercentages.Substring(5, length), + wholePercentages.Substring(7, length) }; - if (string.Join(string.Empty, segments) != normalizedRectangle) + if (string.Join(string.Empty, segments) != wholePercentages) result = null; else { - if (!int.TryParse(segments[1], out int xNormalized) || !int.TryParse(segments[2], out int yNormalized) || !int.TryParse(segments[3], out int wNormalized) || !int.TryParse(segments[4], out int hNormalized)) + if (!int.TryParse(segments[1], out int xWholePercent) || !int.TryParse(segments[2], out int yWholePercent) || !int.TryParse(segments[3], out int wWholePercent) || !int.TryParse(segments[4], out int hWholePercent)) result = null; else - result = new(xNormalized, yNormalized, wNormalized, hNormalized); + result = new(xWholePercent, yWholePercent, wWholePercent, hWholePercent); } return result; } - internal static Rectangle? GetRectangle(int height, int locationDigits, string normalizedRectangle, int width) + internal static Rectangle? GetRectangle(int locationDigits, Models.OutputResolution outputResolution, string wholePercentages) { Rectangle? result; - Rectangle? rectangle = GetNormalizedRectangle(locationDigits, normalizedRectangle); + if (wholePercentages.Length != locationDigits || wholePercentages[0] is not '4' and not '8') + throw new NotSupportedException("Old way has been removed!"); + (int width, int height) = OutputResolution.Get(outputResolution); + Rectangle? rectangle = GetWholePercentages(locationDigits, wholePercentages); if (rectangle is null) result = null; else @@ -149,16 +152,6 @@ internal abstract class Location decimal factor = 100; result = new((int)(rectangle.Value.X / factor * width), (int)(rectangle.Value.Y / factor * height), (int)(rectangle.Value.Width / factor * width), (int)(rectangle.Value.Height / factor * height)); } - return result; - } - - internal static Rectangle? GetRectangle(int locationDigits, string normalizedRectangle, Models.OutputResolution outputResolution) - { - Rectangle? result; - if (normalizedRectangle.Length != locationDigits || normalizedRectangle[0] is not '4' and not '8') - throw new NotSupportedException("Old way has been removed!"); - (int width, int height) = OutputResolution.Get(outputResolution); - result = GetRectangle(height, locationDigits, normalizedRectangle, width); if (result is null) throw new NullReferenceException(nameof(result)); return result; @@ -290,7 +283,12 @@ internal abstract class Location return results; } - internal static List FilterByIntersect(Models.Face[] faces, int normalizedRectangle, float rectangleIntersectMinimum) + // private static double GP(OutputResolution outputResolution,Location location, ){ + // double result; + // return result; + // } + + internal static List FilterByIntersect(Models.Face[] faces, float rectangleIntersectMinimum, int wholePercentages) { List results = new(); double? percent; @@ -302,7 +300,7 @@ internal abstract class Location if (face.Location is null || face.OutputResolution is null) continue; checkRectangle = new(face.Location.Left, face.Location.Top, face.Location.Right - face.Location.Left, face.Location.Bottom - face.Location.Top); - sourceRectangle = GetRectangle(Stateless.ILocation.Digits, normalizedRectangle.ToString(), face.OutputResolution); + sourceRectangle = GetRectangle(Stateless.ILocation.Digits, face.OutputResolution, wholePercentages.ToString()); if (sourceRectangle is null) continue; intersectRectangle = Rectangle.Intersect(checkRectangle, sourceRectangle.Value); diff --git a/Shared/Models/Stateless/Methods/Mapping.cs b/Shared/Models/Stateless/Methods/Mapping.cs index 82ea00e..0164da9 100644 --- a/Shared/Models/Stateless/Methods/Mapping.cs +++ b/Shared/Models/Stateless/Methods/Mapping.cs @@ -8,61 +8,61 @@ internal abstract class Mapping string[] segments = fileName.Split('.'); string? id; string? extensionLowered; + string? wholePercentages; bool? needsFacesFileNameExtension; - string? normalizedRectangle; if (segments.Length < 4 || $".{segments[3]}" != facesFileNameExtension) { id = null; extensionLowered = null; - normalizedRectangle = null; + wholePercentages = null; needsFacesFileNameExtension = null; } else { id = segments[0]; extensionLowered = $".{segments[2]}"; - normalizedRectangle = segments[1]; + wholePercentages = segments[1]; needsFacesFileNameExtension = segments.Length == 3; } - return new(id, normalizedRectangle, extensionLowered, needsFacesFileNameExtension); + return new(id, wholePercentages, extensionLowered, needsFacesFileNameExtension); } private static (int?, int?) GetConvertedFromSegments(string facesFileNameExtension, string fileName) { int? id; - int? normalizedRectangle; - (string? Id, string? NormalizedRectangle, string? ExtensionLowered, bool? Check) segments = GetSegments(facesFileNameExtension, fileName); - if (string.IsNullOrEmpty(segments.Id) || string.IsNullOrEmpty(segments.NormalizedRectangle) || string.IsNullOrEmpty(segments.ExtensionLowered) || segments.Check is null) + int? wholePercentages; + (string? Id, string? WholePercentages, string? ExtensionLowered, bool? Check) segments = GetSegments(facesFileNameExtension, fileName); + if (string.IsNullOrEmpty(segments.Id) || string.IsNullOrEmpty(segments.WholePercentages) || string.IsNullOrEmpty(segments.ExtensionLowered) || segments.Check is null) { id = null; - normalizedRectangle = null; + wholePercentages = null; } - else if (!int.TryParse(segments.Id, out int idValue) || !int.TryParse(segments.NormalizedRectangle, out int normalizedRectangleValue)) + else if (!int.TryParse(segments.Id, out int idValue) || !int.TryParse(segments.WholePercentages, out int wholePercentagesValue)) { id = null; - normalizedRectangle = null; + wholePercentages = null; } else { id = idValue; - normalizedRectangle = normalizedRectangleValue; + wholePercentages = wholePercentagesValue; } - return new(id, normalizedRectangle); + return new(id, wholePercentages); } internal static (int?, int?) GetConverted(string facesFileNameExtension, string file) { int? id; - int? normalizedRectangle; + int? wholePercentages; string fileName = Path.GetFileName(file); if (fileName.Length >= 2 && !fileName[1..].Contains('-')) - (id, normalizedRectangle) = GetConvertedFromSegments(facesFileNameExtension, fileName); + (id, wholePercentages) = GetConvertedFromSegments(facesFileNameExtension, fileName); else { id = null; - normalizedRectangle = null; + wholePercentages = null; } - return new(id, normalizedRectangle); + return new(id, wholePercentages); } internal static int GetAreaPermyriad(int faceAreaPermyriad, int bottom, int height, int left, int right, int top, int width) diff --git a/Shared/Models/Stateless/Methods/PersonContainer.cs b/Shared/Models/Stateless/Methods/PersonContainer.cs index 886a83c..268cfba 100644 --- a/Shared/Models/Stateless/Methods/PersonContainer.cs +++ b/Shared/Models/Stateless/Methods/PersonContainer.cs @@ -64,15 +64,15 @@ internal abstract class PersonContainer string[] results; int? id; string checkFile; + int? wholePercentages; string? checkDirectory; - int? normalizedRectangle; string[] files = Directory.GetFiles(personDisplayDirectory, "*", SearchOption.TopDirectoryOnly); foreach (string file in files) { if (file.EndsWith(".lnk")) continue; - (id, normalizedRectangle) = IMapping.GetConverted(facesFileNameExtension, file); - if (id is not null && normalizedRectangle is not null) + (id, wholePercentages) = IMapping.GetConverted(facesFileNameExtension, file); + if (id is not null && wholePercentages is not null) continue; checkDirectory = Path.GetDirectoryName(file); if (string.IsNullOrEmpty(checkDirectory)) diff --git a/Shared/Models/Stateless/Methods/Sorting.cs b/Shared/Models/Stateless/Methods/Sorting.cs index 99f4368..6508bc7 100644 --- a/Shared/Models/Stateless/Methods/Sorting.cs +++ b/Shared/Models/Stateless/Methods/Sorting.cs @@ -8,13 +8,13 @@ internal abstract class Sorting Models.Sorting result; if (faceDistanceLength.Length is null) throw new NotSupportedException(); - if (faceDistanceLength.NormalizedRectangle is null) + if (faceDistanceLength.WholePercentages is null) throw new NotSupportedException(); TimeSpan timeSpan = new(faceDistanceLength.DateTimeOriginalThenMinimumDateTime.Ticks - faceDistanceEncoding.DateTimeOriginalThenMinimumDateTime.Ticks); bool older = timeSpan.TotalMilliseconds < 0; int daysDelta = (int)Math.Round(Math.Abs(timeSpan.TotalDays), 0); int distancePermyriad = (int)(faceDistanceLength.Length.Value / rangeDistanceTolerance * faceDistancePermyriad); - result = new(daysDelta, distancePermyriad, faceDistanceLength.Id, faceDistanceLength.NormalizedRectangle.Value, older); + result = new(daysDelta, distancePermyriad, faceDistanceLength.Id, older, faceDistanceLength.WholePercentages.Value); return result; }