Get Segments

This commit is contained in:
Mike Phares 2022-09-20 20:24:03 -07:00
parent b24d3b9c8d
commit 90244811ed
7 changed files with 60 additions and 54 deletions

View File

@ -115,13 +115,14 @@ public class MapLogic
private List<(long, long, long, long)> GetPersonKeysRangesCollection(PersonContainer[] personContainers)
{
List<(long, long, long, long)> results = new();
(long, long, long, long) singleton;
foreach (PersonContainer personContainer in personContainers)
{
if (personContainer.Key is null)
continue;
if (!_PersonKeyToRanges.ContainsKey(personContainer.Key.Value))
if (!_PersonKeyToRanges.TryGetValue(personContainer.Key.Value, out singleton))
continue;
results.Add(_PersonKeyToRanges[personContainer.Key.Value]);
results.Add(singleton);
}
return results;
}
@ -133,7 +134,8 @@ public class MapLogic
List<Sorting> results = new();
Sorting sorting;
FaceDistance faceDistanceLength;
Dictionary<int, PersonContainer[]> keyValuePairs;
List<int>? normalizedPixelPercentages;
Dictionary<int, PersonContainer[]>? keyValuePairs;
List<(long lcl, long minimum, long maximum, long ucl)> personKeysRangesCollection;
for (int j = 0; j < faceDistanceLengths.Count; j++)
{
@ -144,20 +146,18 @@ public class MapLogic
throw new NotSupportedException();
if (faceDistanceLength.Length == 0)
continue;
if (_SkipCollection.ContainsKey(faceDistanceEncoding.Id))
if (_SkipCollection.TryGetValue(faceDistanceEncoding.Id, out normalizedPixelPercentages))
{
if (_SkipCollection[faceDistanceEncoding.Id].Contains(faceDistanceEncoding.NormalizedPixelPercentage.Value))
if (normalizedPixelPercentages.Contains(faceDistanceEncoding.NormalizedPixelPercentage.Value))
continue;
}
if (_IdThenNormalizedPixelPercentageToPersonContainers.ContainsKey(faceDistanceEncoding.Id))
if (_IdThenNormalizedPixelPercentageToPersonContainers.TryGetValue(faceDistanceEncoding.Id, out keyValuePairs))
{
keyValuePairs = _IdThenNormalizedPixelPercentageToPersonContainers[faceDistanceEncoding.Id];
if (keyValuePairs.ContainsKey(faceDistanceEncoding.NormalizedPixelPercentage.Value))
continue;
}
if (!_IdThenNormalizedPixelPercentageToPersonContainers.ContainsKey(faceDistanceLength.Id))
if (!_IdThenNormalizedPixelPercentageToPersonContainers.TryGetValue(faceDistanceLength.Id, out keyValuePairs))
continue;
keyValuePairs = _IdThenNormalizedPixelPercentageToPersonContainers[faceDistanceLength.Id];
if (!keyValuePairs.ContainsKey(faceDistanceLength.NormalizedPixelPercentage.Value))
continue;
personKeysRangesCollection = GetPersonKeysRangesCollection(keyValuePairs[faceDistanceLength.NormalizedPixelPercentage.Value]);
@ -183,8 +183,8 @@ public class MapLogic
string fullName;
string personKeyFormatted;
PersonBirthday personBirthday;
PersonContainer personContainer;
WindowsShortcut windowsShortcut;
PersonContainer? personContainer;
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)
{
@ -205,9 +205,8 @@ public class MapLogic
if (!Directory.Exists(directory))
{
_ = Directory.CreateDirectory(directory);
if (personKey is not null && _PersonKeyToPersonContainer.ContainsKey(personKey.Value))
if (personKey is not null && _PersonKeyToPersonContainer.TryGetValue(personKey.Value, out personContainer))
{
personContainer = _PersonKeyToPersonContainer[personKey.Value];
fullName = string.Concat(personContainer.DisplayDirectoryName, ".txt");
File.WriteAllText(Path.Combine(directory, fullName), string.Empty);
}
@ -270,23 +269,23 @@ public class MapLogic
const int zero = 0;
string mappingSegmentB;
PersonBirthday personBirthday;
PersonContainer[]? collection;
int by = Stateless.IMapLogic.Mapping;
List<PersonContainer> personContainers = new();
Dictionary<int, PersonContainer[]> keyValuePairs;
Dictionary<int, PersonContainer[]>? keyValuePairs;
foreach (Face face in distinctFilteredFaces)
{
personContainers.Clear();
if (face.Mapping is null)
throw new NotSupportedException();
if (!_IdThenNormalizedPixelPercentageToPersonContainers.ContainsKey(face.Mapping.MappingFromItem.Id))
if (!_IdThenNormalizedPixelPercentageToPersonContainers.TryGetValue(face.Mapping.MappingFromItem.Id, out keyValuePairs))
result += 1;
else
{
keyValuePairs = _IdThenNormalizedPixelPercentageToPersonContainers[face.Mapping.MappingFromItem.Id];
if (!keyValuePairs.ContainsKey(face.Mapping.MappingFromLocation.NormalizedPixelPercentage))
if (!keyValuePairs.TryGetValue(face.Mapping.MappingFromLocation.NormalizedPixelPercentage, out collection))
result += 1;
else
personContainers.AddRange(keyValuePairs[face.Mapping.MappingFromLocation.NormalizedPixelPercentage]);
personContainers.AddRange(collection);
}
foreach (PersonContainer personContainer in personContainers)
{
@ -420,7 +419,7 @@ public class MapLogic
PersonBirthday personBirthday;
DateTime dateTime = DateTime.Now;
PersonContainer[] personContainers;
Dictionary<int, PersonContainer[]> keyValuePairs;
Dictionary<int, PersonContainer[]>? keyValuePairs;
foreach (Face face in distinctFilteredFaces)
{
if (face.Mapping is null)
@ -430,14 +429,13 @@ public class MapLogic
relativePath = Path.GetDirectoryName($"C:{face.RelativePath}");
if (string.IsNullOrEmpty(relativePath) || relativePath.Length < 3)
continue;
if (!_IdThenNormalizedPixelPercentageToPersonContainers.ContainsKey(face.Mapping.MappingFromItem.Id))
if (!_IdThenNormalizedPixelPercentageToPersonContainers.TryGetValue(face.Mapping.MappingFromItem.Id, out keyValuePairs))
{
personKey = null;
directory = Path.Combine(_EDistanceContentTicksDirectory, $"Unnamed{relativePath[2..]}");
}
else
{
keyValuePairs = _IdThenNormalizedPixelPercentageToPersonContainers[face.Mapping.MappingFromItem.Id];
if (!keyValuePairs.ContainsKey(face.Mapping.MappingFromLocation.NormalizedPixelPercentage))
continue;
personKey = null;
@ -497,7 +495,7 @@ public class MapLogic
PersonBirthday personBirthday;
PersonContainer[] personContainers;
const int by = Stateless.IMapLogic.Sorting;
Dictionary<int, PersonContainer[]> keyValuePairs;
Dictionary<int, PersonContainer[]>? keyValuePairs;
Dictionary<string, List<Mapping>> checkKeyValuePairs = new();
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)";
@ -510,14 +508,13 @@ public class MapLogic
progressBar.Tick();
if (sortingContainer.Face.Mapping is null)
throw new NotSupportedException();
if (!_IdThenNormalizedPixelPercentageToPersonContainers.ContainsKey(sortingContainer.Sorting.Id))
if (!_IdThenNormalizedPixelPercentageToPersonContainers.TryGetValue(sortingContainer.Sorting.Id, out keyValuePairs))
throw new NotSupportedException();
if (!results.ContainsKey(sortingContainer.Face.Mapping.MappingFromItem.Id))
results.Add(sortingContainer.Face.Mapping.MappingFromItem.Id, new());
hashSet = results[sortingContainer.Face.Mapping.MappingFromItem.Id];
if (hashSet.Contains(sortingContainer.Face.Mapping.MappingFromLocation.NormalizedPixelPercentage))
continue;
keyValuePairs = _IdThenNormalizedPixelPercentageToPersonContainers[sortingContainer.Sorting.Id];
if (!keyValuePairs.ContainsKey(sortingContainer.Sorting.NormalizedPixelPercentage))
throw new NotSupportedException();
personContainers = keyValuePairs[sortingContainer.Sorting.NormalizedPixelPercentage];
@ -553,7 +550,7 @@ public class MapLogic
const int zero = 0;
string mappingSegmentB;
PersonBirthday personBirthday;
List<int> normalizedPixelPercentages;
List<int>? normalizedPixelPercentages;
int by = Stateless.IMapLogic.ForceSingleImage;
string displayDirectoryName = _Configuration.MappingDefaultName;
Face[] orderedDistinctFilteredFaces = (from l in distinctFilteredFaces orderby l.Mapping is not null, l.Mapping?.MappingFromLocation.Confidence descending select l).ToArray();
@ -563,9 +560,8 @@ public class MapLogic
throw new NotSupportedException();
if (face.Mapping.MappingFromPerson.PersonBirthday is not null)
continue;
if (_SkipCollection.ContainsKey(face.Mapping.MappingFromItem.Id))
if (_SkipCollection.TryGetValue(face.Mapping.MappingFromItem.Id, out normalizedPixelPercentages))
{
normalizedPixelPercentages = _SkipCollection[face.Mapping.MappingFromItem.Id];
if (normalizedPixelPercentages.Contains(face.Mapping.MappingFromLocation.NormalizedPixelPercentage))
continue;
}
@ -724,8 +720,9 @@ public class MapLogic
string? personDisplayDirectory;
int? normalizedPixelPercentage;
WindowsShortcut windowsShortcut;
Dictionary<int, PersonContainer[]> keyValuePairs;
Dictionary<int, PersonContainer[]>? keyValuePairs;
string by = nameof(Stateless.IMapLogic.ManualCopy);
Dictionary<int, Face>? normalizedPixelPercentageToFace;
string dFacesContentDirectory = Path.Combine(dResultsFullGroupDirectory, "()");
string successfull = $"_ {nameof(Stateless.IMapLogic.ManualCopy).Humanize(LetterCasing.Title)} Successfull";
Dictionary<int, Dictionary<int, Face>> idToNormalizedPixelPercentageToFace = GetKeyValuePairs(distinctFilteredFaces);
@ -741,9 +738,8 @@ public class MapLogic
(id, normalizedPixelPercentage, _) = IMapping.GetReversedDeterministicHashCodeKey(_Configuration.LocationDigits, _FacesFileNameExtension, personDisplayDirectoryAllFile);
if (id is null || normalizedPixelPercentage is null)
continue;
if (_IdThenNormalizedPixelPercentageToPersonContainers.ContainsKey(id.Value))
if (_IdThenNormalizedPixelPercentageToPersonContainers.TryGetValue(id.Value, out keyValuePairs))
{
keyValuePairs = _IdThenNormalizedPixelPercentageToPersonContainers[id.Value];
if (keyValuePairs.ContainsKey(normalizedPixelPercentage.Value))
continue;
}
@ -756,10 +752,10 @@ public class MapLogic
mappingSegmentB = GetMappingSegmentB(_Ticks, personBirthday, keyValuePair.Value.ApproximateYears, fileInfo.CreationTime, isWrongYear: null);
directory = Path.Combine(_EDistanceContentTicksDirectory, by, personKeyFormatted, mappingSegmentB);
personDirectory = Path.Combine(directory, keyValuePair.Value.DisplayDirectoryName, "lnk");
if (!Directory.Exists(personDirectory))
_ = Directory.CreateDirectory(personDirectory);
if (!idToNormalizedPixelPercentageToFace.ContainsKey(id.Value))
throw new NotSupportedException();
if (!idToNormalizedPixelPercentageToFace.TryGetValue(id.Value, out normalizedPixelPercentageToFace))
continue;
if (!normalizedPixelPercentageToFace.ContainsKey(normalizedPixelPercentage.Value))
continue;
face = idToNormalizedPixelPercentageToFace[id.Value][normalizedPixelPercentage.Value];
if (face.Mapping is null)
throw new NotSupportedException();
@ -772,6 +768,8 @@ public class MapLogic
facesDirectory = Path.Combine($"{dFacesContentDirectory}{directoryName}", face.Mapping.MappingFromItem.ImageFileHolder.NameWithoutExtension);
faceFileName = $"{face.Mapping.MappingFromLocation.DeterministicHashCodeKey}{face.Mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}{_FacesFileNameExtension}";
checkFile = Path.Combine(directory, fileInfo.Name);
if (!Directory.Exists(personDirectory))
_ = Directory.CreateDirectory(personDirectory);
if (!File.Exists(checkFile))
File.Copy(personDisplayDirectoryAllFile, checkFile);
if (personDisplayDirectoryAllFile.Contains(successfull))

View File

@ -345,12 +345,12 @@ internal abstract class MapLogic
}
}
private static string? GetCheckFile(string facesFileNameExtension, string file, int id, int normalizedPixelPercentage)
private static string? GetCheckFile(Configuration configuration, string facesFileNameExtension, string file, int id, int normalizedPixelPercentage)
{
string? result;
string fileName = Path.GetFileName(file);
string? directoryName = Path.GetDirectoryName(file);
(string? Id, string? NormalizedPixelPercentage, string? ExtensionLowered, bool? Check) segments = IMapping.GetSegments(facesFileNameExtension, fileName);
(string? Id, string? NormalizedPixelPercentage, string? ExtensionLowered, bool? Check) segments = IMapping.GetSegments(configuration.LocationDigits, facesFileNameExtension, fileName);
if (string.IsNullOrEmpty(directoryName) || string.IsNullOrEmpty(segments.Id) || string.IsNullOrEmpty(segments.NormalizedPixelPercentage) || string.IsNullOrEmpty(segments.ExtensionLowered))
result = null;
else
@ -452,7 +452,7 @@ internal abstract class MapLogic
result++;
continue;
}
checkFile = GetCheckFile(facesFileNameExtension, file, id.Value, normalizedPixelPercentage.Value);
checkFile = GetCheckFile(configuration, facesFileNameExtension, file, id.Value, normalizedPixelPercentage.Value);
if (string.IsNullOrEmpty(checkFile))
throw new NotSupportedException();
if (faces is null)
@ -554,8 +554,8 @@ internal abstract class MapLogic
private static void SetPersonTicks(long ticks, List<Face> distinctFilteredFaces, Dictionary<long, (long LCL, long Minimum, long Maximum, long UCL)> personKeyToRanges, Dictionary<int, Dictionary<int, PersonContainer[]>> idThenNormalizedPixelPercentageToPersonContainers)
{
PersonContainer[] personContainers;
Dictionary<int, PersonContainer[]> keyValuePairs;
PersonContainer[]? personContainers;
Dictionary<int, PersonContainer[]>? keyValuePairs;
Dictionary<long, List<long>> personTicks = new();
int totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds);
string message = $") {distinctFilteredFaces.Count:000} Set Person Ticks - {totalSeconds} total second(s)";
@ -566,12 +566,10 @@ internal abstract class MapLogic
progressBar.Tick();
if (face.Mapping is null)
throw new NotSupportedException();
if (!idThenNormalizedPixelPercentageToPersonContainers.ContainsKey(face.Mapping.MappingFromItem.Id))
if (!idThenNormalizedPixelPercentageToPersonContainers.TryGetValue(face.Mapping.MappingFromItem.Id, out keyValuePairs))
continue;
keyValuePairs = idThenNormalizedPixelPercentageToPersonContainers[face.Mapping.MappingFromItem.Id];
if (!keyValuePairs.ContainsKey(face.Mapping.MappingFromLocation.NormalizedPixelPercentage))
if (!keyValuePairs.TryGetValue(face.Mapping.MappingFromLocation.NormalizedPixelPercentage, out personContainers))
continue;
personContainers = keyValuePairs[face.Mapping.MappingFromLocation.NormalizedPixelPercentage];
foreach (PersonContainer personContainer in personContainers)
{
if (personContainer.Key is null)
@ -607,13 +605,14 @@ internal abstract class MapLogic
private static void AppendToSkipCollection(Dictionary<int, List<int>> skipCollection, Dictionary<int, Dictionary<int, PersonContainer[]>> idThenNormalizedPixelPercentageToPersonContainers, Dictionary<int, Dictionary<int, PersonContainer[]>> incorrectIdThenNormalizedPixelPercentageToPersonContainers)
{
Dictionary<int, PersonContainer[]>? keyValuePairs;
foreach (KeyValuePair<int, Dictionary<int, PersonContainer[]>> keyValuePair in incorrectIdThenNormalizedPixelPercentageToPersonContainers)
{
if (!skipCollection.ContainsKey(keyValuePair.Key))
skipCollection.Add(keyValuePair.Key, new());
if (idThenNormalizedPixelPercentageToPersonContainers.ContainsKey(keyValuePair.Key))
if (idThenNormalizedPixelPercentageToPersonContainers.TryGetValue(keyValuePair.Key, out keyValuePairs))
{
if (idThenNormalizedPixelPercentageToPersonContainers[keyValuePair.Key].ContainsKey(keyValuePair.Value.ElementAt(0).Key))
if (keyValuePairs.ContainsKey(keyValuePair.Value.ElementAt(0).Key))
continue;
}
skipCollection[keyValuePair.Key].AddRange(from l in keyValuePair.Value.Keys select l);
@ -642,7 +641,7 @@ internal abstract class MapLogic
{
int? approximateYears = null;
PersonBirthday? personBirthday;
PersonContainer personContainer;
PersonContainer? personContainer;
string displayDirectoryName = configuration.MappingDefaultName;
foreach (long personKey in personKeyCollection)
{

View File

@ -6,7 +6,7 @@ public interface ILocation
string TestStatic_GetRightPadded(int locationDigits, string value) =>
GetRightPadded(locationDigits, value);
static string GetRightPadded(int locationDigits, string value) =>
value.PadRight(locationDigits, '0');
value.Length == locationDigits ? value : value.Length > locationDigits ? value[..locationDigits] : value.PadRight(locationDigits, '0');
string TestStatic_GetRightPadded(int locationDigits, int value) =>
GetRightPadded(locationDigits, value);

View File

@ -6,10 +6,10 @@ public interface IMapping
static string GetDeterministicHashCodeKey(int id, int normalizedPixelPercentage)
=> $"{id}.{normalizedPixelPercentage}";
(string?, string?, string?, bool?) TestStatic_GetSegments(string facesFileNameExtension, string fileName)
=> GetSegments(facesFileNameExtension, fileName);
static (string?, string?, string?, bool?) GetSegments(string facesFileNameExtension, string fileName)
=> Mapping.GetSegments(facesFileNameExtension, fileName);
(string?, string?, string?, bool?) TestStatic_GetSegments(int locationDigits, string facesFileNameExtension, string fileName)
=> GetSegments(locationDigits, facesFileNameExtension, fileName);
static (string?, string?, string?, bool?) GetSegments(int locationDigits, string facesFileNameExtension, string fileName)
=> Mapping.GetSegments(locationDigits, facesFileNameExtension, fileName);
(int?, int?, List<Models.Face>?) TestStatic_GetReversedDeterministicHashCodeKey(int locationDigits, string facesFileNameExtension, string file) =>
GetReversedDeterministicHashCodeKey(locationDigits, facesFileNameExtension, file);

View File

@ -18,7 +18,7 @@ internal abstract class Mapping
int? id;
List<Models.Face>? faces;
int? normalizedPixelPercentage;
(string? Id, string? NormalizedPixelPercentage, string? ExtensionLowered, bool? Check) segments = GetSegments(facesFileNameExtension, fileName);
(string? Id, string? NormalizedPixelPercentage, string? ExtensionLowered, bool? Check) segments = GetSegments(locationDigits, facesFileNameExtension, fileName);
if (string.IsNullOrEmpty(segments.Id) || string.IsNullOrEmpty(segments.NormalizedPixelPercentage) || string.IsNullOrEmpty(segments.ExtensionLowered) || segments.Check is null)
{
id = null;
@ -45,7 +45,7 @@ internal abstract class Mapping
return new(id, normalizedPixelPercentage, faces);
}
internal static (string?, string?, string?, bool?) GetSegments(string facesFileNameExtension, string fileName)
internal static (string?, string?, string?, bool?) GetSegments(int locationDigits, string facesFileNameExtension, string fileName)
{
string[] segments = fileName.Split('.');
string? id;
@ -63,8 +63,8 @@ internal abstract class Mapping
{
id = segments[0];
extensionLowered = $".{segments[2]}";
normalizedPixelPercentage = segments[1];
needsFacesFileNameExtension = segments.Length == 3;
normalizedPixelPercentage = ILocation.GetRightPadded(locationDigits, segments[1]);
}
return new(id, normalizedPixelPercentage, extensionLowered, needsFacesFileNameExtension);
}

View File

@ -15,7 +15,7 @@ internal abstract class PersonContainer
if (personDisplayDirectoryAllFile.EndsWith(".lnk"))
continue;
(id, normalizedPixelPercentage, _) = IMapping.GetReversedDeterministicHashCodeKey(locationDigits, facesFileNameExtension, personDisplayDirectoryAllFile);
if (id is not null && normalizedPixelPercentage is not null)
if (id is not null && normalizedPixelPercentage is not null && !personDisplayDirectoryAllFile.EndsWith(".json"))
continue;
checkDirectory = Path.GetDirectoryName(personDisplayDirectoryAllFile);
if (string.IsNullOrEmpty(checkDirectory))

View File

@ -130,6 +130,15 @@ public class UnitTestCalculations
Assert.IsTrue(successfull == "_ Manual Copy Successfull");
}
[TestMethod]
public void TestMethodDel()
{
string source = @"F:\Tmp\Phares\Compare\Images 2022-09-15 - 7390c13 - III - Results\E) Distance\2022-09-15\7680 x 4320\7680x4320 - Hog - Large\()\(637992984751968513)";
for (int i = 1; i < 11; i++)
_ = IPath.DeleteEmptyDirectories(source);
Assert.IsTrue(true);
}
[TestMethod]
public void TestMethodDirectory()
{