Remove Person Require People File,
PersonContainer and bug fix for GetRightPadded
This commit is contained in:
@ -13,6 +13,7 @@ public class Configuration
|
||||
public int LocationDigits { init; get; }
|
||||
public int LocationFactor { init; get; }
|
||||
public int MapLogicSigma { init; get; }
|
||||
public bool MappingMoveUnableToMatch { init; get; }
|
||||
public bool MappingSaveFaceEncoding { init; get; }
|
||||
public bool MappingSaveNotMapped { init; get; }
|
||||
public bool MappingSaveMapped { init; get; }
|
||||
@ -36,6 +37,7 @@ public class Configuration
|
||||
int locationDigits,
|
||||
int locationFactor,
|
||||
int mapLogicSigma,
|
||||
bool mappingMoveUnableToMatch,
|
||||
bool mappingSaveFaceEncoding,
|
||||
bool mappingSaveNotMapped,
|
||||
bool mappingSaveMapped,
|
||||
@ -58,6 +60,7 @@ public class Configuration
|
||||
LocationDigits = locationDigits;
|
||||
LocationFactor = locationFactor;
|
||||
MapLogicSigma = mapLogicSigma;
|
||||
MappingMoveUnableToMatch = mappingMoveUnableToMatch;
|
||||
MappingSaveFaceEncoding = mappingSaveFaceEncoding;
|
||||
MappingSaveNotMapped = mappingSaveNotMapped;
|
||||
MappingSaveMapped = mappingSaveMapped;
|
||||
|
@ -9,17 +9,14 @@ namespace View_by_Distance.Map.Models;
|
||||
public class MapLogic
|
||||
{
|
||||
|
||||
protected readonly List<double> _SkipCollection;
|
||||
protected readonly List<long> _NotMappedPersonKeys;
|
||||
protected readonly Dictionary<int, int[]> _KeyValuePairs;
|
||||
protected readonly Dictionary<int, int[]> _IndicesFromNew;
|
||||
protected readonly Dictionary<long, (long LCL, long Minimum, long Maximum, long UCL)> _PersonKeysRanges;
|
||||
protected readonly Dictionary<int, Dictionary<int, PersonBirthday[]>> _IdThenNormalizedPixelPercentageKeyValuePairs;
|
||||
protected readonly Dictionary<int, Dictionary<int, PersonBirthday[]>> _IncorrectIdThenNormalizedPixelPercentageKeyValuePairs;
|
||||
protected readonly Dictionary<long, (string DisplayDirectoryName, int? ApproximateYears, PersonBirthday[] PersonBirthdays, long PersonKey)> _PeopleKeyValuePairs;
|
||||
protected readonly Dictionary<int, List<int>> _SkipCollection;
|
||||
protected readonly Dictionary<long, PersonContainer> _PersonKeyToPersonContainer;
|
||||
protected readonly Dictionary<long, (long LCL, long Minimum, long Maximum, long UCL)> _PersonKeyToRanges;
|
||||
protected readonly Dictionary<int, Dictionary<int, PersonContainer[]>> _IdThenNormalizedPixelPercentageToPersonContainers;
|
||||
|
||||
public Dictionary<int, int[]> KeyValuePairs => _KeyValuePairs;
|
||||
public Dictionary<int, int[]> IndicesFromNew => _IndicesFromNew;
|
||||
public Dictionary<int, int[]> KeyValuePairs => throw new NotImplementedException();
|
||||
public Dictionary<int, int[]> IndicesFromNew => throw new NotImplementedException();
|
||||
|
||||
private readonly long _Ticks;
|
||||
private const int _Mapping = 1;
|
||||
@ -29,20 +26,17 @@ public class MapLogic
|
||||
private readonly int _MaxDegreeOfParallelism;
|
||||
private readonly Configuration? _Configuration;
|
||||
private readonly string _FacesFilenameExtension;
|
||||
private readonly string _ResizeFilenameExtension;
|
||||
private readonly string _FacePartsFilenameExtension;
|
||||
private readonly string _FacesHiddenFilenameExtension;
|
||||
private readonly string _EDistanceContentTicksDirectory;
|
||||
|
||||
public MapLogic(int maxDegreeOfParallelism, Property.Models.Configuration propertyConfiguration, Configuration? configuration, string resizeFilenameExtension, string facesFilenameExtension, string facesHiddenFilenameExtension, string facePartsFilenameExtension, long ticks, Person[] people, string a2PeopleDateGroupDirectory, string eResultsFullGroupDirectory, List<Face> distinctFilteredFaces, Shared.Models.Methods.IFaceDistance? distance)
|
||||
public MapLogic(int maxDegreeOfParallelism, Property.Models.Configuration propertyConfiguration, Configuration? configuration, string resizeFilenameExtension, string facesFilenameExtension, string facesHiddenFilenameExtension, string facePartsFilenameExtension, long ticks, List<PersonContainer> personContainers, string eResultsFullGroupDirectory, List<Face> distinctFilteredFaces, Shared.Models.Methods.IFaceDistance? distance)
|
||||
{
|
||||
_Ticks = ticks;
|
||||
_PersonKeysRanges = new();
|
||||
_Configuration = configuration;
|
||||
_Log = Serilog.Log.ForContext<MapLogic>();
|
||||
_FacesFilenameExtension = facesFilenameExtension;
|
||||
_MaxDegreeOfParallelism = maxDegreeOfParallelism;
|
||||
_ResizeFilenameExtension = resizeFilenameExtension;
|
||||
_FacePartsFilenameExtension = facePartsFilenameExtension;
|
||||
_FacesHiddenFilenameExtension = facesHiddenFilenameExtension;
|
||||
if (_Log is null)
|
||||
@ -52,22 +46,16 @@ public class MapLogic
|
||||
if (_MaxDegreeOfParallelism == 0)
|
||||
{ }
|
||||
string json;
|
||||
string[] files;
|
||||
string fullPath;
|
||||
const int zero = 0;
|
||||
List<double> skipCollection = new();
|
||||
Dictionary<int, int[]>? keyValuePairs;
|
||||
List<long> notMappedPersonKeys = new();
|
||||
List<KeyValuePair<int, int[]>>? collection;
|
||||
Dictionary<int, int[]> indicesFromNew = new();
|
||||
string a2PeopleContentDirectory = Path.Combine(a2PeopleDateGroupDirectory, "()");
|
||||
Dictionary<int, List<int>> skipCollection = new();
|
||||
Dictionary<long, PersonContainer> personKeyToPersonContainer = new();
|
||||
string eDistanceContentDirectory = Path.Combine(eResultsFullGroupDirectory, "()");
|
||||
Dictionary<long, (string, int?, PersonBirthday[], long)> peopleKeyValuePairs = new();
|
||||
string? rootDirectoryParent = Path.GetDirectoryName(propertyConfiguration.RootDirectory);
|
||||
Dictionary<long, (long LCL, long Minimum, long Maximum, long UCL)> personKeyToRanges = new();
|
||||
string eDistanceContentTicksDirectory = Path.Combine(eDistanceContentDirectory, $"({ticks})");
|
||||
string a2PeopleContentKnownPeopleDirectory = Path.Combine(a2PeopleContentDirectory, "(KnownPeople)");
|
||||
Dictionary<int, Dictionary<int, PersonBirthday[]>> idThenNormalizedPixelPercentageKeyValuePairs = new();
|
||||
Dictionary<int, Dictionary<int, PersonBirthday[]>> incorrectIdThenNormalizedPixelPercentageKeyValuePairs = new();
|
||||
Dictionary<int, Dictionary<int, PersonContainer[]>> idThenNormalizedPixelPercentageToPersonContainers = new();
|
||||
for (int i = 1; i < 5; i++)
|
||||
_ = IPath.DeleteEmptyDirectories(eDistanceContentDirectory);
|
||||
_ = IPath.DeleteEmptyDirectories(eDistanceContentDirectory);
|
||||
@ -75,22 +63,10 @@ public class MapLogic
|
||||
throw new NullReferenceException(nameof(rootDirectoryParent));
|
||||
if (!Directory.Exists(eDistanceContentDirectory))
|
||||
_ = Directory.CreateDirectory(eDistanceContentDirectory);
|
||||
if (!Directory.Exists(a2PeopleContentKnownPeopleDirectory))
|
||||
_ = Directory.CreateDirectory(a2PeopleContentKnownPeopleDirectory);
|
||||
if (configuration is not null)
|
||||
Stateless.ByRef.Set(propertyConfiguration, configuration, ticks, _ResizeFilenameExtension, people, eDistanceContentDirectory, a2PeopleContentDirectory, distinctFilteredFaces, distance, skipCollection, peopleKeyValuePairs, notMappedPersonKeys, idThenNormalizedPixelPercentageKeyValuePairs, incorrectIdThenNormalizedPixelPercentageKeyValuePairs);
|
||||
if (!Directory.Exists(eDistanceContentTicksDirectory))
|
||||
_ = Directory.CreateDirectory(eDistanceContentTicksDirectory);
|
||||
files = Directory.GetFiles(rootDirectoryParent, "*keyValuePairs-6*.json", SearchOption.TopDirectoryOnly);
|
||||
if (files.Length != 1)
|
||||
keyValuePairs = new();
|
||||
else
|
||||
{
|
||||
json = File.ReadAllText(files[zero]);
|
||||
keyValuePairs = JsonSerializer.Deserialize<Dictionary<int, int[]>>(json);
|
||||
if (keyValuePairs is null)
|
||||
throw new NullReferenceException(nameof(keyValuePairs));
|
||||
}
|
||||
if (configuration is not null)
|
||||
Stateless.MapLogic.Set(propertyConfiguration, configuration, resizeFilenameExtension, ticks, personContainers, eDistanceContentDirectory, distinctFilteredFaces, distance, personKeyToPersonContainer, personKeyToRanges, notMappedPersonKeys, skipCollection, idThenNormalizedPixelPercentageToPersonContainers);
|
||||
foreach (string propertyContentCollectionFile in propertyConfiguration.PropertyContentCollectionFiles)
|
||||
{
|
||||
fullPath = Path.GetFullPath(string.Concat(rootDirectoryParent, propertyContentCollectionFile));
|
||||
@ -102,29 +78,17 @@ public class MapLogic
|
||||
collection = JsonSerializer.Deserialize<List<KeyValuePair<int, int[]>>>(json);
|
||||
if (collection is null)
|
||||
throw new NullReferenceException(nameof(collection));
|
||||
foreach (KeyValuePair<int, int[]> keyValuePair in collection)
|
||||
{
|
||||
if (indicesFromNew.ContainsKey(keyValuePair.Key))
|
||||
continue;
|
||||
indicesFromNew.Add(keyValuePair.Key, keyValuePair.Value);
|
||||
}
|
||||
}
|
||||
_KeyValuePairs = keyValuePairs;
|
||||
_IndicesFromNew = indicesFromNew;
|
||||
_SkipCollection = skipCollection;
|
||||
_PersonKeyToRanges = personKeyToRanges;
|
||||
_NotMappedPersonKeys = notMappedPersonKeys;
|
||||
_PeopleKeyValuePairs = peopleKeyValuePairs;
|
||||
_PersonKeyToPersonContainer = personKeyToPersonContainer;
|
||||
_EDistanceContentTicksDirectory = eDistanceContentTicksDirectory;
|
||||
_IdThenNormalizedPixelPercentageKeyValuePairs = idThenNormalizedPixelPercentageKeyValuePairs;
|
||||
_IncorrectIdThenNormalizedPixelPercentageKeyValuePairs = incorrectIdThenNormalizedPixelPercentageKeyValuePairs;
|
||||
_IdThenNormalizedPixelPercentageToPersonContainers = idThenNormalizedPixelPercentageToPersonContainers;
|
||||
}
|
||||
|
||||
public MapLogic(int maxDegreeOfParallelism, Property.Models.Configuration propertyConfiguration, Configuration? configuration, string resizeFilenameExtension, string facesFilenameExtension, string facesHiddenFilenameExtension, string facePartsFilenameExtension, long ticks, Person[] people, string peopleDateGroupDirectory, string zResultsFullGroupDirectory) :
|
||||
this(maxDegreeOfParallelism, propertyConfiguration, configuration, resizeFilenameExtension, facesFilenameExtension, facesHiddenFilenameExtension, facePartsFilenameExtension, ticks, people, peopleDateGroupDirectory, zResultsFullGroupDirectory, new(), null)
|
||||
{ }
|
||||
|
||||
public MapLogic(int maxDegreeOfParallelism, Property.Models.Configuration propertyConfiguration, Configuration? configuration, string outputExtension, long ticks, Person[] people, string peopleDateGroupDirectory, string zResultsFullGroupDirectory) :
|
||||
this(maxDegreeOfParallelism, propertyConfiguration, configuration, outputExtension, outputExtension, outputExtension, outputExtension, ticks, people, peopleDateGroupDirectory, zResultsFullGroupDirectory, new(), null)
|
||||
public MapLogic(int maxDegreeOfParallelism, Property.Models.Configuration propertyConfiguration, Configuration? configuration, string outputExtension, long ticks, List<PersonContainer> personContainers, string eResultsFullGroupDirectory) :
|
||||
this(maxDegreeOfParallelism, propertyConfiguration, configuration, outputExtension, outputExtension, outputExtension, outputExtension, ticks, personContainers, eResultsFullGroupDirectory, new(), null)
|
||||
{ }
|
||||
|
||||
public override string ToString()
|
||||
@ -133,18 +97,16 @@ public class MapLogic
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool Skip(double deterministicHashCodeKey) => _SkipCollection.Contains(deterministicHashCodeKey);
|
||||
|
||||
private List<(long, long, long, long)> GetPersonKeysRangesCollection(PersonBirthday[] personBirthdays)
|
||||
private List<(long, long, long, long)> GetPersonKeysRangesCollection(PersonContainer[] personContainers)
|
||||
{
|
||||
List<(long, long, long, long)> results = new();
|
||||
long personKey;
|
||||
foreach (PersonBirthday personBirthday in personBirthdays)
|
||||
foreach (PersonContainer personContainer in personContainers)
|
||||
{
|
||||
personKey = personBirthday.Value.Ticks;
|
||||
if (!_PersonKeysRanges.ContainsKey(personKey))
|
||||
if (personContainer.PersonKey is null)
|
||||
continue;
|
||||
results.Add(_PersonKeysRanges[personKey]);
|
||||
if (!_PersonKeyToRanges.ContainsKey(personContainer.PersonKey.Value))
|
||||
continue;
|
||||
results.Add(_PersonKeyToRanges[personContainer.PersonKey.Value]);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
@ -156,7 +118,7 @@ public class MapLogic
|
||||
List<Sorting> results = new();
|
||||
Sorting sorting;
|
||||
FaceDistance faceDistanceLength;
|
||||
Dictionary<int, PersonBirthday[]> keyValuePairs;
|
||||
Dictionary<int, PersonContainer[]> keyValuePairs;
|
||||
List<(long lcl, long minimum, long maximum, long ucl)> personKeysRangesCollection;
|
||||
for (int j = 0; j < faceDistanceLengths.Count; j++)
|
||||
{
|
||||
@ -167,15 +129,20 @@ public class MapLogic
|
||||
throw new NotSupportedException();
|
||||
if (faceDistanceLength.Length == 0)
|
||||
continue;
|
||||
if (_IdThenNormalizedPixelPercentageKeyValuePairs.ContainsKey(faceDistanceEncoding.Id))
|
||||
if (_SkipCollection.ContainsKey(faceDistanceEncoding.Id))
|
||||
{
|
||||
keyValuePairs = _IdThenNormalizedPixelPercentageKeyValuePairs[faceDistanceEncoding.Id];
|
||||
if (_SkipCollection[faceDistanceEncoding.Id].Contains(faceDistanceEncoding.NormalizedPixelPercentage.Value))
|
||||
continue;
|
||||
}
|
||||
if (_IdThenNormalizedPixelPercentageToPersonContainers.ContainsKey(faceDistanceEncoding.Id))
|
||||
{
|
||||
keyValuePairs = _IdThenNormalizedPixelPercentageToPersonContainers[faceDistanceEncoding.Id];
|
||||
if (keyValuePairs.ContainsKey(faceDistanceEncoding.NormalizedPixelPercentage.Value))
|
||||
continue;
|
||||
}
|
||||
if (!_IdThenNormalizedPixelPercentageKeyValuePairs.ContainsKey(faceDistanceLength.Id))
|
||||
if (!_IdThenNormalizedPixelPercentageToPersonContainers.ContainsKey(faceDistanceLength.Id))
|
||||
continue;
|
||||
keyValuePairs = _IdThenNormalizedPixelPercentageKeyValuePairs[faceDistanceLength.Id];
|
||||
keyValuePairs = _IdThenNormalizedPixelPercentageToPersonContainers[faceDistanceLength.Id];
|
||||
if (!keyValuePairs.ContainsKey(faceDistanceLength.NormalizedPixelPercentage.Value))
|
||||
continue;
|
||||
personKeysRangesCollection = GetPersonKeysRangesCollection(keyValuePairs[faceDistanceLength.NormalizedPixelPercentage.Value]);
|
||||
@ -201,8 +168,8 @@ public class MapLogic
|
||||
string fullName;
|
||||
string personKeyFormatted;
|
||||
PersonBirthday personBirthday;
|
||||
PersonContainer personContainer;
|
||||
WindowsShortcut windowsShortcut;
|
||||
(string DisplayDirectoryName, int? ApproximateYears, PersonBirthday[] PersonBirthdays, long PersonKey) person;
|
||||
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)
|
||||
{
|
||||
@ -223,10 +190,10 @@ public class MapLogic
|
||||
if (!Directory.Exists(directory))
|
||||
{
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
if (personKey is not null && _PeopleKeyValuePairs.ContainsKey(personKey.Value))
|
||||
if (personKey is not null && _PersonKeyToPersonContainer.ContainsKey(personKey.Value))
|
||||
{
|
||||
person = _PeopleKeyValuePairs[personKey.Value];
|
||||
fullName = string.Concat(person.DisplayDirectoryName, ".txt");
|
||||
personContainer = _PersonKeyToPersonContainer[personKey.Value];
|
||||
fullName = string.Concat(personContainer.PersonDisplayDirectoryName, ".txt");
|
||||
File.WriteAllText(Path.Combine(directory, fullName), string.Empty);
|
||||
}
|
||||
}
|
||||
@ -285,44 +252,36 @@ public class MapLogic
|
||||
if (_Configuration is null)
|
||||
throw new NullReferenceException(nameof(_Configuration));
|
||||
int result = 0;
|
||||
long personKey;
|
||||
int by = _Mapping;
|
||||
const int zero = 0;
|
||||
int? approximateYears;
|
||||
string mappingSegmentB;
|
||||
string personKeyFormatted;
|
||||
string displayDirectoryName;
|
||||
PersonBirthday personBirthday;
|
||||
List<PersonBirthday> personBirthdays = new();
|
||||
Dictionary<int, PersonBirthday[]> keyValuePairs;
|
||||
(string DisplayDirectoryName, int? ApproximateYears, PersonBirthday[] PersonBirthdays, long PersonKey) person;
|
||||
List<PersonContainer> personContainers = new();
|
||||
Dictionary<int, PersonContainer[]> keyValuePairs;
|
||||
foreach (Face face in distinctFilteredFaces)
|
||||
{
|
||||
personBirthdays.Clear();
|
||||
personContainers.Clear();
|
||||
if (face.Mapping is null)
|
||||
throw new NotSupportedException();
|
||||
if (!_IdThenNormalizedPixelPercentageKeyValuePairs.ContainsKey(face.Mapping.MappingFromItem.Id))
|
||||
if (!_IdThenNormalizedPixelPercentageToPersonContainers.ContainsKey(face.Mapping.MappingFromItem.Id))
|
||||
result += 1;
|
||||
else
|
||||
{
|
||||
keyValuePairs = _IdThenNormalizedPixelPercentageKeyValuePairs[face.Mapping.MappingFromItem.Id];
|
||||
keyValuePairs = _IdThenNormalizedPixelPercentageToPersonContainers[face.Mapping.MappingFromItem.Id];
|
||||
if (!keyValuePairs.ContainsKey(face.Mapping.MappingFromLocation.NormalizedPixelPercentage))
|
||||
result += 1;
|
||||
else
|
||||
personBirthdays.AddRange(keyValuePairs[face.Mapping.MappingFromLocation.NormalizedPixelPercentage]);
|
||||
personContainers.AddRange(keyValuePairs[face.Mapping.MappingFromLocation.NormalizedPixelPercentage]);
|
||||
}
|
||||
for (int i = 0; i < personBirthdays.Count; i++)
|
||||
foreach (PersonContainer personContainer in personContainers)
|
||||
{
|
||||
personKey = personBirthdays[i].Value.Ticks;
|
||||
if (!_PeopleKeyValuePairs.ContainsKey(personKey))
|
||||
if (personContainer.PersonKey is null || personContainer.PersonBirthdays is null || !personContainer.PersonBirthdays.Any())
|
||||
continue;
|
||||
person = _PeopleKeyValuePairs[personKey];
|
||||
approximateYears = person.ApproximateYears;
|
||||
personBirthday = person.PersonBirthdays[zero];
|
||||
displayDirectoryName = person.DisplayDirectoryName;
|
||||
personBirthday = personContainer.PersonBirthdays[zero];
|
||||
personKeyFormatted = IPersonBirthday.GetFormatted(_Configuration.PersonBirthdayFormat, personBirthday);
|
||||
mappingSegmentB = GetMappingSegmentB(_Ticks, personBirthday, approximateYears, face.Mapping.MappingFromItem);
|
||||
face.Mapping.UpdateMappingFromPerson(approximateYears, by, displayDirectoryName, personBirthday, mappingSegmentB);
|
||||
mappingSegmentB = GetMappingSegmentB(_Ticks, personBirthday, personContainer.ApproximateYears, face.Mapping.MappingFromItem);
|
||||
face.Mapping.UpdateMappingFromPerson(personContainer.ApproximateYears, by, personContainer.PersonDisplayDirectoryName, personBirthday, mappingSegmentB);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@ -423,9 +382,9 @@ public class MapLogic
|
||||
string subDirectoryName;
|
||||
string personKeyFormatted;
|
||||
PersonBirthday personBirthday;
|
||||
PersonBirthday[] personBirthdays;
|
||||
DateTime dateTime = DateTime.Now;
|
||||
Dictionary<int, PersonBirthday[]> keyValuePairs;
|
||||
PersonContainer[] personContainers;
|
||||
Dictionary<int, PersonContainer[]> keyValuePairs;
|
||||
foreach (Face face in distinctFilteredFaces)
|
||||
{
|
||||
if (face.Mapping is null)
|
||||
@ -435,28 +394,29 @@ public class MapLogic
|
||||
relativePath = Path.GetDirectoryName($"C:{face.RelativePath}");
|
||||
if (string.IsNullOrEmpty(relativePath) || relativePath.Length < 3)
|
||||
continue;
|
||||
if (!_IdThenNormalizedPixelPercentageKeyValuePairs.ContainsKey(face.Mapping.MappingFromItem.Id))
|
||||
if (!_IdThenNormalizedPixelPercentageToPersonContainers.ContainsKey(face.Mapping.MappingFromItem.Id))
|
||||
{
|
||||
personKey = null;
|
||||
directory = Path.Combine(_EDistanceContentTicksDirectory, $"Unnamed{relativePath[2..]}");
|
||||
}
|
||||
else
|
||||
{
|
||||
keyValuePairs = _IdThenNormalizedPixelPercentageKeyValuePairs[face.Mapping.MappingFromItem.Id];
|
||||
keyValuePairs = _IdThenNormalizedPixelPercentageToPersonContainers[face.Mapping.MappingFromItem.Id];
|
||||
if (!keyValuePairs.ContainsKey(face.Mapping.MappingFromLocation.NormalizedPixelPercentage))
|
||||
throw new NotSupportedException();
|
||||
personBirthdays = keyValuePairs[face.Mapping.MappingFromLocation.NormalizedPixelPercentage];
|
||||
personKey = null;
|
||||
isWrongYearFlag = IItem.GetWrongYearFlag(face.Mapping.MappingFromItem.IsWrongYear);
|
||||
subDirectoryName = $"{isWrongYearFlag}{face.Mapping.MappingFromItem.MinimumDateTime:yyyy}";
|
||||
if (personBirthdays.Length != 1)
|
||||
personContainers = keyValuePairs[face.Mapping.MappingFromLocation.NormalizedPixelPercentage];
|
||||
directory = Path.Combine(_EDistanceContentTicksDirectory, $"Not Supported{relativePath[2..]}", subDirectoryName);
|
||||
foreach (PersonContainer personContainer in personContainers)
|
||||
{
|
||||
personKey = null;
|
||||
directory = Path.Combine(_EDistanceContentTicksDirectory, $"Not Supported{relativePath[2..]}", subDirectoryName);
|
||||
}
|
||||
else
|
||||
{
|
||||
personBirthday = personBirthdays[zero];
|
||||
personKey = personBirthday.Value.Ticks;
|
||||
if (personContainers.Length != 1)
|
||||
break;
|
||||
if (personContainer.PersonKey is null || personContainer.PersonBirthdays is null || !personContainer.PersonBirthdays.Any())
|
||||
continue;
|
||||
personKey = personContainer.PersonKey.Value;
|
||||
personBirthday = personContainer.PersonBirthdays[zero];
|
||||
timeSpan = IPersonBirthday.GetTimeSpan(face.Mapping.MappingFromItem.MinimumDateTime, face.Mapping.MappingFromItem.IsWrongYear, personBirthday);
|
||||
if (timeSpan.HasValue)
|
||||
{
|
||||
@ -493,7 +453,6 @@ public class MapLogic
|
||||
int result = 0;
|
||||
Dictionary<int, HashSet<int>> results = new();
|
||||
string key;
|
||||
long personKey;
|
||||
const int zero = 0;
|
||||
HashSet<int> hashSet;
|
||||
string mappingSegmentB;
|
||||
@ -501,14 +460,13 @@ public class MapLogic
|
||||
string personKeyFormatted;
|
||||
List<Mapping> checkCollection;
|
||||
PersonBirthday personBirthday;
|
||||
PersonBirthday[] personBirthdays;
|
||||
Dictionary<int, PersonBirthday[]> keyValuePairs;
|
||||
PersonContainer[] personContainers;
|
||||
Dictionary<int, PersonContainer[]> keyValuePairs;
|
||||
Dictionary<string, List<Mapping>> checkKeyValuePairs = new();
|
||||
int totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - _Ticks).TotalSeconds);
|
||||
(string DisplayDirectoryName, int? ApproximateYears, PersonBirthday[] PersonBirthdays, long PersonKey) person;
|
||||
string message = $") {sortingContainers.Length:000} Update From Sorting Container(s) - {totalSeconds} total second(s)";
|
||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||
foreach (KeyValuePair<int, Dictionary<int, PersonBirthday[]>> keyValuePair in _IdThenNormalizedPixelPercentageKeyValuePairs)
|
||||
foreach (KeyValuePair<int, Dictionary<int, PersonContainer[]>> keyValuePair in _IdThenNormalizedPixelPercentageToPersonContainers)
|
||||
results.Add(keyValuePair.Key, (from l in keyValuePair.Value select l.Key).ToHashSet());
|
||||
using ProgressBar progressBar = new(sortingContainers.Length, message, options);
|
||||
foreach (SortingContainer sortingContainer in sortingContainers)
|
||||
@ -516,28 +474,26 @@ public class MapLogic
|
||||
progressBar.Tick();
|
||||
if (sortingContainer.Face.Mapping is null)
|
||||
throw new NotSupportedException();
|
||||
if (!_IdThenNormalizedPixelPercentageKeyValuePairs.ContainsKey(sortingContainer.Sorting.Id))
|
||||
if (!_IdThenNormalizedPixelPercentageToPersonContainers.ContainsKey(sortingContainer.Sorting.Id))
|
||||
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 = _IdThenNormalizedPixelPercentageKeyValuePairs[sortingContainer.Sorting.Id];
|
||||
keyValuePairs = _IdThenNormalizedPixelPercentageToPersonContainers[sortingContainer.Sorting.Id];
|
||||
if (!keyValuePairs.ContainsKey(sortingContainer.Sorting.NormalizedPixelPercentage))
|
||||
throw new NotSupportedException();
|
||||
personBirthdays = keyValuePairs[sortingContainer.Sorting.NormalizedPixelPercentage];
|
||||
personContainers = keyValuePairs[sortingContainer.Sorting.NormalizedPixelPercentage];
|
||||
if (sortingContainer.Face.Mapping.MappingFromLocation.Confidence < _Configuration.FaceDistanceMinimumConfidence || sortingContainer.Sorting.DistancePermyriad > _Configuration.FaceDistancePermyriad || sortingContainer.Sorting.DaysDelta > _Configuration.SortingDaysDeltaTolerance)
|
||||
continue;
|
||||
for (int i = 0; i < personBirthdays.Length; i++)
|
||||
foreach (PersonContainer personContainer in personContainers)
|
||||
{
|
||||
personKey = personBirthdays[i].Value.Ticks;
|
||||
if (!_PeopleKeyValuePairs.ContainsKey(personKey))
|
||||
if (personContainer.PersonKey is null || personContainer.PersonBirthdays is null || !personContainer.PersonBirthdays.Any())
|
||||
continue;
|
||||
person = _PeopleKeyValuePairs[personKey];
|
||||
personBirthday = person.PersonBirthdays[zero];
|
||||
personBirthday = personContainer.PersonBirthdays[zero];
|
||||
personKeyFormatted = IPersonBirthday.GetFormatted(_Configuration.PersonBirthdayFormat, personBirthday);
|
||||
mappingSegmentB = GetMappingSegmentB(_Ticks, personBirthday, person.ApproximateYears, sortingContainer.Face.Mapping.MappingFromItem);
|
||||
mappingSegmentB = GetMappingSegmentB(_Ticks, personBirthday, personContainer.ApproximateYears, sortingContainer.Face.Mapping.MappingFromItem);
|
||||
key = string.Concat(personKeyFormatted, '\t', mappingSegmentB);
|
||||
if (!checkKeyValuePairs.ContainsKey(key))
|
||||
checkKeyValuePairs.Add(key, new());
|
||||
@ -545,7 +501,7 @@ public class MapLogic
|
||||
if (checkCollection.Count > _Configuration.SortingMaximumPerKey)
|
||||
continue;
|
||||
_ = hashSet.Add(sortingContainer.Sorting.NormalizedPixelPercentage);
|
||||
sortingContainer.Face.Mapping.UpdateMappingFromPerson(person.ApproximateYears, by, person.DisplayDirectoryName, personBirthday, mappingSegmentB);
|
||||
sortingContainer.Face.Mapping.UpdateMappingFromPerson(personContainer.ApproximateYears, by, personContainer.PersonDisplayDirectoryName, personBirthday, mappingSegmentB);
|
||||
checkCollection.Add(sortingContainer.Face.Mapping);
|
||||
result += 1;
|
||||
break;
|
||||
@ -562,6 +518,7 @@ public class MapLogic
|
||||
int by = _ForceSingleImage;
|
||||
int? approximateYears = null;
|
||||
PersonBirthday personBirthday;
|
||||
List<int> normalizedPixelPercentages;
|
||||
string displayDirectoryName = propertyConfiguration.ResultAllInOne;
|
||||
Face[] orderedDistinctFilteredFaces = (from l in distinctFilteredFaces orderby l.Mapping is not null, l.Mapping?.MappingFromLocation.Confidence descending select l).ToArray();
|
||||
foreach (Face face in orderedDistinctFilteredFaces)
|
||||
@ -570,6 +527,12 @@ public class MapLogic
|
||||
throw new NotSupportedException();
|
||||
if (face.Mapping.MappingFromPerson.PersonBirthday is not null)
|
||||
continue;
|
||||
if (_SkipCollection.ContainsKey(face.Mapping.MappingFromItem.Id))
|
||||
{
|
||||
normalizedPixelPercentages = _SkipCollection[face.Mapping.MappingFromItem.Id];
|
||||
if (normalizedPixelPercentages.Contains(face.Mapping.MappingFromLocation.NormalizedPixelPercentage))
|
||||
continue;
|
||||
}
|
||||
personKey = _NotMappedPersonKeys[zero];
|
||||
personBirthday = IPersonBirthday.GetPersonBirthday(personKey.Value);
|
||||
mappingSegmentB = GetMappingSegmentB(_Ticks, personBirthday, approximateYears, face.Mapping.MappingFromItem);
|
||||
@ -578,7 +541,7 @@ public class MapLogic
|
||||
}
|
||||
}
|
||||
|
||||
private List<SaveContainer> GetMappingSaveContainers(string dFacesContentDirectory, string d2ResultsFullGroupDirectory, List<Face> filteredFaces)
|
||||
private List<SaveContainer> GetMappingSaveContainers(string dResultsFullGroupDirectory, string d2ResultsFullGroupDirectory, List<Face> filteredFaces)
|
||||
{
|
||||
if (_Configuration is null)
|
||||
throw new NullReferenceException(nameof(_Configuration));
|
||||
@ -598,6 +561,8 @@ public class MapLogic
|
||||
FileHolder facePartsFileHolder;
|
||||
FileHolder hiddenFaceFileHolder;
|
||||
Dictionary<string, int> keyValuePairs = new();
|
||||
string dFacesContentDirectory = Path.Combine(dResultsFullGroupDirectory, "()");
|
||||
string d2FacePartsContentDirectory = Path.Combine(d2ResultsFullGroupDirectory, "()");
|
||||
foreach (Face face in filteredFaces)
|
||||
{
|
||||
if (face.Mapping is null)
|
||||
@ -628,9 +593,6 @@ public class MapLogic
|
||||
if (!keyValuePairs.ContainsKey(directory))
|
||||
keyValuePairs.Add(directory, 0);
|
||||
keyValuePairs[directory]++;
|
||||
saveContainer = new(Path.Combine(directory, "!"));
|
||||
if (face.Mapping.MappingFromPerson.By.HasValue && face.Mapping.MappingFromPerson.By == _Sorting && keyValuePairs[directory] > 3)
|
||||
results.Add(saveContainer);
|
||||
if (face.Mapping.MappingFromPerson.By is not null)
|
||||
personDirectory = Path.Combine(directory, face.Mapping.MappingFromPerson.DisplayDirectoryName, "lnk");
|
||||
else
|
||||
@ -638,7 +600,7 @@ public class MapLogic
|
||||
saveContainer = new(personDirectory);
|
||||
results.Add(saveContainer);
|
||||
facesDirectory = Path.Combine($"{dFacesContentDirectory}{directoryName}", face.Mapping.MappingFromItem.ImageFileHolder.NameWithoutExtension);
|
||||
facePartsDirectory = Path.Combine($"{d2ResultsFullGroupDirectory}{directoryName}", face.Mapping.MappingFromItem.ImageFileHolder.NameWithoutExtension);
|
||||
facePartsDirectory = Path.Combine($"{d2FacePartsContentDirectory}{directoryName}", face.Mapping.MappingFromItem.ImageFileHolder.NameWithoutExtension);
|
||||
checkFile = Path.Combine(directory, $"{face.Mapping.MappingFromLocation.DeterministicHashCodeKey}{face.Mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}");
|
||||
faceFileHolder = new(Path.Combine(facesDirectory, $"{face.Mapping.MappingFromLocation.DeterministicHashCodeKey}{face.Mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}{_FacesFilenameExtension}"));
|
||||
hiddenFaceFileHolder = new(Path.Combine(facesDirectory, $"{face.Mapping.MappingFromLocation.DeterministicHashCodeKey}{face.Mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}{_FacesHiddenFilenameExtension}"));
|
||||
@ -661,96 +623,22 @@ public class MapLogic
|
||||
return results;
|
||||
}
|
||||
|
||||
public void ForceSingleImageThenSaveMapping(int maxDegreeOfParallelism, Property.Models.Configuration propertyConfiguration, string dFacesContentDirectory, string d2ResultsFullGroupDirectory, List<Face> distinctFilteredFaces, SortingContainer[] sortingContainers, int totalNotMapped)
|
||||
public void ForceSingleImageThenSaveMapping(int maxDegreeOfParallelism, Property.Models.Configuration propertyConfiguration, string dResultsFullGroupDirectory, string d2ResultsFullGroupDirectory, List<Face> distinctFilteredFaces, SortingContainer[] sortingContainers, int totalNotMapped)
|
||||
{
|
||||
List<SaveContainer> saveContainers;
|
||||
if (!sortingContainers.Any())
|
||||
{
|
||||
ForceSingleImage(propertyConfiguration, distinctFilteredFaces);
|
||||
saveContainers = GetMappingSaveContainers(dFacesContentDirectory, d2ResultsFullGroupDirectory, distinctFilteredFaces);
|
||||
saveContainers = GetMappingSaveContainers(dResultsFullGroupDirectory, d2ResultsFullGroupDirectory, distinctFilteredFaces);
|
||||
}
|
||||
else
|
||||
{
|
||||
int updated = UpdateFromSortingContainers(sortingContainers);
|
||||
if (totalNotMapped - updated > 0)
|
||||
ForceSingleImage(propertyConfiguration, distinctFilteredFaces);
|
||||
saveContainers = GetMappingSaveContainers(dFacesContentDirectory, d2ResultsFullGroupDirectory, distinctFilteredFaces);
|
||||
saveContainers = GetMappingSaveContainers(dResultsFullGroupDirectory, d2ResultsFullGroupDirectory, distinctFilteredFaces);
|
||||
}
|
||||
SaveContainers(saveContainers);
|
||||
}
|
||||
|
||||
private static double GetStandardDeviation(IEnumerable<long> values, double average)
|
||||
{
|
||||
double result = 0;
|
||||
if (!values.Any())
|
||||
throw new Exception("Collection must have at least one value!");
|
||||
double sum = values.Sum(l => (l - average) * (l - average));
|
||||
result = Math.Sqrt(sum / values.Count());
|
||||
return result;
|
||||
}
|
||||
|
||||
private void SetPersonKeysRanges(Dictionary<long, List<long>> personTicks)
|
||||
{
|
||||
long lcl;
|
||||
long ucl;
|
||||
long maximum;
|
||||
long minimum;
|
||||
double average;
|
||||
long[] collection;
|
||||
double standardDeviation;
|
||||
foreach (KeyValuePair<long, List<long>> keyValuePair in personTicks)
|
||||
{
|
||||
minimum = keyValuePair.Value.Min();
|
||||
if (keyValuePair.Value.Count < 3)
|
||||
{
|
||||
maximum = keyValuePair.Value.Max();
|
||||
_PersonKeysRanges.Add(keyValuePair.Key, new(new DateTime(minimum).AddYears(-1).Ticks, minimum, maximum, new DateTime(maximum).AddYears(1).Ticks));
|
||||
}
|
||||
else
|
||||
{
|
||||
collection = (from l in keyValuePair.Value select l - minimum).ToArray();
|
||||
maximum = collection.Max() + minimum;
|
||||
average = (collection.Sum() / collection.Length) + minimum;
|
||||
standardDeviation = GetStandardDeviation(collection, average);
|
||||
ucl = (long)(average + (standardDeviation * Stateless.IMapLogic.Sigma));
|
||||
lcl = (long)(average - (standardDeviation * Stateless.IMapLogic.Sigma));
|
||||
if (lcl < 0)
|
||||
lcl = 0;
|
||||
if (ucl > 0)
|
||||
ucl = _Ticks;
|
||||
_PersonKeysRanges.Add(keyValuePair.Key, new(lcl, minimum, maximum, ucl));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetPersonTicks(List<Face> distinctFilteredFaces)
|
||||
{
|
||||
PersonBirthday[] personBirthdays;
|
||||
Dictionary<int, PersonBirthday[]> 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)";
|
||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||
using ProgressBar progressBar = new(distinctFilteredFaces.Count, message, options);
|
||||
foreach (Face face in distinctFilteredFaces)
|
||||
{
|
||||
progressBar.Tick();
|
||||
if (face.Mapping is null)
|
||||
throw new NotSupportedException();
|
||||
if (!_IdThenNormalizedPixelPercentageKeyValuePairs.ContainsKey(face.Mapping.MappingFromItem.Id))
|
||||
continue;
|
||||
keyValuePairs = _IdThenNormalizedPixelPercentageKeyValuePairs[face.Mapping.MappingFromItem.Id];
|
||||
if (!keyValuePairs.ContainsKey(face.Mapping.MappingFromLocation.NormalizedPixelPercentage))
|
||||
continue;
|
||||
personBirthdays = keyValuePairs[face.Mapping.MappingFromLocation.NormalizedPixelPercentage];
|
||||
foreach (PersonBirthday personBirthday in personBirthdays)
|
||||
{
|
||||
if (!personTicks.ContainsKey(personBirthday.Value.Ticks))
|
||||
personTicks.Add(personBirthday.Value.Ticks, new());
|
||||
personTicks[personBirthday.Value.Ticks].Add(face.Mapping.MappingFromItem.MinimumDateTime.Ticks);
|
||||
}
|
||||
}
|
||||
SetPersonKeysRanges(personTicks);
|
||||
}
|
||||
|
||||
}
|
@ -1,475 +0,0 @@
|
||||
using ShellProgressBar;
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
using View_by_Distance.Shared.Models;
|
||||
|
||||
namespace View_by_Distance.Map.Models.Stateless;
|
||||
|
||||
public class ByRef
|
||||
{
|
||||
|
||||
private static void SetOther(Property.Models.Configuration propertyConfiguration, Configuration configuration, string resizeFilenameExtension, Person[] people, string a2PeopleContentDirectory, List<double> skipCollection, Dictionary<long, long> personKeyAliases, List<(string, int?, PersonBirthday[], long)> peopleCollection)
|
||||
{
|
||||
long pK;
|
||||
string json;
|
||||
long personKey;
|
||||
PersonBirthday pB;
|
||||
string[] segments;
|
||||
const int zero = 0;
|
||||
int? approximateYears;
|
||||
string groupDirectoryName;
|
||||
string personKeyFormatted;
|
||||
PersonBirthday[] collection;
|
||||
string personKeyJsonFileName;
|
||||
List<long> personKeys = new();
|
||||
string[] personKeyDirectories;
|
||||
string personKeyJsonDirectory;
|
||||
PersonBirthday? personBirthday;
|
||||
string[] personDisplayDirectories;
|
||||
string convertedPersonKeyDirectory;
|
||||
string? personDisplayDirectoryName;
|
||||
List<PersonBirthday> personBirthdays;
|
||||
Dictionary<string, Person> personKeyValuePairs = new();
|
||||
foreach (Person person in people)
|
||||
{
|
||||
personKeyFormatted = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(configuration.PersonBirthdayFormat, person.Birthday);
|
||||
if (personKeyValuePairs.ContainsKey(personKeyFormatted))
|
||||
break;
|
||||
personKeyValuePairs.Add(personKeyFormatted, person);
|
||||
}
|
||||
string[] groupDirectories = Directory.GetDirectories(a2PeopleContentDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string groupDirectory in groupDirectories)
|
||||
{
|
||||
groupDirectoryName = Path.GetFileName(groupDirectory);
|
||||
if (groupDirectoryName[zero] == '!')
|
||||
{
|
||||
skipCollection.AddRange(from l in Directory.GetFiles(groupDirectory, $"*{resizeFilenameExtension}", SearchOption.AllDirectories) select double.Parse(Path.GetFileNameWithoutExtension(l)));
|
||||
continue;
|
||||
}
|
||||
else if (groupDirectoryName[zero] is not '_' and not '~' and not '^')
|
||||
continue;
|
||||
skipCollection.AddRange(from l in Directory.GetFiles(groupDirectory, $"*{resizeFilenameExtension}", SearchOption.AllDirectories) select double.Parse(Path.GetFileNameWithoutExtension(l)));
|
||||
personDisplayDirectories = Directory.GetDirectories(groupDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string personDisplayDirectory in personDisplayDirectories)
|
||||
{
|
||||
personBirthdays = new();
|
||||
personDisplayDirectoryName = Path.GetFileName(personDisplayDirectory);
|
||||
if (string.IsNullOrEmpty(personDisplayDirectoryName))
|
||||
continue;
|
||||
if (groupDirectoryName[zero] != '~')
|
||||
approximateYears = null;
|
||||
else
|
||||
{
|
||||
segments = personDisplayDirectoryName.Split('~');
|
||||
if (segments.Length == 1 || !int.TryParse(segments[1].Split('-')[zero], out int years))
|
||||
approximateYears = null;
|
||||
else
|
||||
approximateYears = years;
|
||||
}
|
||||
personKeyDirectories = Directory.GetDirectories(personDisplayDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string personKeyDirectory in personKeyDirectories)
|
||||
{
|
||||
personKeyFormatted = Path.GetFileName(personKeyDirectory);
|
||||
if (!DateTime.TryParseExact(personKeyFormatted, "MM.dd.yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime birthday))
|
||||
personBirthday = Shared.Models.Stateless.Methods.IPersonBirthday.GetPersonBirthday(configuration.PersonBirthdayFormat, personKeyFormatted);
|
||||
else
|
||||
{
|
||||
personBirthday = new PersonBirthday(birthday);
|
||||
personKeyFormatted = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(configuration.PersonBirthdayFormat, personBirthday);
|
||||
convertedPersonKeyDirectory = Path.Combine(personDisplayDirectory, personKeyFormatted);
|
||||
if (!Directory.Exists(convertedPersonKeyDirectory))
|
||||
Directory.Move(personKeyDirectory, convertedPersonKeyDirectory);
|
||||
}
|
||||
if (personBirthday is null)
|
||||
continue;
|
||||
personBirthdays.Add(personBirthday);
|
||||
}
|
||||
if (!personBirthdays.Any())
|
||||
continue;
|
||||
foreach (string personKeyDirectory in personKeyDirectories)
|
||||
{
|
||||
personKeyFormatted = Path.GetFileName(personKeyDirectory);
|
||||
personBirthday = Shared.Models.Stateless.Methods.IPersonBirthday.GetPersonBirthday(configuration.PersonBirthdayFormat, personKeyFormatted);
|
||||
if (personBirthday is null)
|
||||
continue;
|
||||
if (personKeyValuePairs.ContainsKey(personKeyFormatted))
|
||||
{
|
||||
personKeyJsonDirectory = Path.Combine(personDisplayDirectory, personKeyFormatted);
|
||||
if (!Directory.Exists(personKeyJsonDirectory))
|
||||
Directory.Move(personKeyDirectory, personKeyJsonDirectory);
|
||||
personKeyJsonFileName = Path.Combine(personKeyJsonDirectory, $"{personKeyFormatted}.json");
|
||||
json = JsonSerializer.Serialize(personKeyValuePairs[personKeyFormatted], new JsonSerializerOptions() { WriteIndented = true });
|
||||
_ = Shared.Models.Stateless.Methods.IPath.WriteAllText(personKeyJsonFileName, json, updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null);
|
||||
}
|
||||
collection = personBirthdays.OrderByDescending(l => l.Value).ToArray();
|
||||
personKey = collection[zero].Value.Ticks;
|
||||
if (personBirthdays.Count > 1)
|
||||
{
|
||||
for (int i = 1; i < collection.Length; i++)
|
||||
{
|
||||
pB = collection[i];
|
||||
pK = pB.Value.Ticks;
|
||||
if (!personKeyAliases.ContainsKey(pK))
|
||||
personKeyAliases.Add(pK, personKey);
|
||||
}
|
||||
}
|
||||
peopleCollection.Add(new(personDisplayDirectoryName, approximateYears, collection, personKey));
|
||||
for (int i = 0; i < collection.Length; i++)
|
||||
{
|
||||
personKey = collection[i].Value.Ticks;
|
||||
personKeys.Add(personKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
approximateYears = null;
|
||||
string displayDirectoryName = propertyConfiguration.ResultAllInOne;
|
||||
DateTime incrementDate = new(configuration.PersonBirthdayFirstYear, 1, 1);
|
||||
for (int i = 0; i < 500; i++)
|
||||
{
|
||||
personKey = incrementDate.Ticks;
|
||||
personBirthday = new(incrementDate);
|
||||
incrementDate = incrementDate.AddDays(1);
|
||||
personKeyFormatted = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(configuration.PersonBirthdayFormat, personBirthday);
|
||||
if (personKeys.Contains(personKey))
|
||||
continue;
|
||||
personKeys.Add(personKey);
|
||||
peopleCollection.Add(new(displayDirectoryName, approximateYears, new PersonBirthday[] { personBirthday }, personKey));
|
||||
}
|
||||
}
|
||||
|
||||
internal static List<(string, char, string, int?, int?, List<Face>?)> DeleteEmptyDirectoriesAndGetCollection(Configuration configuration, long ticks, string eDistanceContentDirectory, Dictionary<int, List<Face>> keyValuePairs)
|
||||
{
|
||||
List<(string, char, string, int?, int?, List<Face>?)> results = new();
|
||||
int? id;
|
||||
string[] files;
|
||||
List<Face>? faces;
|
||||
const int zero = 0;
|
||||
string[] yearDirectories;
|
||||
string personKeyFormatted;
|
||||
string ticksDirectoryName;
|
||||
string? personFirstInitial;
|
||||
string[] personKeyDirectories;
|
||||
int? normalizedPixelPercentage;
|
||||
string[] personNameDirectories;
|
||||
string[] personNameLinkDirectories;
|
||||
string? personFirstInitialDirectory;
|
||||
bool keyValuePairsAny = keyValuePairs.Any();
|
||||
int totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds);
|
||||
string[] ticksDirectories = Directory.GetDirectories(eDistanceContentDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
string message = $") {ticksDirectories.Length:000} ticks Director(ies) - A - {totalSeconds} total second(s)";
|
||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||
using ProgressBar progressBar = new(ticksDirectories.Length, message, options);
|
||||
foreach (string ticksDirectory in ticksDirectories)
|
||||
{
|
||||
progressBar.Tick();
|
||||
ticksDirectoryName = Path.GetFileName(ticksDirectory);
|
||||
if (ticksDirectoryName.Length < 3 || ticksDirectoryName[zero] != '(' || ticksDirectoryName[^1] != ')')
|
||||
continue;
|
||||
personKeyDirectories = Directory.GetDirectories(ticksDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string personKeyDirectory in personKeyDirectories)
|
||||
{
|
||||
personKeyFormatted = Path.GetFileName(personKeyDirectory);
|
||||
if (personKeyFormatted.Length != configuration.PersonBirthdayFormat.Length)
|
||||
continue;
|
||||
yearDirectories = Directory.GetDirectories(personKeyDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string yearDirectory in yearDirectories)
|
||||
{
|
||||
files = Directory.GetFiles(yearDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
personNameDirectories = Directory.GetDirectories(yearDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string file in files)
|
||||
File.Delete(file);
|
||||
foreach (string personNameDirectory in personNameDirectories)
|
||||
{
|
||||
personFirstInitial = Path.GetFileName(personNameDirectory)[..1];
|
||||
if (personFirstInitial is null)
|
||||
continue;
|
||||
personFirstInitialDirectory = Path.Combine(yearDirectory, personFirstInitial.ToString());
|
||||
if (personNameDirectory != personFirstInitialDirectory)
|
||||
Directory.Move(personNameDirectory, personFirstInitialDirectory);
|
||||
files = Directory.GetFiles(personFirstInitialDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
if (personKeyFormatted == nameof(Models.MapLogic.ForceSingleImage) && files.Any())
|
||||
throw new Exception($"Move personKey directories up one from {nameof(Models.MapLogic.ForceSingleImage)} and delete {nameof(Models.MapLogic.ForceSingleImage)} directory!");
|
||||
if (personKeyFormatted == nameof(Sorting) && files.Any())
|
||||
throw new Exception($"Move personKey directories up one from {nameof(Sorting)} and delete {nameof(Sorting)} directory!");
|
||||
foreach (string file in files)
|
||||
{
|
||||
if (file.EndsWith(".lnk") || file.EndsWith(".json"))
|
||||
continue;
|
||||
(id, normalizedPixelPercentage, faces) = Shared.Models.Stateless.Methods.IMapping.GetReversedDeterministicHashCodeKey(configuration.LocationDigits, keyValuePairsAny, keyValuePairs, file);
|
||||
if (id is null || normalizedPixelPercentage is null)
|
||||
continue;
|
||||
results.Add(new(personKeyFormatted, personFirstInitial[0], file, id, normalizedPixelPercentage, faces));
|
||||
}
|
||||
personNameLinkDirectories = Directory.GetDirectories(personFirstInitialDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string personNameLinkDirectory in personNameLinkDirectories)
|
||||
{
|
||||
files = Directory.GetFiles(personNameLinkDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string file in files)
|
||||
{
|
||||
if (!file.EndsWith(".lnk"))
|
||||
continue;
|
||||
File.Delete(file);
|
||||
}
|
||||
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(personNameLinkDirectory);
|
||||
}
|
||||
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(personFirstInitialDirectory);
|
||||
}
|
||||
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(yearDirectory);
|
||||
}
|
||||
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(personKeyDirectory);
|
||||
}
|
||||
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(ticksDirectory);
|
||||
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(ticksDirectory);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private static void SetKeyValuePairs(Configuration configuration, List<(PersonBirthday, int, int)> idThenNormalizedPixelPercentageCollection, List<(PersonBirthday, int, int)> incorrectIdThenNormalizedPixelPercentageCollection, Dictionary<int, Dictionary<int, PersonBirthday[]>> idThenNormalizedPixelPercentageKeyValuePairs, Dictionary<int, Dictionary<int, PersonBirthday[]>> incorrectIdThenNormalizedPixelPercentageKeyValuePairs)
|
||||
{
|
||||
string check;
|
||||
int normalizedPixelPercentageInDecimalForm;
|
||||
Dictionary<int, Dictionary<int, List<PersonBirthday>>> idThenNormalizedPixelPercentageScope = new();
|
||||
foreach ((PersonBirthday personBirthday, int id, int normalizedPixelPercentage) in idThenNormalizedPixelPercentageCollection)
|
||||
{
|
||||
if (!idThenNormalizedPixelPercentageScope.ContainsKey(id))
|
||||
idThenNormalizedPixelPercentageScope.Add(id, new());
|
||||
check = normalizedPixelPercentage.ToString();
|
||||
if (check.Length == configuration.LocationDigits)
|
||||
{
|
||||
if (!idThenNormalizedPixelPercentageScope[id].ContainsKey(normalizedPixelPercentage))
|
||||
idThenNormalizedPixelPercentageScope[id].Add(normalizedPixelPercentage, new());
|
||||
idThenNormalizedPixelPercentageScope[id][normalizedPixelPercentage].Add(personBirthday);
|
||||
}
|
||||
else
|
||||
{
|
||||
normalizedPixelPercentageInDecimalForm = int.Parse(check.PadRight(configuration.LocationDigits, '0'));
|
||||
if (!idThenNormalizedPixelPercentageScope[id].ContainsKey(normalizedPixelPercentageInDecimalForm))
|
||||
idThenNormalizedPixelPercentageScope[id].Add(normalizedPixelPercentageInDecimalForm, new());
|
||||
idThenNormalizedPixelPercentageScope[id][normalizedPixelPercentageInDecimalForm].Add(personBirthday);
|
||||
}
|
||||
}
|
||||
foreach (KeyValuePair<int, Dictionary<int, List<PersonBirthday>>> keyValuePair in idThenNormalizedPixelPercentageScope)
|
||||
{
|
||||
idThenNormalizedPixelPercentageKeyValuePairs.Add(keyValuePair.Key, new());
|
||||
foreach (KeyValuePair<int, List<PersonBirthday>> innerKeyValuePair in keyValuePair.Value)
|
||||
idThenNormalizedPixelPercentageKeyValuePairs[keyValuePair.Key].Add(innerKeyValuePair.Key, innerKeyValuePair.Value.Distinct().ToArray());
|
||||
}
|
||||
Dictionary<int, Dictionary<int, List<PersonBirthday>>> incorrectIdThenNormalizedPixelPercentageScope = new();
|
||||
foreach ((PersonBirthday personBirthday, int id, int normalizedPixelPercentage) in incorrectIdThenNormalizedPixelPercentageCollection)
|
||||
{
|
||||
if (!incorrectIdThenNormalizedPixelPercentageScope.ContainsKey(id))
|
||||
incorrectIdThenNormalizedPixelPercentageScope.Add(id, new());
|
||||
check = normalizedPixelPercentage.ToString();
|
||||
if (check.Length == configuration.LocationDigits)
|
||||
{
|
||||
if (!incorrectIdThenNormalizedPixelPercentageScope[id].ContainsKey(normalizedPixelPercentage))
|
||||
incorrectIdThenNormalizedPixelPercentageScope[id].Add(normalizedPixelPercentage, new());
|
||||
incorrectIdThenNormalizedPixelPercentageScope[id][normalizedPixelPercentage].Add(personBirthday);
|
||||
}
|
||||
else
|
||||
{
|
||||
normalizedPixelPercentageInDecimalForm = int.Parse(check.PadRight(configuration.LocationDigits, '0'));
|
||||
if (!incorrectIdThenNormalizedPixelPercentageScope[id].ContainsKey(normalizedPixelPercentageInDecimalForm))
|
||||
incorrectIdThenNormalizedPixelPercentageScope[id].Add(normalizedPixelPercentageInDecimalForm, new());
|
||||
incorrectIdThenNormalizedPixelPercentageScope[id][normalizedPixelPercentageInDecimalForm].Add(personBirthday);
|
||||
}
|
||||
}
|
||||
foreach (KeyValuePair<int, Dictionary<int, List<PersonBirthday>>> keyValuePair in incorrectIdThenNormalizedPixelPercentageScope)
|
||||
{
|
||||
incorrectIdThenNormalizedPixelPercentageKeyValuePairs.Add(keyValuePair.Key, new());
|
||||
foreach (KeyValuePair<int, List<PersonBirthday>> innerKeyValuePair in keyValuePair.Value)
|
||||
incorrectIdThenNormalizedPixelPercentageKeyValuePairs[keyValuePair.Key].Add(innerKeyValuePair.Key, innerKeyValuePair.Value.Distinct().ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
private static string? GetCheckFile(string file, int id, int normalizedPixelPercentage)
|
||||
{
|
||||
string? result;
|
||||
string? fileName = Path.GetFileName(file);
|
||||
if (fileName is null)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
string[] segments = fileName.Split('.');
|
||||
if (segments.Length != 3)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
string extensionLowered = $".{segments[2]}";
|
||||
string? directoryName = Path.GetDirectoryName(file);
|
||||
if (string.IsNullOrEmpty(directoryName))
|
||||
result = null;
|
||||
else
|
||||
result = Path.Combine(directoryName, $"{Shared.Models.Stateless.Methods.IMapping.GetDeterministicHashCodeKey(id, normalizedPixelPercentage)}{extensionLowered}.json");
|
||||
}
|
||||
}
|
||||
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);
|
||||
_ = Shared.Models.Stateless.Methods.IPath.WriteAllText(checkFile, json, updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int SetCollectionsAndGet(Configuration configuration, long ticks, Shared.Models.Methods.IFaceDistance? distance, Dictionary<long, long> personKeyAliases, List<(PersonBirthday, int, int)> idThenNormalizedPixelPercentageCollection, List<(PersonBirthday, int, int)> incorrectIdThenNormalizedPixelPercentageCollection, List<(string, char, string, int?, int?, List<Face>?)> collection)
|
||||
{
|
||||
int result = 0;
|
||||
long personKey;
|
||||
string? checkFile;
|
||||
List<Face> checkFaces = new();
|
||||
PersonBirthday? personBirthday;
|
||||
int totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds);
|
||||
string message = $") {collection.Count:000} 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, char personFirstInitial, string file, int? id, int? normalizedPixelPercentage, List<Face>? faces) in collection)
|
||||
{
|
||||
progressBar.Tick();
|
||||
if (id is null || normalizedPixelPercentage is null)
|
||||
continue;
|
||||
personBirthday = Shared.Models.Stateless.Methods.IPersonBirthday.GetPersonBirthday(configuration.PersonBirthdayFormat, personKeyFormatted);
|
||||
if (personBirthday is null)
|
||||
continue;
|
||||
personKey = personBirthday.Value.Ticks;
|
||||
if (personKeyAliases.ContainsKey(personKey))
|
||||
{
|
||||
personKey = personKeyAliases[personKey];
|
||||
personBirthday = Shared.Models.Stateless.Methods.IPersonBirthday.GetPersonBirthday(personKey);
|
||||
}
|
||||
if (faces is not null)
|
||||
{
|
||||
checkFaces.Clear();
|
||||
foreach (Face face in faces)
|
||||
{
|
||||
if (face.Mapping is null)
|
||||
throw new NotSupportedException();
|
||||
if (normalizedPixelPercentage.Value != face.Mapping.MappingFromLocation.NormalizedPixelPercentage)
|
||||
continue;
|
||||
checkFaces.Add(face);
|
||||
}
|
||||
checkFile = GetCheckFile(file, id.Value, normalizedPixelPercentage.Value);
|
||||
if (string.IsNullOrEmpty(checkFile))
|
||||
{
|
||||
result++;
|
||||
continue;
|
||||
}
|
||||
if (checkFaces.Count != 1 && distance is not null && File.Exists(checkFile))
|
||||
{
|
||||
checkFaces.Clear();
|
||||
checkFaces.AddRange(distance.GetMatchingFaces(configuration.FaceDistanceTolerance, checkFile, faces));
|
||||
}
|
||||
if (!checkFaces.Any())
|
||||
{
|
||||
result++;
|
||||
continue;
|
||||
}
|
||||
if (checkFaces.Count != 1)
|
||||
{
|
||||
result++;
|
||||
continue;
|
||||
}
|
||||
if (!Valid(checkFile, checkFaces))
|
||||
{
|
||||
result++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (personFirstInitial != '!')
|
||||
idThenNormalizedPixelPercentageCollection.Add(new(personBirthday, id.Value, normalizedPixelPercentage.Value));
|
||||
else
|
||||
incorrectIdThenNormalizedPixelPercentageCollection.Add(new(personBirthday, id.Value, normalizedPixelPercentage.Value));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static void Set(Property.Models.Configuration propertyConfiguration, Configuration? configuration, long ticks, string resizeFilenameExtension, Person[] people, string eDistanceContentDirectory, string a2PeopleContentDirectory, List<Face> distinctFilteredFaces, Shared.Models.Methods.IFaceDistance? distance, List<double> skipCollection, Dictionary<long, (string DisplayDirectoryName, int? ApproximateYears, PersonBirthday[] PersonBirthdays, long PersonKey)> peopleKeyValuePairs, List<long> notMappedPersonKeys, Dictionary<int, Dictionary<int, PersonBirthday[]>> idThenNormalizedPixelPercentageKeyValuePairs, Dictionary<int, Dictionary<int, PersonBirthday[]>> incorrectIdThenNormalizedPixelPercentageKeyValuePairs)
|
||||
{
|
||||
if (configuration is null)
|
||||
throw new NullReferenceException(nameof(configuration));
|
||||
Dictionary<long, long> personKeyAliases = new();
|
||||
Dictionary<int, List<Face>> keyValuePairs = new();
|
||||
List<long> notMappedAndNotNamedPersonKeys = new();
|
||||
List<long> notMappedAndWithNamedPersonKeys = new();
|
||||
List<long> idThenNormalizedPixelPercentagePersonKeys = new();
|
||||
List<(string, int?, PersonBirthday[], long)> peopleCollection = new();
|
||||
List<(PersonBirthday, int, int)> idThenNormalizedPixelPercentageCollection = new();
|
||||
List<(PersonBirthday, int, int)> incorrectIdThenNormalizedPixelPercentageCollection = new();
|
||||
SetOther(propertyConfiguration, configuration, resizeFilenameExtension, people, a2PeopleContentDirectory, skipCollection, personKeyAliases, peopleCollection);
|
||||
foreach (Face face in distinctFilteredFaces)
|
||||
{
|
||||
if (face.FaceEncoding is null || face.Location?.NormalizedPixelPercentage is null)
|
||||
throw new NotSupportedException();
|
||||
if (face.Mapping is null)
|
||||
throw new NotSupportedException();
|
||||
if (!keyValuePairs.ContainsKey(face.Mapping.MappingFromItem.Id))
|
||||
keyValuePairs.Add(face.Mapping.MappingFromItem.Id, new());
|
||||
keyValuePairs[face.Mapping.MappingFromItem.Id].Add(face);
|
||||
}
|
||||
List<(string, char, string, int?, int?, List<Face>?)> collection = DeleteEmptyDirectoriesAndGetCollection(configuration, ticks, eDistanceContentDirectory, keyValuePairs);
|
||||
int unableToMatchCount = SetCollectionsAndGet(configuration, ticks, distance, personKeyAliases, idThenNormalizedPixelPercentageCollection, incorrectIdThenNormalizedPixelPercentageCollection, collection);
|
||||
SetKeyValuePairs(configuration, idThenNormalizedPixelPercentageCollection, incorrectIdThenNormalizedPixelPercentageCollection, idThenNormalizedPixelPercentageKeyValuePairs, incorrectIdThenNormalizedPixelPercentageKeyValuePairs);
|
||||
int totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds);
|
||||
string message = $") {collection.Count:000} ticks Director(ies) - C - {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<int, Dictionary<int, PersonBirthday[]>> keyValuePair in idThenNormalizedPixelPercentageKeyValuePairs)
|
||||
{
|
||||
progressBar.Tick();
|
||||
foreach (KeyValuePair<int, PersonBirthday[]> keyValue in keyValuePair.Value)
|
||||
idThenNormalizedPixelPercentagePersonKeys.AddRange(from l in keyValue.Value select l.Value.Ticks);
|
||||
}
|
||||
idThenNormalizedPixelPercentagePersonKeys = idThenNormalizedPixelPercentagePersonKeys.Distinct().ToList();
|
||||
if (peopleCollection.Any())
|
||||
{
|
||||
foreach ((string displayDirectoryName, int? approximateYears, PersonBirthday[] personBirthdays, long personKey) in peopleCollection)
|
||||
{
|
||||
if (peopleKeyValuePairs.ContainsKey(personKey))
|
||||
{
|
||||
if (peopleKeyValuePairs[personKey].DisplayDirectoryName == displayDirectoryName)
|
||||
continue;
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
if (idThenNormalizedPixelPercentagePersonKeys.Contains(personKey))
|
||||
peopleKeyValuePairs.Add(personKey, new(displayDirectoryName, approximateYears, personBirthdays, personKey));
|
||||
else if (string.IsNullOrEmpty(displayDirectoryName) || displayDirectoryName == propertyConfiguration.ResultAllInOne)
|
||||
notMappedAndNotNamedPersonKeys.Add(personKey);
|
||||
else
|
||||
notMappedAndWithNamedPersonKeys.Add(personKey);
|
||||
}
|
||||
}
|
||||
notMappedAndNotNamedPersonKeys.Sort();
|
||||
notMappedAndWithNamedPersonKeys.Sort();
|
||||
notMappedPersonKeys.AddRange(notMappedAndNotNamedPersonKeys);
|
||||
notMappedPersonKeys.AddRange(notMappedAndWithNamedPersonKeys);
|
||||
if (idThenNormalizedPixelPercentagePersonKeys.Any())
|
||||
{
|
||||
int? approximateYears = null;
|
||||
PersonBirthday? personBirthday;
|
||||
string displayDirectoryName = propertyConfiguration.ResultAllInOne;
|
||||
foreach (long personKey in idThenNormalizedPixelPercentagePersonKeys)
|
||||
{
|
||||
if (!peopleKeyValuePairs.ContainsKey(personKey))
|
||||
{
|
||||
personBirthday = Shared.Models.Stateless.Methods.IPersonBirthday.GetPersonBirthday(personKey);
|
||||
peopleKeyValuePairs.Add(personKey, new(displayDirectoryName, approximateYears, new PersonBirthday[] { personBirthday }, personKey));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,664 @@
|
||||
using ShellProgressBar;
|
||||
using System.Text.Json;
|
||||
using View_by_Distance.Shared.Models;
|
||||
using View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
namespace View_by_Distance.Map.Models.Stateless;
|
||||
|
||||
internal abstract class MapLogic
|
||||
{
|
||||
|
||||
private static List<PersonContainer> AddToPersonKeysThenGetNonSpecificPeopleCollection(Property.Models.Configuration propertyConfiguration, Configuration configuration, List<long> personKeys)
|
||||
{
|
||||
List<PersonContainer> results = new();
|
||||
Person person;
|
||||
long personKey;
|
||||
int? approximateYears = null;
|
||||
PersonBirthday personBirthday;
|
||||
PersonContainer personContainer;
|
||||
string[] personDisplayDirectoryAllFiles = Array.Empty<string>();
|
||||
DateTime incrementDate = new(configuration.PersonBirthdayFirstYear, 1, 1);
|
||||
for (int i = 0; i < 500; i++)
|
||||
{
|
||||
personKey = incrementDate.Ticks;
|
||||
incrementDate = incrementDate.AddDays(1);
|
||||
if (personKeys.Contains(personKey))
|
||||
continue;
|
||||
personKeys.Add(personKey);
|
||||
personBirthday = IPersonBirthday.GetPersonBirthday(personKey);
|
||||
person = IPerson.GetPerson(propertyConfiguration.ResultAllInOne, personKey, personBirthday);
|
||||
personContainer = new(approximateYears, person, new PersonBirthday[] { personBirthday }, personDisplayDirectoryAllFiles, propertyConfiguration.ResultAllInOne, personKey);
|
||||
results.Add(personContainer);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private static void SetPersonCollections(Configuration configuration, string resizeFilenameExtension, List<PersonContainer> personContainers, List<long> personKeys, Dictionary<string, string> personKeyFormattedToNewestPersonKeyFormatted, Dictionary<int, List<int>> skipCollection)
|
||||
{
|
||||
int? id;
|
||||
long personKey;
|
||||
string personKeyFormatted;
|
||||
int? normalizedPixelPercentage;
|
||||
string newestPersonKeyFormatted;
|
||||
foreach (PersonContainer personContainer in personContainers)
|
||||
{
|
||||
foreach (string personDisplayDirectoryAllFile in personContainer.PersonDisplayDirectoryAllFiles)
|
||||
{
|
||||
if (Path.GetExtension(personDisplayDirectoryAllFile) != resizeFilenameExtension)
|
||||
continue;
|
||||
(id, normalizedPixelPercentage, _) = IMapping.GetReversedDeterministicHashCodeKey(configuration.LocationDigits, personDisplayDirectoryAllFile);
|
||||
if (id is null || normalizedPixelPercentage is null)
|
||||
continue;
|
||||
if (!skipCollection.ContainsKey(id.Value))
|
||||
skipCollection.Add(id.Value, new());
|
||||
skipCollection[id.Value].Add(normalizedPixelPercentage.Value);
|
||||
}
|
||||
if (personContainer.Person is null || personContainer.PersonKey is null || personContainer.PersonBirthdays is null || !personContainer.PersonBirthdays.Any())
|
||||
continue;
|
||||
foreach (PersonBirthday personBirthday in personContainer.PersonBirthdays)
|
||||
{
|
||||
personKey = personBirthday.Value.Ticks;
|
||||
personKeys.Add(personKey);
|
||||
}
|
||||
if (personContainer.PersonBirthdays.Length > 1)
|
||||
{
|
||||
foreach (PersonBirthday personBirthday in personContainer.PersonBirthdays)
|
||||
{
|
||||
personKeyFormatted = IPersonBirthday.GetFormatted(configuration.PersonBirthdayFormat, personBirthday);
|
||||
newestPersonKeyFormatted = IPersonBirthday.GetFormatted(configuration.PersonBirthdayFormat, personContainer.PersonKey.Value);
|
||||
if (!personKeyFormattedToNewestPersonKeyFormatted.ContainsKey(personKeyFormatted))
|
||||
personKeyFormattedToNewestPersonKeyFormatted.Add(personKeyFormatted, newestPersonKeyFormatted);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static List<(string, char, string, int?, int?, List<Face>?)> DeleteEmptyDirectoriesAndGetCollection(Configuration configuration, long ticks, string eDistanceContentDirectory, Dictionary<int, List<Face>> keyValuePairs)
|
||||
{
|
||||
List<(string, char, string, int?, int?, List<Face>?)> 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;
|
||||
string? personFirstInitial;
|
||||
DirectoryInfo directoryInfo;
|
||||
string[] personKeyDirectories;
|
||||
int? normalizedPixelPercentage;
|
||||
string[] personNameDirectories;
|
||||
string[] personNameLinkDirectories;
|
||||
string? personFirstInitialDirectory;
|
||||
bool keyValuePairsAny = keyValuePairs.Any();
|
||||
int totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds);
|
||||
string[] ticksDirectories = Directory.GetDirectories(eDistanceContentDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
string message = $") {ticksDirectories.Length:000} compile from and clean ticks Director(ies) - A - {totalSeconds} total second(s)";
|
||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||
using ProgressBar progressBar = new(ticksDirectories.Length, message, options);
|
||||
foreach (string ticksDirectory in ticksDirectories)
|
||||
{
|
||||
progressBar.Tick();
|
||||
ticksDirectoryName = Path.GetFileName(ticksDirectory);
|
||||
if (ticksDirectoryName.Length < 3 || ticksDirectoryName[zero] != '(' || ticksDirectoryName[^1] != ')')
|
||||
continue;
|
||||
if (!long.TryParse(ticksDirectoryName[1..^1], out long directoryTicks))
|
||||
{
|
||||
if (!long.TryParse(ticksDirectoryName[1..^4], out directoryTicks))
|
||||
continue;
|
||||
}
|
||||
directoryInfo = new(ticksDirectory);
|
||||
if (directoryInfo.CreationTime.Ticks != directoryTicks)
|
||||
Directory.SetCreationTime(ticksDirectory, new DateTime(directoryTicks));
|
||||
if (directoryInfo.LastWriteTime.Ticks != directoryTicks)
|
||||
Directory.SetLastWriteTime(ticksDirectory, new DateTime(directoryTicks));
|
||||
personKeyDirectories = Directory.GetDirectories(ticksDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string personKeyDirectory in personKeyDirectories)
|
||||
{
|
||||
personKeyFormatted = Path.GetFileName(personKeyDirectory);
|
||||
if (personKeyFormatted.Length != configuration.PersonBirthdayFormat.Length)
|
||||
continue;
|
||||
yearDirectories = Directory.GetDirectories(personKeyDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string yearDirectory in yearDirectories)
|
||||
{
|
||||
files = Directory.GetFiles(yearDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
personNameDirectories = Directory.GetDirectories(yearDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string file in files)
|
||||
File.Delete(file);
|
||||
foreach (string personNameDirectory in personNameDirectories)
|
||||
{
|
||||
personFirstInitial = Path.GetFileName(personNameDirectory)[..1];
|
||||
if (personFirstInitial is null)
|
||||
continue;
|
||||
personFirstInitialDirectory = Path.Combine(yearDirectory, personFirstInitial.ToString());
|
||||
if (personNameDirectory != personFirstInitialDirectory)
|
||||
Directory.Move(personNameDirectory, personFirstInitialDirectory);
|
||||
files = Directory.GetFiles(personFirstInitialDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
if (personKeyFormatted == nameof(Models.MapLogic.ForceSingleImage) && files.Any())
|
||||
throw new Exception($"Move personKey directories up one from {nameof(Models.MapLogic.ForceSingleImage)} and delete {nameof(Models.MapLogic.ForceSingleImage)} directory!");
|
||||
if (personKeyFormatted == nameof(Sorting) && files.Any())
|
||||
throw new Exception($"Move personKey directories up one from {nameof(Sorting)} and delete {nameof(Sorting)} directory!");
|
||||
foreach (string file in files)
|
||||
{
|
||||
if (file.EndsWith(".lnk") || file.EndsWith(".json"))
|
||||
continue;
|
||||
(id, normalizedPixelPercentage, faces) = IMapping.GetReversedDeterministicHashCodeKey(configuration.LocationDigits, keyValuePairsAny, keyValuePairs, 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, personFirstInitial[0], file, id, normalizedPixelPercentage, faces));
|
||||
}
|
||||
personNameLinkDirectories = Directory.GetDirectories(personFirstInitialDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string personNameLinkDirectory in personNameLinkDirectories)
|
||||
{
|
||||
files = Directory.GetFiles(personNameLinkDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string file in files)
|
||||
{
|
||||
if (!file.EndsWith(".lnk"))
|
||||
continue;
|
||||
File.Delete(file);
|
||||
}
|
||||
_ = IPath.DeleteEmptyDirectories(personNameLinkDirectory);
|
||||
}
|
||||
_ = IPath.DeleteEmptyDirectories(personFirstInitialDirectory);
|
||||
}
|
||||
_ = IPath.DeleteEmptyDirectories(yearDirectory);
|
||||
}
|
||||
_ = IPath.DeleteEmptyDirectories(personKeyDirectory);
|
||||
}
|
||||
_ = IPath.DeleteEmptyDirectories(ticksDirectory);
|
||||
_ = IPath.DeleteEmptyDirectories(ticksDirectory);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private static PersonContainer[] GetDistinctPersonContainers(List<PersonContainer> personContainers)
|
||||
{
|
||||
List<PersonContainer> results = new();
|
||||
List<long> distinctCheck = new();
|
||||
foreach (PersonContainer personContainer in personContainers)
|
||||
{
|
||||
if (personContainer.PersonKey is null || distinctCheck.Contains(personContainer.PersonKey.Value))
|
||||
continue;
|
||||
results.Add(personContainer);
|
||||
}
|
||||
return results.ToArray();
|
||||
}
|
||||
|
||||
private static void SetKeyValuePairs(Configuration configuration, long ticks, List<PersonContainer> personContainers, List<Face> distinctFilteredFaces, List<(string, int, int)> personKeyFormattedIdThenNormalizedPixelPercentageCollection, List<(string, int, int)> incorrectPersonKeyFormattedIdThenNormalizedPixelPercentageCollection, Dictionary<long, PersonContainer> personKeyToPersonContainer, Dictionary<int, Dictionary<int, PersonContainer[]>> idThenNormalizedPixelPercentageToPersonContainers, Dictionary<int, Dictionary<int, PersonContainer[]>> incorrectIdThenNormalizedPixelPercentageToPersonContainers, Dictionary<long, (long LCL, long Minimum, long Maximum, long UCL)> personKeyToRanges)
|
||||
{
|
||||
string check;
|
||||
string rightPadded;
|
||||
PersonBirthday? personBirthday;
|
||||
string newestPersonKeyFormatted;
|
||||
PersonContainer[] distinctPersonContainers;
|
||||
int normalizedPixelPercentageInDecimalForm;
|
||||
Dictionary<string, PersonContainer> personKeyFormattedToPersonContainer = new();
|
||||
Dictionary<int, Dictionary<int, List<PersonContainer>>> idThenNormalizedPixelPercentageToPersonContainerCollection = new();
|
||||
Dictionary<int, Dictionary<int, List<PersonContainer>>> incorrectIdThenNormalizedPixelPercentageToPersonContainerCollection = new();
|
||||
foreach (PersonContainer personContainer in personContainers)
|
||||
{
|
||||
if (personContainer.PersonKey is null)
|
||||
continue;
|
||||
if (!personKeyToPersonContainer.ContainsKey(personContainer.PersonKey.Value))
|
||||
personKeyToPersonContainer.Add(personContainer.PersonKey.Value, personContainer);
|
||||
newestPersonKeyFormatted = IPersonBirthday.GetFormatted(configuration.PersonBirthdayFormat, personContainer.PersonKey.Value);
|
||||
if (!personKeyFormattedToPersonContainer.ContainsKey(newestPersonKeyFormatted))
|
||||
personKeyFormattedToPersonContainer.Add(newestPersonKeyFormatted, personContainer);
|
||||
}
|
||||
foreach ((string personKeyFormatted, int id, int normalizedPixelPercentage) in personKeyFormattedIdThenNormalizedPixelPercentageCollection)
|
||||
{
|
||||
personBirthday = IPersonBirthday.GetPersonBirthday(configuration.PersonBirthdayFormat, personKeyFormatted);
|
||||
if (personBirthday is null)
|
||||
continue;
|
||||
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());
|
||||
if (!personKeyFormattedToPersonContainer.ContainsKey(personKeyFormatted))
|
||||
throw new NotSupportedException();
|
||||
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());
|
||||
if (!personKeyFormattedToPersonContainer.ContainsKey(personKeyFormatted))
|
||||
throw new NotSupportedException();
|
||||
idThenNormalizedPixelPercentageToPersonContainerCollection[id][normalizedPixelPercentage].Add(personKeyFormattedToPersonContainer[personKeyFormatted]);
|
||||
}
|
||||
}
|
||||
foreach (KeyValuePair<int, Dictionary<int, List<PersonContainer>>> keyValuePair in idThenNormalizedPixelPercentageToPersonContainerCollection)
|
||||
{
|
||||
idThenNormalizedPixelPercentageToPersonContainers.Add(keyValuePair.Key, new());
|
||||
foreach (KeyValuePair<int, List<PersonContainer>> innerKeyValuePair in keyValuePair.Value)
|
||||
{
|
||||
distinctPersonContainers = GetDistinctPersonContainers(innerKeyValuePair.Value);
|
||||
idThenNormalizedPixelPercentageToPersonContainers[keyValuePair.Key].Add(innerKeyValuePair.Key, distinctPersonContainers);
|
||||
}
|
||||
};
|
||||
SetPersonTicks(ticks, distinctFilteredFaces, personKeyToRanges, idThenNormalizedPixelPercentageToPersonContainers);
|
||||
foreach ((string personKeyFormatted, int id, int normalizedPixelPercentage) in incorrectPersonKeyFormattedIdThenNormalizedPixelPercentageCollection)
|
||||
{
|
||||
personBirthday = IPersonBirthday.GetPersonBirthday(configuration.PersonBirthdayFormat, personKeyFormatted);
|
||||
if (personBirthday is null)
|
||||
continue;
|
||||
if (!incorrectIdThenNormalizedPixelPercentageToPersonContainerCollection.ContainsKey(id))
|
||||
incorrectIdThenNormalizedPixelPercentageToPersonContainerCollection.Add(id, new());
|
||||
check = normalizedPixelPercentage.ToString();
|
||||
if (check.Length == configuration.LocationDigits)
|
||||
{
|
||||
if (!incorrectIdThenNormalizedPixelPercentageToPersonContainerCollection[id].ContainsKey(normalizedPixelPercentage))
|
||||
incorrectIdThenNormalizedPixelPercentageToPersonContainerCollection[id].Add(normalizedPixelPercentage, new());
|
||||
if (!personKeyFormattedToPersonContainer.ContainsKey(personKeyFormatted))
|
||||
throw new NotSupportedException();
|
||||
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());
|
||||
if (!personKeyFormattedToPersonContainer.ContainsKey(personKeyFormatted))
|
||||
throw new NotSupportedException();
|
||||
incorrectIdThenNormalizedPixelPercentageToPersonContainerCollection[id][normalizedPixelPercentage].Add(personKeyFormattedToPersonContainer[personKeyFormatted]);
|
||||
}
|
||||
}
|
||||
foreach (KeyValuePair<int, Dictionary<int, List<PersonContainer>>> keyValuePair in incorrectIdThenNormalizedPixelPercentageToPersonContainerCollection)
|
||||
{
|
||||
incorrectIdThenNormalizedPixelPercentageToPersonContainers.Add(keyValuePair.Key, new());
|
||||
foreach (KeyValuePair<int, List<PersonContainer>> innerKeyValuePair in keyValuePair.Value)
|
||||
{
|
||||
distinctPersonContainers = GetDistinctPersonContainers(innerKeyValuePair.Value);
|
||||
incorrectIdThenNormalizedPixelPercentageToPersonContainers[keyValuePair.Key].Add(innerKeyValuePair.Key, distinctPersonContainers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static string? GetCheckFile(string file, int id, int normalizedPixelPercentage)
|
||||
{
|
||||
string? result;
|
||||
string? fileName = Path.GetFileName(file);
|
||||
if (fileName is null)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
string[] segments = fileName.Split('.');
|
||||
if (segments.Length != 3)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
string extensionLowered = $".{segments[2]}";
|
||||
string? directoryName = Path.GetDirectoryName(file);
|
||||
if (string.IsNullOrEmpty(directoryName))
|
||||
result = null;
|
||||
else
|
||||
result = Path.Combine(directoryName, $"{IMapping.GetDeterministicHashCodeKey(id, normalizedPixelPercentage)}{extensionLowered}.json");
|
||||
}
|
||||
}
|
||||
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;
|
||||
string? fileName = Path.GetFileName(file);
|
||||
string? jsonFileName = Path.GetFileName(jsonFile);
|
||||
if (fileName is null || jsonFileName is null)
|
||||
result = false;
|
||||
else
|
||||
{
|
||||
string? directoryName = Path.GetDirectoryName(jsonFile);
|
||||
string? jsonDirectoryName = Path.GetDirectoryName(jsonFile);
|
||||
if (string.IsNullOrEmpty(directoryName) || string.IsNullOrEmpty(directoryName) || directoryName != jsonDirectoryName || !directoryName.Contains(eDistanceContentDirectory))
|
||||
result = false;
|
||||
else
|
||||
{
|
||||
List<string> directoryNames = new();
|
||||
string? checkDirectoryName = directoryName;
|
||||
for (int i = 0; i < int.MaxValue; i++)
|
||||
{
|
||||
if (string.IsNullOrEmpty(checkDirectoryName))
|
||||
continue;
|
||||
directoryNames.Add(Path.GetFileName(checkDirectoryName));
|
||||
checkDirectoryName = Path.GetDirectoryName(checkDirectoryName);
|
||||
if (string.IsNullOrEmpty(checkDirectoryName))
|
||||
continue;
|
||||
if (checkDirectoryName == eDistanceContentDirectory)
|
||||
break;
|
||||
}
|
||||
if (string.IsNullOrEmpty(checkDirectoryName) || !directoryNames.Any() || !long.TryParse(directoryNames[^1][1..^1], out long directoryTicks))
|
||||
result = false;
|
||||
else
|
||||
{
|
||||
bool jsonFileExists = File.Exists(jsonFile);
|
||||
if (!jsonFileExists)
|
||||
checkDirectoryName = Path.Combine(checkDirectoryName, $"({directoryTicks}.00)");
|
||||
else
|
||||
checkDirectoryName = Path.Combine(checkDirectoryName, $"({directoryTicks}{configuration.FaceDistanceTolerance.ToString()[1..]})");
|
||||
for (int i = directoryNames.Count - 1 - 1; i > -1; i--)
|
||||
checkDirectoryName = Path.Combine(checkDirectoryName, directoryNames[i]);
|
||||
if (!Directory.Exists(checkDirectoryName))
|
||||
_ = Directory.CreateDirectory(checkDirectoryName);
|
||||
File.Move(file, Path.Combine(checkDirectoryName, fileName));
|
||||
if (jsonFileExists)
|
||||
File.Move(jsonFile, Path.Combine(checkDirectoryName, jsonFileName));
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result)
|
||||
{ }
|
||||
}
|
||||
|
||||
private static int SetCollectionsAndGetUnableToMatchCount(Configuration configuration, long ticks, string eDistanceContentDirectory, Shared.Models.Methods.IFaceDistance? distance, Dictionary<string, string> personKeyFormattedToNewestPersonKeyFormatted, List<(string, int, int)> personKeyFormattedIdThenNormalizedPixelPercentageCollection, List<(string, int, int)> incorrectPersonKeyFormattedIdThenNormalizedPixelPercentageCollection, List<(string, char, string, int?, int?, List<Face>?)> collection)
|
||||
{
|
||||
int result = 0;
|
||||
string? checkFile;
|
||||
List<Face> checkFaces = new();
|
||||
string newestPersonKeyFormatted;
|
||||
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, char personFirstInitial, string file, int? id, int? normalizedPixelPercentage, List<Face>? faces) in collection)
|
||||
{
|
||||
progressBar.Tick();
|
||||
if (id is null || normalizedPixelPercentage is null)
|
||||
continue;
|
||||
if (faces is null)
|
||||
result++;
|
||||
else
|
||||
{
|
||||
checkFaces.Clear();
|
||||
foreach (Face face in faces)
|
||||
{
|
||||
if (face.Mapping is null)
|
||||
throw new NotSupportedException();
|
||||
if (normalizedPixelPercentage.Value != face.Mapping.MappingFromLocation.NormalizedPixelPercentage)
|
||||
continue;
|
||||
checkFaces.Add(face);
|
||||
}
|
||||
checkFile = GetCheckFile(file, id.Value, normalizedPixelPercentage.Value);
|
||||
if (string.IsNullOrEmpty(checkFile))
|
||||
{
|
||||
result++;
|
||||
continue;
|
||||
}
|
||||
if (checkFaces.Count != 1 && distance is not null && File.Exists(checkFile))
|
||||
{
|
||||
checkFaces.Clear();
|
||||
checkFaces.AddRange(distance.GetMatchingFaces(configuration.FaceDistanceTolerance, checkFile, faces));
|
||||
}
|
||||
if (!checkFaces.Any())
|
||||
{
|
||||
result++;
|
||||
if (configuration.MappingMoveUnableToMatch)
|
||||
MoveUnableToMatch(configuration, eDistanceContentDirectory, file, checkFile);
|
||||
continue;
|
||||
}
|
||||
if (checkFaces.Count != 1)
|
||||
{
|
||||
result++;
|
||||
if (configuration.MappingMoveUnableToMatch)
|
||||
MoveUnableToMatch(configuration, eDistanceContentDirectory, file, checkFile);
|
||||
continue;
|
||||
}
|
||||
if (!Valid(checkFile, checkFaces))
|
||||
{
|
||||
result++;
|
||||
if (configuration.MappingMoveUnableToMatch)
|
||||
MoveUnableToMatch(configuration, eDistanceContentDirectory, file, checkFile);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (!personKeyFormattedToNewestPersonKeyFormatted.ContainsKey(personKeyFormatted))
|
||||
newestPersonKeyFormatted = personKeyFormatted;
|
||||
else
|
||||
newestPersonKeyFormatted = personKeyFormattedToNewestPersonKeyFormatted[personKeyFormatted];
|
||||
if (personFirstInitial != '!')
|
||||
personKeyFormattedIdThenNormalizedPixelPercentageCollection.Add(new(newestPersonKeyFormatted, id.Value, normalizedPixelPercentage.Value));
|
||||
else
|
||||
incorrectPersonKeyFormattedIdThenNormalizedPixelPercentageCollection.Add(new(newestPersonKeyFormatted, id.Value, normalizedPixelPercentage.Value));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static double GetStandardDeviation(IEnumerable<long> values, double average)
|
||||
{
|
||||
double result = 0;
|
||||
if (!values.Any())
|
||||
throw new Exception("Collection must have at least one value!");
|
||||
double sum = values.Sum(l => (l - average) * (l - average));
|
||||
result = Math.Sqrt(sum / values.Count());
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void SetPersonKeysRanges(long ticks, Dictionary<long, List<long>> personTicks, Dictionary<long, (long LCL, long Minimum, long Maximum, long UCL)> personKeyToRanges)
|
||||
{
|
||||
long lcl;
|
||||
long ucl;
|
||||
long maximum;
|
||||
long minimum;
|
||||
double average;
|
||||
long[] collection;
|
||||
double standardDeviation;
|
||||
foreach (KeyValuePair<long, List<long>> keyValuePair in personTicks)
|
||||
{
|
||||
minimum = keyValuePair.Value.Min();
|
||||
if (keyValuePair.Value.Count < 3)
|
||||
{
|
||||
maximum = keyValuePair.Value.Max();
|
||||
personKeyToRanges.Add(keyValuePair.Key, new(new DateTime(minimum).AddYears(-1).Ticks, minimum, maximum, new DateTime(maximum).AddYears(1).Ticks));
|
||||
}
|
||||
else
|
||||
{
|
||||
collection = (from l in keyValuePair.Value select l - minimum).ToArray();
|
||||
maximum = collection.Max() + minimum;
|
||||
average = (collection.Sum() / collection.Length) + minimum;
|
||||
standardDeviation = GetStandardDeviation(collection, average);
|
||||
ucl = (long)(average + (standardDeviation * IMapLogic.Sigma));
|
||||
lcl = (long)(average - (standardDeviation * IMapLogic.Sigma));
|
||||
if (lcl < 0)
|
||||
lcl = 0;
|
||||
if (ucl > 0)
|
||||
ucl = ticks;
|
||||
personKeyToRanges.Add(keyValuePair.Key, new(lcl, minimum, maximum, ucl));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
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)";
|
||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||
using ProgressBar progressBar = new(distinctFilteredFaces.Count, message, options);
|
||||
foreach (Face face in distinctFilteredFaces)
|
||||
{
|
||||
progressBar.Tick();
|
||||
if (face.Mapping is null)
|
||||
throw new NotSupportedException();
|
||||
if (!idThenNormalizedPixelPercentageToPersonContainers.ContainsKey(face.Mapping.MappingFromItem.Id))
|
||||
continue;
|
||||
keyValuePairs = idThenNormalizedPixelPercentageToPersonContainers[face.Mapping.MappingFromItem.Id];
|
||||
if (!keyValuePairs.ContainsKey(face.Mapping.MappingFromLocation.NormalizedPixelPercentage))
|
||||
continue;
|
||||
personContainers = keyValuePairs[face.Mapping.MappingFromLocation.NormalizedPixelPercentage];
|
||||
foreach (PersonContainer personContainer in personContainers)
|
||||
{
|
||||
if (personContainer.PersonKey is null)
|
||||
continue;
|
||||
if (!personTicks.ContainsKey(personContainer.PersonKey.Value))
|
||||
personTicks.Add(personContainer.PersonKey.Value, new());
|
||||
personTicks[personContainer.PersonKey.Value].Add(face.Mapping.MappingFromItem.MinimumDateTime.Ticks);
|
||||
}
|
||||
}
|
||||
SetPersonKeysRanges(ticks, personTicks, personKeyToRanges);
|
||||
}
|
||||
|
||||
private static List<long> GetNotMappedPersonKeys(Property.Models.Configuration propertyConfiguration, List<PersonContainer> personContainers, long[] personKeyCollection)
|
||||
{
|
||||
List<long> results = new();
|
||||
List<long> notMappedAndNotNamedPersonKeys = new();
|
||||
List<long> notMappedAndWithNamedPersonKeys = new();
|
||||
foreach (PersonContainer personContainer in personContainers)
|
||||
{
|
||||
if (personContainer.Person is null || personContainer.PersonKey is null || personContainer.PersonBirthdays is null || !personContainer.PersonBirthdays.Any())
|
||||
continue;
|
||||
if (personKeyCollection.Contains(personContainer.PersonKey.Value))
|
||||
continue;
|
||||
else if (string.IsNullOrEmpty(personContainer.PersonDisplayDirectoryName) || personContainer.PersonDisplayDirectoryName == propertyConfiguration.ResultAllInOne)
|
||||
notMappedAndNotNamedPersonKeys.Add(personContainer.PersonKey.Value);
|
||||
else
|
||||
notMappedAndWithNamedPersonKeys.Add(personContainer.PersonKey.Value);
|
||||
}
|
||||
notMappedAndNotNamedPersonKeys.Sort();
|
||||
notMappedAndWithNamedPersonKeys.Sort();
|
||||
results.AddRange(notMappedAndNotNamedPersonKeys);
|
||||
results.AddRange(notMappedAndWithNamedPersonKeys);
|
||||
return results;
|
||||
}
|
||||
|
||||
private static void AppendToSkipCollection(Dictionary<int, List<int>> skipCollection, Dictionary<int, Dictionary<int, PersonContainer[]>> idThenNormalizedPixelPercentageToPersonContainers, Dictionary<int, Dictionary<int, PersonContainer[]>> incorrectIdThenNormalizedPixelPercentageToPersonContainers)
|
||||
{
|
||||
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[keyValuePair.Key].ContainsKey(keyValuePair.Value.ElementAt(0).Key))
|
||||
continue;
|
||||
}
|
||||
skipCollection[keyValuePair.Key].AddRange(from l in keyValuePair.Value.Keys select l);
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetPersonKeyToPersonContainer(Property.Models.Configuration propertyConfiguration, List<PersonContainer> personContainers, long[] personKeyCollection, Dictionary<long, PersonContainer> personKeyToPersonContainer)
|
||||
{
|
||||
foreach (PersonContainer personContainer in personContainers)
|
||||
{
|
||||
if (personContainer.PersonKey is null || !personKeyCollection.Contains(personContainer.PersonKey.Value))
|
||||
continue;
|
||||
if (personKeyToPersonContainer.ContainsKey(personContainer.PersonKey.Value))
|
||||
{
|
||||
if (personKeyToPersonContainer[personContainer.PersonKey.Value].PersonDisplayDirectoryName == personContainer.PersonDisplayDirectoryName)
|
||||
continue;
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
personKeyToPersonContainer.Add(personContainer.PersonKey.Value, personContainer);
|
||||
}
|
||||
if (personKeyCollection.Any())
|
||||
{
|
||||
int? approximateYears = null;
|
||||
PersonBirthday? personBirthday;
|
||||
PersonContainer personContainer;
|
||||
string displayDirectoryName = propertyConfiguration.ResultAllInOne;
|
||||
foreach (long personKey in personKeyCollection)
|
||||
{
|
||||
if (personKeyToPersonContainer.ContainsKey(personKey))
|
||||
continue;
|
||||
personBirthday = IPersonBirthday.GetPersonBirthday(personKey);
|
||||
personContainer = new(approximateYears, personBirthday, displayDirectoryName, personKey);
|
||||
personKeyToPersonContainer.Add(personKey, personContainer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static void Set(Property.Models.Configuration propertyConfiguration, Configuration? configuration, string resizeFilenameExtension, long ticks, List<PersonContainer> personContainers, string eDistanceContentDirectory, List<Face> distinctFilteredFaces, Shared.Models.Methods.IFaceDistance? distance, Dictionary<long, PersonContainer> personKeyToPersonContainer, Dictionary<long, (long LCL, long Minimum, long Maximum, long UCL)> personKeyToRanges, List<long> notMappedPersonKeys, Dictionary<int, List<int>> skipCollection, Dictionary<int, Dictionary<int, PersonContainer[]>> idThenNormalizedPixelPercentageToPersonContainers)
|
||||
{
|
||||
if (configuration is null)
|
||||
throw new NullReferenceException(nameof(configuration));
|
||||
List<long> personKeys = new();
|
||||
List<long?> nullablePersonKeyCollection = new();
|
||||
Dictionary<int, List<Face>> keyValuePairs = new();
|
||||
Dictionary<string, string> personKeyFormattedToNewestPersonKeyFormatted = new();
|
||||
List<(string, int, int)> personKeyFormattedIdThenNormalizedPixelPercentageCollection = new();
|
||||
List<(string, int, int)> incorrectPersonKeyFormattedIdThenNormalizedPixelPercentageCollection = new();
|
||||
Dictionary<int, Dictionary<int, PersonContainer[]>> incorrectIdThenNormalizedPixelPercentageToPersonContainers = new();
|
||||
SetPersonCollections(configuration, resizeFilenameExtension, personContainers, personKeys, personKeyFormattedToNewestPersonKeyFormatted, skipCollection);
|
||||
personContainers.AddRange(AddToPersonKeysThenGetNonSpecificPeopleCollection(propertyConfiguration, configuration, personKeys));
|
||||
foreach (Face face in distinctFilteredFaces)
|
||||
{
|
||||
if (face.FaceEncoding is null || face.Location?.NormalizedPixelPercentage is null)
|
||||
throw new NotSupportedException();
|
||||
if (face.Mapping is null)
|
||||
throw new NotSupportedException();
|
||||
if (!keyValuePairs.ContainsKey(face.Mapping.MappingFromItem.Id))
|
||||
keyValuePairs.Add(face.Mapping.MappingFromItem.Id, new());
|
||||
keyValuePairs[face.Mapping.MappingFromItem.Id].Add(face);
|
||||
}
|
||||
List<(string, char, string, int?, int?, List<Face>?)> collection = DeleteEmptyDirectoriesAndGetCollection(configuration, ticks, eDistanceContentDirectory, keyValuePairs);
|
||||
int unableToMatchCount = SetCollectionsAndGetUnableToMatchCount(configuration, ticks, eDistanceContentDirectory, distance, personKeyFormattedToNewestPersonKeyFormatted, personKeyFormattedIdThenNormalizedPixelPercentageCollection, incorrectPersonKeyFormattedIdThenNormalizedPixelPercentageCollection, collection);
|
||||
SetKeyValuePairs(configuration, ticks, personContainers, distinctFilteredFaces, personKeyFormattedIdThenNormalizedPixelPercentageCollection, incorrectPersonKeyFormattedIdThenNormalizedPixelPercentageCollection, personKeyToPersonContainer, idThenNormalizedPixelPercentageToPersonContainers, incorrectIdThenNormalizedPixelPercentageToPersonContainers, personKeyToRanges);
|
||||
int totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds);
|
||||
string message = $") {collection.Count:000} message from ticks Director(ies) - C - {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<int, Dictionary<int, PersonContainer[]>> keyValuePair in idThenNormalizedPixelPercentageToPersonContainers)
|
||||
{
|
||||
progressBar.Tick();
|
||||
foreach (KeyValuePair<int, PersonContainer[]> keyValue in keyValuePair.Value)
|
||||
nullablePersonKeyCollection.AddRange(from l in keyValue.Value select l.PersonKey);
|
||||
}
|
||||
}
|
||||
long[] personKeyCollection = (from l in nullablePersonKeyCollection where l is not null select l.Value).Distinct().ToArray();
|
||||
notMappedPersonKeys.AddRange(GetNotMappedPersonKeys(propertyConfiguration, personContainers, personKeyCollection));
|
||||
SetPersonKeyToPersonContainer(propertyConfiguration, personContainers, personKeyCollection, personKeyToPersonContainer);
|
||||
AppendToSkipCollection(skipCollection, idThenNormalizedPixelPercentageToPersonContainers, incorrectIdThenNormalizedPixelPercentageToPersonContainers);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user