Change to the Normalized Pixel Percentage Formula
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
using Humanizer;
|
||||
using ShellProgressBar;
|
||||
using System.Text.Json;
|
||||
using View_by_Distance.Shared.Models;
|
||||
using View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
@ -74,15 +73,12 @@ internal abstract class MapLogic
|
||||
}
|
||||
}
|
||||
|
||||
internal static List<(string, string[], string, List<Face>?)> DeleteEmptyDirectoriesAndGetCollection(Configuration configuration, string facesFileNameExtension, long ticks, string eDistanceContentDirectory, List<string> personKeyFormattedCollection, Dictionary<int, List<Face>> keyValuePairs)
|
||||
internal static List<(string, string[], string)> DeleteEmptyDirectoriesAndGetCollection(Configuration configuration, string facesFileNameExtension, long ticks, string eDistanceContentDirectory, List<string> personKeyFormattedCollection)
|
||||
{
|
||||
List<(string, string[], string, List<Face>?)> results = new();
|
||||
List<(string, string[], string)> results = new();
|
||||
int? id;
|
||||
bool check;
|
||||
string[] files;
|
||||
List<Face>? faces;
|
||||
const int zero = 0;
|
||||
List<int> checks = new();
|
||||
string[] yearDirectories;
|
||||
string personKeyFormatted;
|
||||
string ticksDirectoryName;
|
||||
@ -94,7 +90,6 @@ internal abstract class MapLogic
|
||||
string[] personNameLinkDirectories;
|
||||
string? personFirstInitialDirectory;
|
||||
string[] personDisplayDirectoryNames;
|
||||
bool keyValuePairsAny = keyValuePairs.Any();
|
||||
string manualCopyHumanized = nameof(IMapLogic.ManualCopy).Humanize(LetterCasing.Title);
|
||||
int totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds);
|
||||
string forceSingleImageHumanized = nameof(IMapLogic.ForceSingleImage).Humanize(LetterCasing.Title);
|
||||
@ -156,31 +151,10 @@ internal abstract class MapLogic
|
||||
{
|
||||
if (file.EndsWith(".lnk") || file.EndsWith(".json"))
|
||||
continue;
|
||||
(id, normalizedPixelPercentage, faces) = IMapping.GetReversedDeterministicHashCodeKey(configuration.LocationDigits, facesFileNameExtension, keyValuePairsAny, keyValuePairs, file);
|
||||
(id, normalizedPixelPercentage, _) = IMapping.GetReversedDeterministicHashCodeKey(configuration.LocationDigits, facesFileNameExtension, file);
|
||||
if (id is null || normalizedPixelPercentage is null)
|
||||
continue;
|
||||
if (configuration.MappingMoveUnableToMatch)
|
||||
{
|
||||
if (faces is null)
|
||||
check = false;
|
||||
else
|
||||
{
|
||||
check = false;
|
||||
checks.Clear();
|
||||
foreach (Face face in faces)
|
||||
{
|
||||
if (face.Mapping is null)
|
||||
throw new NotSupportedException();
|
||||
checks.Add(face.Mapping.MappingFromLocation.NormalizedPixelPercentage);
|
||||
if (normalizedPixelPercentage.Value != face.Mapping.MappingFromLocation.NormalizedPixelPercentage)
|
||||
continue;
|
||||
check = true;
|
||||
}
|
||||
if (!check)
|
||||
checks.Add(normalizedPixelPercentage.Value);
|
||||
}
|
||||
}
|
||||
results.Add(new(personKeyFormatted, personDisplayDirectoryNames, file, faces));
|
||||
results.Add(new(personKeyFormatted, personDisplayDirectoryNames, file));
|
||||
}
|
||||
personNameLinkDirectories = Directory.GetDirectories(personFirstInitialDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string personNameLinkDirectory in personNameLinkDirectories)
|
||||
@ -221,13 +195,10 @@ internal abstract class MapLogic
|
||||
|
||||
private static void SetKeyValuePairs(Configuration configuration, long ticks, List<PersonContainer> personContainers, List<Face> distinctFilteredFaces, List<(string, string[], int, int)> personKeyFormattedIdThenNormalizedPixelPercentageCollection, List<(string, int, int)> incorrectPersonKeyFormattedIdThenNormalizedPixelPercentageCollection, Dictionary<long, PersonContainer> personKeyToPersonContainer, Dictionary<int, Dictionary<int, PersonContainer[]>> idThenNormalizedPixelPercentageToPersonContainers, List<(string[], PersonContainer)> possiblyNewPersonDisplayDirectoryNamesAndPersonContainer, Dictionary<int, Dictionary<int, PersonContainer[]>> incorrectIdThenNormalizedPixelPercentageToPersonContainers, Dictionary<long, (long LCL, long Minimum, long Maximum, long UCL)> personKeyToRanges)
|
||||
{
|
||||
string check;
|
||||
const int zero = 0;
|
||||
string rightPadded;
|
||||
PersonBirthday? personBirthday;
|
||||
string newestPersonKeyFormatted;
|
||||
PersonContainer[] distinctPersonContainers;
|
||||
int normalizedPixelPercentageInDecimalForm;
|
||||
Dictionary<string, PersonContainer> personKeyFormattedToPersonContainer = new();
|
||||
Dictionary<long, List<PersonContainer>> personKeyToPersonContainerCollection = new();
|
||||
Dictionary<int, Dictionary<int, List<PersonContainer>>> idThenNormalizedPixelPercentageToPersonContainerCollection = new();
|
||||
@ -272,21 +243,9 @@ internal abstract class MapLogic
|
||||
personDisplayDirectoryTo.Add(personDisplayDirectory, new(personDisplayDirectoryNames, personKeyFormattedToPersonContainer[personKeyFormatted]));
|
||||
if (!idThenNormalizedPixelPercentageToPersonContainerCollection.ContainsKey(id))
|
||||
idThenNormalizedPixelPercentageToPersonContainerCollection.Add(id, new());
|
||||
check = normalizedPixelPercentage.ToString();
|
||||
if (check.Length == configuration.LocationDigits)
|
||||
{
|
||||
if (!idThenNormalizedPixelPercentageToPersonContainerCollection[id].ContainsKey(normalizedPixelPercentage))
|
||||
idThenNormalizedPixelPercentageToPersonContainerCollection[id].Add(normalizedPixelPercentage, new());
|
||||
idThenNormalizedPixelPercentageToPersonContainerCollection[id][normalizedPixelPercentage].Add(personKeyFormattedToPersonContainer[personKeyFormatted]);
|
||||
}
|
||||
else
|
||||
{
|
||||
rightPadded = ILocation.GetRightPadded(configuration.LocationDigits, check);
|
||||
normalizedPixelPercentageInDecimalForm = int.Parse(rightPadded);
|
||||
if (!idThenNormalizedPixelPercentageToPersonContainerCollection[id].ContainsKey(normalizedPixelPercentageInDecimalForm))
|
||||
idThenNormalizedPixelPercentageToPersonContainerCollection[id].Add(normalizedPixelPercentageInDecimalForm, new());
|
||||
idThenNormalizedPixelPercentageToPersonContainerCollection[id][normalizedPixelPercentage].Add(personKeyFormattedToPersonContainer[personKeyFormatted]);
|
||||
}
|
||||
if (!idThenNormalizedPixelPercentageToPersonContainerCollection[id].ContainsKey(normalizedPixelPercentage))
|
||||
idThenNormalizedPixelPercentageToPersonContainerCollection[id].Add(normalizedPixelPercentage, new());
|
||||
idThenNormalizedPixelPercentageToPersonContainerCollection[id][normalizedPixelPercentage].Add(personKeyFormattedToPersonContainer[personKeyFormatted]);
|
||||
}
|
||||
foreach (KeyValuePair<string, (string[], PersonContainer)> keyValuePair in personDisplayDirectoryTo)
|
||||
possiblyNewPersonDisplayDirectoryNamesAndPersonContainer.Add(keyValuePair.Value);
|
||||
@ -311,27 +270,14 @@ internal abstract class MapLogic
|
||||
continue;
|
||||
if (!incorrectIdThenNormalizedPixelPercentageToPersonContainerCollection.ContainsKey(id))
|
||||
incorrectIdThenNormalizedPixelPercentageToPersonContainerCollection.Add(id, new());
|
||||
check = normalizedPixelPercentage.ToString();
|
||||
if (!personKeyFormattedToPersonContainer.ContainsKey(personKeyFormatted))
|
||||
{
|
||||
personContainer = new(personBirthday, configuration.MappingDefaultName);
|
||||
personKeyFormattedToPersonContainer.Add(personKeyFormatted, personContainer);
|
||||
}
|
||||
if (check.Length == configuration.LocationDigits)
|
||||
{
|
||||
if (!incorrectIdThenNormalizedPixelPercentageToPersonContainerCollection[id].ContainsKey(normalizedPixelPercentage))
|
||||
incorrectIdThenNormalizedPixelPercentageToPersonContainerCollection[id].Add(normalizedPixelPercentage, new());
|
||||
incorrectIdThenNormalizedPixelPercentageToPersonContainerCollection[id][normalizedPixelPercentage].Add(personKeyFormattedToPersonContainer[personKeyFormatted]);
|
||||
}
|
||||
else
|
||||
{
|
||||
rightPadded = ILocation.GetRightPadded(configuration.LocationDigits, check);
|
||||
normalizedPixelPercentageInDecimalForm = int.Parse(rightPadded);
|
||||
if (!incorrectIdThenNormalizedPixelPercentageToPersonContainerCollection[id].ContainsKey(normalizedPixelPercentageInDecimalForm))
|
||||
incorrectIdThenNormalizedPixelPercentageToPersonContainerCollection[id].Add(normalizedPixelPercentageInDecimalForm, new());
|
||||
incorrectIdThenNormalizedPixelPercentageToPersonContainerCollection[id][normalizedPixelPercentage].Add(personKeyFormattedToPersonContainer[personKeyFormatted]);
|
||||
}
|
||||
|
||||
if (!incorrectIdThenNormalizedPixelPercentageToPersonContainerCollection[id].ContainsKey(normalizedPixelPercentage))
|
||||
incorrectIdThenNormalizedPixelPercentageToPersonContainerCollection[id].Add(normalizedPixelPercentage, new());
|
||||
incorrectIdThenNormalizedPixelPercentageToPersonContainerCollection[id][normalizedPixelPercentage].Add(personKeyFormattedToPersonContainer[personKeyFormatted]);
|
||||
}
|
||||
}
|
||||
foreach (KeyValuePair<int, Dictionary<int, List<PersonContainer>>> keyValuePair in incorrectIdThenNormalizedPixelPercentageToPersonContainerCollection)
|
||||
@ -358,26 +304,6 @@ internal abstract class MapLogic
|
||||
return result;
|
||||
}
|
||||
|
||||
private static bool Valid(string checkFile, List<Face> faces)
|
||||
{
|
||||
bool result = false;
|
||||
string json;
|
||||
foreach (Face face in faces)
|
||||
{
|
||||
if (face.FaceEncoding is null)
|
||||
throw new NotSupportedException();
|
||||
if (faces.Count != 1)
|
||||
break;
|
||||
result = true;
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
json = JsonSerializer.Serialize(face.FaceEncoding);
|
||||
if (IPath.WriteAllText(checkFile, json, updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null))
|
||||
continue;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void MoveUnableToMatch(Configuration configuration, string eDistanceContentDirectory, string file, string jsonFile)
|
||||
{
|
||||
bool result;
|
||||
@ -407,7 +333,11 @@ internal abstract class MapLogic
|
||||
break;
|
||||
}
|
||||
if (string.IsNullOrEmpty(checkDirectoryName) || !directoryNames.Any() || !long.TryParse(directoryNames[^1][1..^1], out long directoryTicks))
|
||||
{
|
||||
result = false;
|
||||
File.Delete(jsonFile);
|
||||
File.Delete(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
bool jsonFileExists = File.Exists(jsonFile);
|
||||
@ -430,28 +360,43 @@ internal abstract class MapLogic
|
||||
{ }
|
||||
}
|
||||
|
||||
private static int SetCollectionsAndGetUnableToMatchCount(Configuration configuration, string facesFileNameExtension, long ticks, string eDistanceContentDirectory, Shared.Models.Methods.IFaceDistance? distance, Dictionary<string, string> personKeyFormattedToNewestPersonKeyFormatted, List<(string, string[], int, int)> personKeyFormattedIdThenNormalizedPixelPercentageCollection, List<(string, int, int)> incorrectPersonKeyFormattedIdThenNormalizedPixelPercentageCollection, List<(string, string[], string, List<Face>?)> collection)
|
||||
private static int SetCollectionsAndGetUnableToMatchCount(Configuration configuration, string facesFileNameExtension, long ticks, string eDistanceContentDirectory, Shared.Models.Methods.IFaceDistance? distance, Dictionary<int, List<Face>> idToFaces, Dictionary<string, string> personKeyFormattedToNewestPersonKeyFormatted, List<(string, string[], int, int)> personKeyFormattedIdThenNormalizedPixelPercentageCollection, List<(string, int, int)> incorrectPersonKeyFormattedIdThenNormalizedPixelPercentageCollection, List<(string, string[], string)> collection)
|
||||
{
|
||||
int? id;
|
||||
int result = 0;
|
||||
bool debugCheck;
|
||||
string? checkFile;
|
||||
List<Face>? faces;
|
||||
List<int> debugChecks = new();
|
||||
List<Face> checkFaces = new();
|
||||
int? normalizedPixelPercentage;
|
||||
string newestPersonKeyFormatted;
|
||||
List<string> duplicates = new();
|
||||
string personDisplayDirectoryName;
|
||||
bool idToFacesAny = idToFaces.Any();
|
||||
List<int> normalizedPixelPercentages;
|
||||
Dictionary<int, List<int>> idToNormalizedPixelPercentages = new();
|
||||
int totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds);
|
||||
string message = $") {collection.Count:000} join from ticks Director(ies) - B - {totalSeconds} total second(s)";
|
||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||
using ProgressBar progressBar = new(collection.Count, message, options);
|
||||
foreach ((string personKeyFormatted, string[] personDisplayDirectoryNames, string file, List<Face>? faces) in collection)
|
||||
foreach ((string personKeyFormatted, string[] personDisplayDirectoryNames, string file) in collection)
|
||||
{
|
||||
progressBar.Tick();
|
||||
(id, normalizedPixelPercentage, _) = IMapping.GetReversedDeterministicHashCodeKey(configuration.LocationDigits, facesFileNameExtension, file);
|
||||
(id, normalizedPixelPercentage, faces) = IMapping.GetReversedDeterministicHashCodeKey(
|
||||
configuration.LocationDigits,
|
||||
facesFileNameExtension,
|
||||
idToFacesAny,
|
||||
idToFaces,
|
||||
file);
|
||||
if (id is null || normalizedPixelPercentage is null)
|
||||
{
|
||||
result++;
|
||||
continue;
|
||||
}
|
||||
if (!idToNormalizedPixelPercentages.ContainsKey(id.Value))
|
||||
idToNormalizedPixelPercentages.Add(id.Value, new());
|
||||
normalizedPixelPercentages = idToNormalizedPixelPercentages[id.Value];
|
||||
checkFile = GetCheckFile(configuration, facesFileNameExtension, file, id.Value, normalizedPixelPercentage.Value);
|
||||
if (string.IsNullOrEmpty(checkFile))
|
||||
throw new NotSupportedException();
|
||||
@ -460,20 +405,33 @@ internal abstract class MapLogic
|
||||
result++;
|
||||
continue;
|
||||
}
|
||||
debugCheck = false;
|
||||
checkFaces.Clear();
|
||||
debugChecks.Clear();
|
||||
foreach (Face face in faces)
|
||||
{
|
||||
if (face.Mapping is null)
|
||||
throw new NotSupportedException();
|
||||
debugChecks.Add(face.Mapping.MappingFromLocation.NormalizedPixelPercentage);
|
||||
if (normalizedPixelPercentage.Value != face.Mapping.MappingFromLocation.NormalizedPixelPercentage)
|
||||
continue;
|
||||
if (normalizedPixelPercentages.Contains(face.Mapping.MappingFromLocation.NormalizedPixelPercentage))
|
||||
{
|
||||
duplicates.Add(string.Concat(id.Value, '.', normalizedPixelPercentage.Value, ".jpg", facesFileNameExtension));
|
||||
continue;
|
||||
}
|
||||
debugCheck = true;
|
||||
checkFaces.Add(face);
|
||||
if (!debugCheck)
|
||||
debugChecks.Add(normalizedPixelPercentage.Value);
|
||||
}
|
||||
if (checkFaces.Count != 1 && distance is not null && File.Exists(checkFile))
|
||||
{
|
||||
checkFaces.Clear();
|
||||
checkFaces.AddRange(distance.GetMatchingFaces(configuration.FaceDistanceTolerance, checkFile, faces));
|
||||
}
|
||||
if (!checkFaces.Any() && faces.Count == 1)
|
||||
checkFaces.AddRange(faces);
|
||||
if (!checkFaces.Any())
|
||||
{
|
||||
result++;
|
||||
@ -488,22 +446,22 @@ internal abstract class MapLogic
|
||||
MoveUnableToMatch(configuration, eDistanceContentDirectory, file, checkFile);
|
||||
continue;
|
||||
}
|
||||
if (!Valid(checkFile, checkFaces))
|
||||
{
|
||||
result++;
|
||||
if (configuration.MappingMoveUnableToMatch)
|
||||
MoveUnableToMatch(configuration, eDistanceContentDirectory, file, checkFile);
|
||||
continue;
|
||||
}
|
||||
idToNormalizedPixelPercentages[id.Value].Add(normalizedPixelPercentage.Value);
|
||||
if (!personKeyFormattedToNewestPersonKeyFormatted.ContainsKey(personKeyFormatted))
|
||||
newestPersonKeyFormatted = personKeyFormatted;
|
||||
else
|
||||
newestPersonKeyFormatted = personKeyFormattedToNewestPersonKeyFormatted[personKeyFormatted];
|
||||
personDisplayDirectoryName = personDisplayDirectoryNames[^1];
|
||||
if (!string.IsNullOrEmpty(personDisplayDirectoryName) && personDisplayDirectoryName[0] != '!')
|
||||
personKeyFormattedIdThenNormalizedPixelPercentageCollection.Add(new(newestPersonKeyFormatted, personDisplayDirectoryNames, id.Value, normalizedPixelPercentage.Value));
|
||||
else
|
||||
if (string.IsNullOrEmpty(personDisplayDirectoryName) || personDisplayDirectoryName[0] == '!')
|
||||
incorrectPersonKeyFormattedIdThenNormalizedPixelPercentageCollection.Add(new(newestPersonKeyFormatted, id.Value, normalizedPixelPercentage.Value));
|
||||
else
|
||||
personKeyFormattedIdThenNormalizedPixelPercentageCollection.Add(new(newestPersonKeyFormatted, personDisplayDirectoryNames, id.Value, normalizedPixelPercentage.Value));
|
||||
}
|
||||
if (duplicates.Any())
|
||||
{
|
||||
duplicates.Sort();
|
||||
if (duplicates.Any())
|
||||
{ }
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -686,18 +644,18 @@ internal abstract class MapLogic
|
||||
keyValuePairs.Add(face.Mapping.MappingFromItem.Id, new());
|
||||
keyValuePairs[face.Mapping.MappingFromItem.Id].Add(face);
|
||||
}
|
||||
List<(string, string[], string, List<Face>?)> collection = DeleteEmptyDirectoriesAndGetCollection(configuration,
|
||||
List<(string, string[], string)> collection = DeleteEmptyDirectoriesAndGetCollection(configuration,
|
||||
facesFileNameExtension,
|
||||
ticks,
|
||||
eDistanceContentDirectory,
|
||||
personKeyFormattedCollection,
|
||||
keyValuePairs);
|
||||
personKeyFormattedCollection);
|
||||
int unableToMatchCount = SetCollectionsAndGetUnableToMatchCount(
|
||||
configuration,
|
||||
facesFileNameExtension,
|
||||
ticks,
|
||||
eDistanceContentDirectory,
|
||||
faceDistance,
|
||||
keyValuePairs,
|
||||
personKeyFormattedToNewestPersonKeyFormatted,
|
||||
personKeyFormattedIdThenNormalizedPixelPercentageCollection,
|
||||
incorrectPersonKeyFormattedIdThenNormalizedPixelPercentageCollection,
|
||||
|
Reference in New Issue
Block a user