Change to support 7680 x 4320 and
Configuration additions
This commit is contained in:
80
Map/Models/Configuration.cs
Normal file
80
Map/Models/Configuration.cs
Normal file
@ -0,0 +1,80 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace View_by_Distance.Map.Models;
|
||||
|
||||
public class Configuration
|
||||
{
|
||||
|
||||
public int FaceDistanceHiddenImageFactor { init; get; }
|
||||
public int FaceDistancePermyriad { init; get; }
|
||||
public double FaceDistanceMinimumConfidence { init; get; }
|
||||
public double FaceDistanceTolerance { init; get; }
|
||||
public int LocationDigits { init; get; }
|
||||
public int LocationFactor { init; get; }
|
||||
public int MapLogicSigma { init; get; }
|
||||
public bool MappingSaveFaceEncoding { init; get; }
|
||||
public bool MappingSaveMapped { init; get; }
|
||||
public bool MappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToMapping { init; get; }
|
||||
public bool MappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForSaveMapping { init; get; }
|
||||
public int PersonBirthdayFirstYear { init; get; }
|
||||
public string PersonBirthdayFormat { init; get; }
|
||||
public string PersonKeyFormat { init; get; }
|
||||
public int SortingDaysDeltaTolerance { init; get; }
|
||||
public int SortingFacesToSkipAfterSortBeforeLoad { init; get; }
|
||||
public int SortingFacesToTakeAfterSortBeforeLoad { init; get; }
|
||||
public int SortingMaximumPerFaceShouldBeHigh { init; get; }
|
||||
public int SortingMaximumPerKey { init; get; }
|
||||
public int SortingSigma { init; get; }
|
||||
|
||||
[JsonConstructor]
|
||||
public Configuration(int faceDistanceHiddenImageFactor,
|
||||
int faceDistancePermyriad,
|
||||
double faceDistanceMinimumConfidence,
|
||||
double faceDistanceTolerance,
|
||||
int locationDigits,
|
||||
int locationFactor,
|
||||
int mapLogicSigma,
|
||||
bool mappingSaveFaceEncoding,
|
||||
bool mappingSaveMapped,
|
||||
bool mappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToMapping,
|
||||
bool mappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForSaveMapping,
|
||||
int personBirthdayFirstYear,
|
||||
string personBirthdayFormat,
|
||||
string personKeyFormat,
|
||||
int sortingDaysDeltaTolerance,
|
||||
int sortingFacesToSkipAfterSortBeforeLoad,
|
||||
int sortingFacesToTakeAfterSortBeforeLoad,
|
||||
int sortingMaximumPerFaceShouldBeHigh,
|
||||
int sortingMaximumPerKey,
|
||||
int sortingSigma)
|
||||
{
|
||||
FaceDistanceHiddenImageFactor = faceDistanceHiddenImageFactor;
|
||||
FaceDistancePermyriad = faceDistancePermyriad;
|
||||
FaceDistanceMinimumConfidence = faceDistanceMinimumConfidence;
|
||||
FaceDistanceTolerance = faceDistanceTolerance;
|
||||
LocationDigits = locationDigits;
|
||||
LocationFactor = locationFactor;
|
||||
MapLogicSigma = mapLogicSigma;
|
||||
MappingSaveFaceEncoding = mappingSaveFaceEncoding;
|
||||
MappingSaveMapped = mappingSaveMapped;
|
||||
MappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToMapping = mappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToMapping;
|
||||
MappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForSaveMapping = mappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForSaveMapping;
|
||||
PersonBirthdayFirstYear = personBirthdayFirstYear;
|
||||
PersonBirthdayFormat = personBirthdayFormat;
|
||||
PersonKeyFormat = personKeyFormat;
|
||||
SortingDaysDeltaTolerance = sortingDaysDeltaTolerance;
|
||||
SortingFacesToSkipAfterSortBeforeLoad = sortingFacesToSkipAfterSortBeforeLoad;
|
||||
SortingFacesToTakeAfterSortBeforeLoad = sortingFacesToTakeAfterSortBeforeLoad;
|
||||
SortingMaximumPerFaceShouldBeHigh = sortingMaximumPerFaceShouldBeHigh;
|
||||
SortingMaximumPerKey = sortingMaximumPerKey;
|
||||
SortingSigma = sortingSigma;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
using ShellProgressBar;
|
||||
using System.Text.Json;
|
||||
using View_by_Distance.Property.Models;
|
||||
using View_by_Distance.Shared.Models;
|
||||
using View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
using WindowsShortcutFactory;
|
||||
@ -23,8 +22,12 @@ public class MapLogic
|
||||
public Dictionary<int, int[]> IndicesFromNew => _IndicesFromNew;
|
||||
|
||||
private readonly long _Ticks;
|
||||
private const int _Mapping = 1;
|
||||
private const int _Sorting = 2;
|
||||
private Configuration? _Configuration;
|
||||
private readonly Serilog.ILogger? _Log;
|
||||
private readonly Configuration _Configuration;
|
||||
private const int _ForceSingleImage = 3;
|
||||
private readonly int _MaxDegreeOfParallelism;
|
||||
private readonly string _FacesFilenameExtension;
|
||||
private readonly string _ResizeFilenameExtension;
|
||||
private readonly string _FacePartsFilenameExtension;
|
||||
@ -32,18 +35,21 @@ public class MapLogic
|
||||
private readonly string _ZPropertyHolderContentDirectory;
|
||||
private readonly string _ZPropertyHolderContentTicksDirectory;
|
||||
private readonly string _ZPropertyHolderSingletonTicksDirectory;
|
||||
private readonly Property.Models.Configuration _PropertyConfiguration;
|
||||
|
||||
public MapLogic(int maxDegreeOfParallelism, Configuration configuration, string resizeFilenameExtension, string facesFilenameExtension, string facesHiddenFilenameExtension, string facePartsFilenameExtension, long ticks, Person[] people, string peopleDateGroupDirectory, string zResultsFullGroupDirectory)
|
||||
public MapLogic(int maxDegreeOfParallelism, Property.Models.Configuration propertyConfiguration, string resizeFilenameExtension, string facesFilenameExtension, string facesHiddenFilenameExtension, string facePartsFilenameExtension, long ticks, Person[] people, string peopleDateGroupDirectory, string zResultsFullGroupDirectory, Configuration? configuration, List<Face> distinctFilteredFaces, Shared.Models.Methods.IFaceDistance? distance)
|
||||
{
|
||||
_Ticks = ticks;
|
||||
_PersonKeysRanges = new();
|
||||
_Configuration = configuration;
|
||||
_Log = Serilog.Log.ForContext<MapLogic>();
|
||||
_PropertyConfiguration = propertyConfiguration;
|
||||
_FacesFilenameExtension = facesFilenameExtension;
|
||||
_MaxDegreeOfParallelism = maxDegreeOfParallelism;
|
||||
_ResizeFilenameExtension = resizeFilenameExtension;
|
||||
_FacePartsFilenameExtension = facePartsFilenameExtension;
|
||||
_FacesHiddenFilenameExtension = facesHiddenFilenameExtension;
|
||||
if (configuration.VerifyToSeason is null || !configuration.VerifyToSeason.Any())
|
||||
if (propertyConfiguration.VerifyToSeason is null || !propertyConfiguration.VerifyToSeason.Any())
|
||||
throw new Exception();
|
||||
string json;
|
||||
string[] files;
|
||||
@ -54,7 +60,7 @@ public class MapLogic
|
||||
Dictionary<int, int[]>? keyValuePairs;
|
||||
List<KeyValuePair<int, int[]>>? collection;
|
||||
Dictionary<int, int[]> indicesFromNew = new();
|
||||
string? rootDirectoryParent = Path.GetDirectoryName(configuration.RootDirectory);
|
||||
string? rootDirectoryParent = Path.GetDirectoryName(propertyConfiguration.RootDirectory);
|
||||
Dictionary<long, (string, int?, PersonBirthday[], long)> peopleKeyValuePairs = new();
|
||||
string zPropertyHolderContentDirectory = Path.Combine(zResultsFullGroupDirectory, "()");
|
||||
string zPropertyHolderSingletonDirectory = Path.Combine(zResultsFullGroupDirectory, "{}");
|
||||
@ -72,7 +78,7 @@ public class MapLogic
|
||||
_ = Directory.CreateDirectory(zPropertyHolderContentDirectory);
|
||||
if (!Directory.Exists(zPropertyHolderPeopleContentDirectory))
|
||||
_ = Directory.CreateDirectory(zPropertyHolderPeopleContentDirectory);
|
||||
Stateless.ByDeterministicHashCode.SetByRef(maxDegreeOfParallelism, ticks, _ResizeFilenameExtension, people, skipCollection, peopleKeyValuePairs, notMappedTicks, idThenNormalizedPixelPercentageKeyValuePairs, incorrectIdThenNormalizedPixelPercentageKeyValuePairs, zPropertyHolderContentDirectory, zPropertyHolderPeopleContentDirectory);
|
||||
Stateless.ByRef.Set(propertyConfiguration, configuration, ticks, _ResizeFilenameExtension, people, zPropertyHolderContentDirectory, zPropertyHolderPeopleContentDirectory, distinctFilteredFaces, distance, skipCollection, peopleKeyValuePairs, notMappedTicks, idThenNormalizedPixelPercentageKeyValuePairs, incorrectIdThenNormalizedPixelPercentageKeyValuePairs);
|
||||
if (!Directory.Exists(zPropertyHolderContentTicksDirectory))
|
||||
_ = Directory.CreateDirectory(zPropertyHolderContentTicksDirectory);
|
||||
files = Directory.GetFiles(rootDirectoryParent, "*keyValuePairs-6*.json", SearchOption.TopDirectoryOnly);
|
||||
@ -85,10 +91,10 @@ public class MapLogic
|
||||
if (keyValuePairs is null)
|
||||
throw new NullReferenceException(nameof(keyValuePairs));
|
||||
}
|
||||
foreach (string propertyContentCollectionFile in configuration.PropertyContentCollectionFiles)
|
||||
foreach (string propertyContentCollectionFile in propertyConfiguration.PropertyContentCollectionFiles)
|
||||
{
|
||||
fullPath = Path.GetFullPath(string.Concat(rootDirectoryParent, propertyContentCollectionFile));
|
||||
if (fullPath.Contains(configuration.RootDirectory))
|
||||
if (fullPath.Contains(propertyConfiguration.RootDirectory))
|
||||
continue;
|
||||
if (!File.Exists(fullPath))
|
||||
continue;
|
||||
@ -115,8 +121,12 @@ public class MapLogic
|
||||
_IncorrectIdThenNormalizedPixelPercentageKeyValuePairs = incorrectIdThenNormalizedPixelPercentageKeyValuePairs;
|
||||
}
|
||||
|
||||
public MapLogic(int maxDegreeOfParallelism, Configuration configuration, string outputExtension, long ticks, Person[] people, string peopleDateGroupDirectory, string zResultsFullGroupDirectory) :
|
||||
this(maxDegreeOfParallelism, configuration, outputExtension, outputExtension, outputExtension, outputExtension, ticks, people, peopleDateGroupDirectory, zResultsFullGroupDirectory)
|
||||
public MapLogic(int maxDegreeOfParallelism, Property.Models.Configuration propertyConfiguration, string resizeFilenameExtension, string facesFilenameExtension, string facesHiddenFilenameExtension, string facePartsFilenameExtension, long ticks, Person[] people, string peopleDateGroupDirectory, string zResultsFullGroupDirectory) :
|
||||
this(maxDegreeOfParallelism, propertyConfiguration, resizeFilenameExtension, facesFilenameExtension, facesHiddenFilenameExtension, facePartsFilenameExtension, ticks, people, peopleDateGroupDirectory, zResultsFullGroupDirectory, null, new(), null)
|
||||
{ }
|
||||
|
||||
public MapLogic(int maxDegreeOfParallelism, Property.Models.Configuration propertyConfiguration, string outputExtension, long ticks, Person[] people, string peopleDateGroupDirectory, string zResultsFullGroupDirectory) :
|
||||
this(maxDegreeOfParallelism, propertyConfiguration, outputExtension, outputExtension, outputExtension, outputExtension, ticks, people, peopleDateGroupDirectory, zResultsFullGroupDirectory, null, new(), null)
|
||||
{ }
|
||||
|
||||
public override string ToString()
|
||||
@ -125,6 +135,8 @@ public class MapLogic
|
||||
return result;
|
||||
}
|
||||
|
||||
public void Update(Configuration configuration) => _Configuration = configuration;
|
||||
|
||||
public bool Skip(double deterministicHashCodeKey) => _SkipCollection.Contains(deterministicHashCodeKey);
|
||||
|
||||
private long LogDelta(long ticks, string? methodName)
|
||||
@ -154,6 +166,8 @@ public class MapLogic
|
||||
|
||||
public List<Sorting> GetSortingCollection(int i, FaceDistance faceDistanceEncoding, List<FaceDistance> faceDistanceLengths, bool anyLowerThanTolerance)
|
||||
{
|
||||
if (_Configuration is null)
|
||||
throw new NullReferenceException(nameof(_Configuration));
|
||||
List<Sorting> results = new();
|
||||
Sorting sorting;
|
||||
FaceDistance faceDistanceLength;
|
||||
@ -180,7 +194,7 @@ public class MapLogic
|
||||
if (!keyValuePairs.ContainsKey(faceDistanceLength.NormalizedPixelPercentage.Value))
|
||||
continue;
|
||||
personKeysRangesCollection = GetPersonKeysRangesCollection(keyValuePairs[faceDistanceLength.NormalizedPixelPercentage.Value]);
|
||||
sorting = ISorting.Get(Shared.Models.Stateless.IFaceDistance.Permyriad, Shared.Models.Stateless.IFaceDistance.Tolerance, faceDistanceEncoding, faceDistanceLength, anyLowerThanTolerance, personKeysRangesCollection);
|
||||
sorting = ISorting.Get(_Configuration.FaceDistancePermyriad, _Configuration.FaceDistanceTolerance, faceDistanceEncoding, faceDistanceLength, anyLowerThanTolerance, personKeysRangesCollection);
|
||||
if (sorting.DistancePermyriad == 0)
|
||||
continue;
|
||||
if (sorting.Id == faceDistanceEncoding.Id)
|
||||
@ -196,6 +210,8 @@ public class MapLogic
|
||||
|
||||
public void SaveShortcuts(string[] juliePhares, List<Face> distinctFilteredFaces)
|
||||
{
|
||||
if (_Configuration is null)
|
||||
throw new NullReferenceException(nameof(_Configuration));
|
||||
string fileName;
|
||||
string fullName;
|
||||
string personKeyFormatted;
|
||||
@ -210,7 +226,7 @@ public class MapLogic
|
||||
if (face.Mapping is null)
|
||||
throw new NotSupportedException();
|
||||
personBirthday = IPersonBirthday.GetPersonBirthday(personKey.Value);
|
||||
personKeyFormatted = IPersonBirthday.GetFormatted(Shared.Models.Stateless.IPersonBirthday.Format, personBirthday);
|
||||
personKeyFormatted = IPersonBirthday.GetFormatted(_Configuration.PersonBirthdayFormat, personBirthday);
|
||||
if (juliePhares.Contains(personKeyFormatted) && !string.IsNullOrEmpty(copyDirectory))
|
||||
{
|
||||
if (!Directory.Exists(copyDirectory))
|
||||
@ -241,25 +257,6 @@ public class MapLogic
|
||||
}
|
||||
}
|
||||
|
||||
private void UseKeyValuePairsSaveFaceEncoding(int maxDegreeOfParallelism, SortingContainer[] sortingContainers)
|
||||
{
|
||||
Dictionary<long, long> personKeyAliases = new();
|
||||
Dictionary<int, List<Face>> keyValuePairs = new();
|
||||
List<(PersonBirthday, int, int)> idThenNormalizedPixelPercentageCollection = new();
|
||||
List<(PersonBirthday, int, int)> incorrectIdThenNormalizedPixelPercentageCollection = new();
|
||||
foreach (SortingContainer sortingContainer in sortingContainers)
|
||||
{
|
||||
if (sortingContainer.Face.FaceEncoding is null || sortingContainer.Face.Location?.NormalizedPixelPercentage is null)
|
||||
throw new NotSupportedException();
|
||||
if (sortingContainer.Face.Mapping is null)
|
||||
throw new NotSupportedException();
|
||||
if (!keyValuePairs.ContainsKey(sortingContainer.Face.Mapping.MappingFromItem.Id))
|
||||
keyValuePairs.Add(sortingContainer.Face.Mapping.MappingFromItem.Id, new());
|
||||
keyValuePairs[sortingContainer.Face.Mapping.MappingFromItem.Id].Add(sortingContainer.Face);
|
||||
}
|
||||
Stateless.ByDeterministicHashCode.SetCollections(maxDegreeOfParallelism, _Ticks, _ZPropertyHolderContentDirectory, personKeyAliases, idThenNormalizedPixelPercentageCollection, incorrectIdThenNormalizedPixelPercentageCollection, keyValuePairs);
|
||||
}
|
||||
|
||||
private static string GetMappingSegmentB(long ticks, PersonBirthday personBirthday, int? approximateYears, long minimumDateTimeTicks, bool? isWrongYear)
|
||||
{
|
||||
int years;
|
||||
@ -298,8 +295,10 @@ public class MapLogic
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Dictionary<int, PersonBirthday[]> GetKeyValuePairs(string json)
|
||||
private Dictionary<int, PersonBirthday[]> GetKeyValuePairs(string json)
|
||||
{
|
||||
if (_Configuration is null)
|
||||
throw new NullReferenceException(nameof(_Configuration));
|
||||
Dictionary<int, PersonBirthday[]> results = new();
|
||||
PersonBirthday? personBirthday;
|
||||
List<PersonBirthday> personBirthdays;
|
||||
@ -311,7 +310,7 @@ public class MapLogic
|
||||
personBirthdays = new();
|
||||
foreach (string personKey in keyValuePair.Value)
|
||||
{
|
||||
personBirthday = IPersonBirthday.GetPersonBirthday(Shared.Models.Stateless.IPersonBirthday.Format, personKey);
|
||||
personBirthday = IPersonBirthday.GetPersonBirthday(_Configuration.PersonBirthdayFormat, personKey);
|
||||
if (personBirthday is null)
|
||||
continue;
|
||||
}
|
||||
@ -322,10 +321,13 @@ public class MapLogic
|
||||
return results;
|
||||
}
|
||||
|
||||
private int AddToMapping(List<Face> distinctFilteredFaces)
|
||||
public int AddToMapping(List<Face> distinctFilteredFaces)
|
||||
{
|
||||
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;
|
||||
@ -334,7 +336,6 @@ public class MapLogic
|
||||
PersonBirthday personBirthday;
|
||||
List<PersonBirthday> personBirthdays = new();
|
||||
Dictionary<int, PersonBirthday[]> keyValuePairs;
|
||||
int by = Shared.Models.Stateless.ISorting.Mapping;
|
||||
(string DisplayDirectoryName, int? ApproximateYears, PersonBirthday[] PersonBirthdays, long PersonKey) person;
|
||||
foreach (Face face in distinctFilteredFaces)
|
||||
{
|
||||
@ -360,7 +361,7 @@ public class MapLogic
|
||||
approximateYears = person.ApproximateYears;
|
||||
personBirthday = person.PersonBirthdays[zero];
|
||||
displayDirectoryName = person.DisplayDirectoryName;
|
||||
personKeyFormatted = IPersonBirthday.GetFormatted(Shared.Models.Stateless.IPersonBirthday.Format, personBirthday);
|
||||
personKeyFormatted = IPersonBirthday.GetFormatted(_Configuration.PersonBirthdayFormat, personBirthday);
|
||||
mappingSegmentB = GetMappingSegmentB(_Ticks, personBirthday, approximateYears, face.Mapping.MappingFromItem);
|
||||
face.Mapping.UpdateMappingFromPerson(approximateYears, by, displayDirectoryName, personBirthday, mappingSegmentB);
|
||||
}
|
||||
@ -374,7 +375,7 @@ public class MapLogic
|
||||
string[] directories = (from l in saveContainers select l.Directory).Distinct().ToArray();
|
||||
int totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - _Ticks).TotalSeconds);
|
||||
string message = $") {saveContainers.Count:000} save(s) - {totalSeconds} total second(s)";
|
||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = false };
|
||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||
foreach (string directory in directories)
|
||||
{
|
||||
if (string.IsNullOrEmpty(directory))
|
||||
@ -424,19 +425,21 @@ public class MapLogic
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveNotMappedTicks()
|
||||
public void SaveNotMappedTicks(Property.Models.Configuration propertyConfiguration)
|
||||
{
|
||||
if (_Configuration is null)
|
||||
throw new NullReferenceException(nameof(_Configuration));
|
||||
string directory;
|
||||
string personKeyFormatted;
|
||||
SaveContainer saveContainer;
|
||||
PersonBirthday personBirthday;
|
||||
List<SaveContainer> saveContainers = new();
|
||||
const string facePopulatedKey = nameof(Sorting);
|
||||
const string facePopulatedKey = nameof(_Sorting);
|
||||
foreach (long personKey in _NotMappedPersonKeys)
|
||||
{
|
||||
personBirthday = IPersonBirthday.GetPersonBirthday(personKey);
|
||||
personKeyFormatted = IPersonBirthday.GetFormatted(Shared.Models.Stateless.IPersonBirthday.Format, personBirthday);
|
||||
directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, $"{facePopulatedKey}NotMapped", personKeyFormatted, Property.Models.Stateless.IResult.AllInOne);
|
||||
personKeyFormatted = IPersonBirthday.GetFormatted(_Configuration.PersonBirthdayFormat, personBirthday);
|
||||
directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, $"{facePopulatedKey}NotMapped", personKeyFormatted, propertyConfiguration.ResultAllInOne);
|
||||
saveContainer = new(directory);
|
||||
saveContainers.Add(saveContainer);
|
||||
}
|
||||
@ -445,6 +448,8 @@ public class MapLogic
|
||||
|
||||
public List<(Face, long?, (string, string, string, string))> GetCollection(List<Face> distinctFilteredFaces)
|
||||
{
|
||||
if (_Configuration is null)
|
||||
throw new NullReferenceException(nameof(_Configuration));
|
||||
List<(Face, long?, (string, string, string, string))> results = new();
|
||||
int years;
|
||||
long? personKey;
|
||||
@ -504,7 +509,7 @@ public class MapLogic
|
||||
subDirectoryName = $"^{years:000}";
|
||||
}
|
||||
}
|
||||
personKeyFormatted = IPersonBirthday.GetFormatted(Shared.Models.Stateless.IPersonBirthday.Format, personBirthday);
|
||||
personKeyFormatted = IPersonBirthday.GetFormatted(_Configuration.PersonBirthdayFormat, personBirthday);
|
||||
directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, "Shortcuts", personKeyFormatted, subDirectoryName);
|
||||
if (face.FaceEncoding is not null && face.Location?.NormalizedPixelPercentage is not null)
|
||||
copyDirectory = Path.Combine(_ZPropertyHolderContentTicksDirectory, "Images", personKeyFormatted, subDirectoryName);
|
||||
@ -550,6 +555,8 @@ public class MapLogic
|
||||
|
||||
private int UpdateFromSortingContainers(SortingContainer[] sortingContainers)
|
||||
{
|
||||
if (_Configuration is null)
|
||||
throw new NullReferenceException(nameof(_Configuration));
|
||||
int result = 0;
|
||||
Dictionary<int, HashSet<int>> results = new();
|
||||
string key;
|
||||
@ -557,22 +564,23 @@ public class MapLogic
|
||||
const int zero = 0;
|
||||
HashSet<int> hashSet;
|
||||
string mappingSegmentB;
|
||||
const int by = _Sorting;
|
||||
string personKeyFormatted;
|
||||
List<Mapping> checkCollection;
|
||||
PersonBirthday personBirthday;
|
||||
PersonBirthday[] personBirthdays;
|
||||
Dictionary<int, PersonBirthday[]> keyValuePairs;
|
||||
const int by = Shared.Models.Stateless.ISorting.Sorting;
|
||||
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 = false };
|
||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||
foreach (KeyValuePair<int, Dictionary<int, PersonBirthday[]>> keyValuePair in _IdThenNormalizedPixelPercentageKeyValuePairs)
|
||||
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)
|
||||
{
|
||||
progressBar.Tick();
|
||||
if (sortingContainer.Face.Mapping is null)
|
||||
throw new NotSupportedException();
|
||||
if (!_IdThenNormalizedPixelPercentageKeyValuePairs.ContainsKey(sortingContainer.Sorting.Id))
|
||||
@ -586,7 +594,7 @@ public class MapLogic
|
||||
if (!keyValuePairs.ContainsKey(sortingContainer.Sorting.NormalizedPixelPercentage))
|
||||
throw new NotSupportedException();
|
||||
personBirthdays = keyValuePairs[sortingContainer.Sorting.NormalizedPixelPercentage];
|
||||
if (sortingContainer.Face.Mapping.MappingFromLocation.Confidence < Shared.Models.Stateless.IFaceDistance.MinimumConfidence || sortingContainer.Sorting.DistancePermyriad > Shared.Models.Stateless.IFaceDistance.Permyriad || sortingContainer.Sorting.DaysDelta > Shared.Models.Stateless.ISorting.DaysDeltaTolerance)
|
||||
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++)
|
||||
{
|
||||
@ -595,13 +603,13 @@ public class MapLogic
|
||||
continue;
|
||||
person = _PeopleKeyValuePairs[personKey];
|
||||
personBirthday = person.PersonBirthdays[zero];
|
||||
personKeyFormatted = IPersonBirthday.GetFormatted(Shared.Models.Stateless.IPersonBirthday.Format, personBirthday);
|
||||
personKeyFormatted = IPersonBirthday.GetFormatted(_Configuration.PersonBirthdayFormat, personBirthday);
|
||||
mappingSegmentB = GetMappingSegmentB(_Ticks, personBirthday, person.ApproximateYears, sortingContainer.Face.Mapping.MappingFromItem);
|
||||
key = string.Concat(personKeyFormatted, '\t', mappingSegmentB);
|
||||
if (!checkKeyValuePairs.ContainsKey(key))
|
||||
checkKeyValuePairs.Add(key, new());
|
||||
checkCollection = checkKeyValuePairs[key];
|
||||
if (checkCollection.Count > Shared.Models.Stateless.ISorting.MaximumPerKey)
|
||||
if (checkCollection.Count > _Configuration.SortingMaximumPerKey)
|
||||
continue;
|
||||
_ = hashSet.Add(sortingContainer.Sorting.NormalizedPixelPercentage);
|
||||
sortingContainer.Face.Mapping.UpdateMappingFromPerson(person.ApproximateYears, by, person.DisplayDirectoryName, personBirthday, mappingSegmentB);
|
||||
@ -613,16 +621,16 @@ public class MapLogic
|
||||
return result;
|
||||
}
|
||||
|
||||
internal void ForceSingleImage(IEnumerable<Face> distinctFilteredFaces)
|
||||
internal void ForceSingleImage(Property.Models.Configuration propertyConfiguration, IEnumerable<Face> distinctFilteredFaces)
|
||||
{
|
||||
long? personKey;
|
||||
const int zero = 0;
|
||||
string mappingSegmentB;
|
||||
int by = _ForceSingleImage;
|
||||
int? approximateYears = null;
|
||||
PersonBirthday personBirthday;
|
||||
int by = Shared.Models.Stateless.ISorting.ForceSingleImage;
|
||||
string displayDirectoryName = propertyConfiguration.ResultAllInOne;
|
||||
Face[] orderedDistinctFilteredFaces = (from l in distinctFilteredFaces orderby l.Mapping is not null, l.Mapping?.MappingFromLocation.Confidence descending select l).ToArray();
|
||||
const string displayDirectoryName = Property.Models.Stateless.IResult.AllInOne;
|
||||
foreach (Face face in orderedDistinctFilteredFaces)
|
||||
{
|
||||
if (face.Mapping is null)
|
||||
@ -639,6 +647,8 @@ public class MapLogic
|
||||
|
||||
private List<SaveContainer> GetMappingSaveContainers(string dFacesContentDirectory, string d2ResultsFullGroupDirectory, List<Face> filteredFaces)
|
||||
{
|
||||
if (_Configuration is null)
|
||||
throw new NullReferenceException(nameof(_Configuration));
|
||||
List<SaveContainer> results = new();
|
||||
string by;
|
||||
string json;
|
||||
@ -654,6 +664,7 @@ public class MapLogic
|
||||
SaveContainer saveContainer;
|
||||
FileHolder facePartsFileHolder;
|
||||
FileHolder hiddenFaceFileHolder;
|
||||
Dictionary<string, int> keyValuePairs = new();
|
||||
foreach (Face face in filteredFaces)
|
||||
{
|
||||
if (face.Mapping is null)
|
||||
@ -665,24 +676,27 @@ public class MapLogic
|
||||
continue;
|
||||
if (string.IsNullOrEmpty(face.Mapping.MappingFromPerson.SegmentB))
|
||||
throw new NotSupportedException();
|
||||
personKeyFormatted = IPersonBirthday.GetFormatted(Shared.Models.Stateless.IPersonBirthday.Format, face.Mapping.MappingFromPerson.PersonBirthday);
|
||||
personKeyFormatted = IPersonBirthday.GetFormatted(_Configuration.PersonBirthdayFormat, face.Mapping.MappingFromPerson.PersonBirthday);
|
||||
if (face.Mapping.MappingFromPerson.By is null)
|
||||
by = $"{nameof(Mapping)}Null";
|
||||
by = $"{nameof(_Mapping)}Null";
|
||||
else
|
||||
{
|
||||
if (face.Mapping.MappingFromPerson.By == Shared.Models.Stateless.ISorting.Mapping && !Shared.Models.Stateless.IMapping.SaveMapped)
|
||||
if (face.Mapping.MappingFromPerson.By == _Mapping && !_Configuration.MappingSaveMapped)
|
||||
continue;
|
||||
by = face.Mapping.MappingFromPerson.By.Value switch
|
||||
{
|
||||
Shared.Models.Stateless.ISorting.Mapping => nameof(Mapping),
|
||||
Shared.Models.Stateless.ISorting.Sorting => nameof(Sorting),
|
||||
Shared.Models.Stateless.ISorting.ForceSingleImage => nameof(MapLogic.ForceSingleImage),
|
||||
_Mapping => nameof(_Mapping),
|
||||
_Sorting => nameof(_Sorting),
|
||||
_ForceSingleImage => nameof(MapLogic.ForceSingleImage),
|
||||
_ => throw new NotImplementedException()
|
||||
};
|
||||
}
|
||||
directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, by, personKeyFormatted, face.Mapping.MappingFromPerson.SegmentB);
|
||||
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 == Shared.Models.Stateless.ISorting.Sorting)
|
||||
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");
|
||||
@ -692,19 +706,19 @@ public class MapLogic
|
||||
results.Add(saveContainer);
|
||||
facesDirectory = string.Concat(dFacesContentDirectory, Path.Combine(directoryName, face.Mapping.MappingFromItem.ImageFileHolder.NameWithoutExtension));
|
||||
facePartsDirectory = string.Concat(d2ResultsFullGroupDirectory, Path.Combine(directoryName, face.Mapping.MappingFromItem.ImageFileHolder.NameWithoutExtension));
|
||||
checkFile = Path.Combine(directory, $"{face.Mapping.MappingFromLocation.DeterministicHashCodeKeyDisplay}{face.Mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}");
|
||||
faceFileHolder = new(Path.Combine(facesDirectory, $"{face.Mapping.MappingFromLocation.DeterministicHashCodeKeyDisplay}{face.Mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}{_FacesFilenameExtension}"));
|
||||
hiddenFaceFileHolder = new(Path.Combine(facesDirectory, $"{face.Mapping.MappingFromLocation.DeterministicHashCodeKeyDisplay}{face.Mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}{_FacesHiddenFilenameExtension}"));
|
||||
facePartsFileHolder = new(Path.Combine(facePartsDirectory, $"{face.Mapping.MappingFromLocation.DeterministicHashCodeKeyDisplay}{face.Mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}{_FacePartsFilenameExtension}"));
|
||||
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}"));
|
||||
facePartsFileHolder = new(Path.Combine(facePartsDirectory, $"{face.Mapping.MappingFromLocation.DeterministicHashCodeKey}{face.Mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}{_FacePartsFilenameExtension}"));
|
||||
if (string.IsNullOrEmpty(personDirectory))
|
||||
shortcutFile = string.Empty;
|
||||
else
|
||||
shortcutFile = Path.Combine(personDirectory, $"{face.Mapping.MappingFromLocation.DeterministicHashCodeKeyDisplay}{face.Mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}.lnk");
|
||||
shortcutFile = Path.Combine(personDirectory, $"{face.Mapping.MappingFromLocation.DeterministicHashCodeKey}{face.Mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}.lnk");
|
||||
saveContainer = new(checkFile, directory, faceFileHolder, hiddenFaceFileHolder, string.Empty, facePartsFileHolder, face.Mapping.MappingFromItem.ResizedFileHolder, shortcutFile);
|
||||
results.Add(saveContainer);
|
||||
if (!string.IsNullOrEmpty(checkFile) && Shared.Models.Stateless.IMapping.SaveFaceEncoding)
|
||||
if (!string.IsNullOrEmpty(checkFile) && _Configuration.MappingSaveFaceEncoding)
|
||||
{
|
||||
checkFile = Path.Combine(directory, $"{face.Mapping.MappingFromLocation.DeterministicHashCodeKeyDisplay}{face.Mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}.json");
|
||||
checkFile = Path.Combine(directory, $"{face.Mapping.MappingFromLocation.DeterministicHashCodeKey}{face.Mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}.json");
|
||||
json = JsonSerializer.Serialize(face.FaceEncoding);
|
||||
saveContainer = new(checkFile, directory, json);
|
||||
results.Add(saveContainer);
|
||||
@ -714,28 +728,22 @@ public class MapLogic
|
||||
return results;
|
||||
}
|
||||
|
||||
public void CommonWork(int maxDegreeOfParallelism, string dFacesContentDirectory, string d2ResultsFullGroupDirectory, List<Face> distinctFilteredFaces, SortingContainer[] sortingContainers)
|
||||
public void ForceSingleImageThenSaveMapping(int maxDegreeOfParallelism, Property.Models.Configuration propertyConfiguration, string dFacesContentDirectory, string d2ResultsFullGroupDirectory, List<Face> distinctFilteredFaces, SortingContainer[] sortingContainers, int totalNotMapped)
|
||||
{
|
||||
List<SaveContainer> saveContainers;
|
||||
if (!_IdThenNormalizedPixelPercentageKeyValuePairs.Any())
|
||||
UseKeyValuePairsSaveFaceEncoding(maxDegreeOfParallelism, sortingContainers);
|
||||
int totalNotMapped = AddToMapping(distinctFilteredFaces);
|
||||
if (totalNotMapped == 0)
|
||||
saveContainers = new();
|
||||
else if (!sortingContainers.Any())
|
||||
if (!sortingContainers.Any())
|
||||
{
|
||||
ForceSingleImage(distinctFilteredFaces);
|
||||
ForceSingleImage(propertyConfiguration, distinctFilteredFaces);
|
||||
saveContainers = GetMappingSaveContainers(dFacesContentDirectory, d2ResultsFullGroupDirectory, distinctFilteredFaces);
|
||||
}
|
||||
else
|
||||
{
|
||||
int updated = UpdateFromSortingContainers(sortingContainers);
|
||||
if (totalNotMapped - updated > 0)
|
||||
ForceSingleImage(distinctFilteredFaces);
|
||||
ForceSingleImage(propertyConfiguration, distinctFilteredFaces);
|
||||
saveContainers = GetMappingSaveContainers(dFacesContentDirectory, d2ResultsFullGroupDirectory, distinctFilteredFaces);
|
||||
}
|
||||
SaveContainers(saveContainers);
|
||||
SaveNotMappedTicks();
|
||||
}
|
||||
|
||||
private static double GetStandardDeviation(IEnumerable<long> values, double average)
|
||||
@ -782,16 +790,16 @@ public class MapLogic
|
||||
}
|
||||
}
|
||||
|
||||
public void SetPersonTicks(string outputResolution, Face[] filteredFaces)
|
||||
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 = $") {filteredFaces.Length:000} Set Person Ticks - {totalSeconds} total second(s) - {outputResolution}";
|
||||
string message = $") {distinctFilteredFaces.Count:000} Set Person Ticks - {totalSeconds} total second(s)";
|
||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||
using ProgressBar progressBar = new(filteredFaces.Length, message, options);
|
||||
foreach (Face face in filteredFaces)
|
||||
using ProgressBar progressBar = new(distinctFilteredFaces.Count, message, options);
|
||||
foreach (Face face in distinctFilteredFaces)
|
||||
{
|
||||
progressBar.Tick();
|
||||
if (face.Mapping is null)
|
||||
|
@ -5,10 +5,10 @@ using View_by_Distance.Shared.Models;
|
||||
|
||||
namespace View_by_Distance.Map.Models.Stateless;
|
||||
|
||||
public class ByDeterministicHashCode
|
||||
public class ByRef
|
||||
{
|
||||
|
||||
private static void SetOther(string resizeFilenameExtension, Person[] people, string deterministicHashCodePeopleDirectory, List<double> skipCollection, Dictionary<long, long> personKeyAliases, List<(string, int?, PersonBirthday[], long)> peopleCollection)
|
||||
private static void SetOther(Property.Models.Configuration propertyConfiguration, Configuration configuration, string resizeFilenameExtension, Person[] people, string deterministicHashCodePeopleDirectory, List<double> skipCollection, Dictionary<long, long> personKeyAliases, List<(string, int?, PersonBirthday[], long)> peopleCollection)
|
||||
{
|
||||
long pK;
|
||||
string json;
|
||||
@ -32,7 +32,7 @@ public class ByDeterministicHashCode
|
||||
Dictionary<string, Person> personKeyValuePairs = new();
|
||||
foreach (Person person in people)
|
||||
{
|
||||
personKeyFormatted = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(Shared.Models.Stateless.IPersonBirthday.Format, person.Birthday);
|
||||
personKeyFormatted = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(configuration.PersonBirthdayFormat, person.Birthday);
|
||||
if (personKeyValuePairs.ContainsKey(personKeyFormatted))
|
||||
break;
|
||||
personKeyValuePairs.Add(personKeyFormatted, person);
|
||||
@ -71,11 +71,11 @@ public class ByDeterministicHashCode
|
||||
{
|
||||
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(Shared.Models.Stateless.IPersonBirthday.Format, personKeyFormatted);
|
||||
personBirthday = Shared.Models.Stateless.Methods.IPersonBirthday.GetPersonBirthday(configuration.PersonBirthdayFormat, personKeyFormatted);
|
||||
else
|
||||
{
|
||||
personBirthday = new PersonBirthday(birthday);
|
||||
personKeyFormatted = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(Shared.Models.Stateless.IPersonBirthday.Format, personBirthday);
|
||||
personKeyFormatted = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(configuration.PersonBirthdayFormat, personBirthday);
|
||||
convertedPersonKeyDirectory = Path.Combine(personDisplayDirectory, personKeyFormatted);
|
||||
if (!Directory.Exists(convertedPersonKeyDirectory))
|
||||
Directory.Move(personKeyDirectory, convertedPersonKeyDirectory);
|
||||
@ -89,7 +89,7 @@ public class ByDeterministicHashCode
|
||||
foreach (string personKeyDirectory in personKeyDirectories)
|
||||
{
|
||||
personKeyFormatted = Path.GetFileName(personKeyDirectory);
|
||||
personBirthday = Shared.Models.Stateless.Methods.IPersonBirthday.GetPersonBirthday(Shared.Models.Stateless.IPersonBirthday.Format, personKeyFormatted);
|
||||
personBirthday = Shared.Models.Stateless.Methods.IPersonBirthday.GetPersonBirthday(configuration.PersonBirthdayFormat, personKeyFormatted);
|
||||
if (personBirthday is null)
|
||||
continue;
|
||||
if (personKeyValuePairs.ContainsKey(personKeyFormatted))
|
||||
@ -123,25 +123,27 @@ public class ByDeterministicHashCode
|
||||
}
|
||||
}
|
||||
approximateYears = null;
|
||||
const string displayDirectoryName = Property.Models.Stateless.IResult.AllInOne;
|
||||
DateTime incrementDate = new(Shared.Models.Stateless.IPersonBirthday.FirstYear, 1, 1);
|
||||
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(Shared.Models.Stateless.IPersonBirthday.Format, personBirthday);
|
||||
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 void SetCollections(int maxDegreeOfParallelism, long ticks, string zPropertyHolderContentDirectory, Dictionary<long, long> personKeyAliases, List<(PersonBirthday, int, int)> idThenNormalizedPixelPercentageCollection, List<(PersonBirthday, int, int)> incorrectIdThenNormalizedPixelPercentageCollection, Dictionary<int, List<Face>> keyValuePairs)
|
||||
|
||||
internal static List<(string, char, string, int?, int?, List<Face>?)> DeleteEmptyDirectoriesAndGetCollection(Configuration configuration, long ticks, string zPropertyHolderContentDirectory, Dictionary<int, List<Face>> keyValuePairs)
|
||||
{
|
||||
List<(string, char, string, int?, int?, List<Face>?)> results = new();
|
||||
int? id;
|
||||
string[] files;
|
||||
long personKey;
|
||||
List<Face>? faces;
|
||||
const int zero = 0;
|
||||
string[] yearDirectories;
|
||||
string personKeyFormatted;
|
||||
@ -150,14 +152,12 @@ public class ByDeterministicHashCode
|
||||
string[] personKeyDirectories;
|
||||
int? normalizedPixelPercentage;
|
||||
string[] personNameDirectories;
|
||||
PersonBirthday? personBirthday;
|
||||
string[] personNameLinkDirectories;
|
||||
string? personFirstInitialDirectory;
|
||||
bool keyValuePairsAny = keyValuePairs.Any();
|
||||
ParallelOptions parallelOptions = new() { MaxDegreeOfParallelism = maxDegreeOfParallelism };
|
||||
int totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds);
|
||||
string[] ticksDirectories = Directory.GetDirectories(zPropertyHolderContentDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
string message = $") {ticksDirectories.Length:000} ticks Director(ies) - {totalSeconds} total second(s)";
|
||||
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)
|
||||
@ -170,20 +170,8 @@ public class ByDeterministicHashCode
|
||||
foreach (string personKeyDirectory in personKeyDirectories)
|
||||
{
|
||||
personKeyFormatted = Path.GetFileName(personKeyDirectory);
|
||||
if (personKeyFormatted.Length != Shared.Models.Stateless.IPersonBirthday.Format.Length)
|
||||
personBirthday = null;
|
||||
else
|
||||
{
|
||||
personBirthday = Shared.Models.Stateless.Methods.IPersonBirthday.GetPersonBirthday(Shared.Models.Stateless.IPersonBirthday.Format, 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 (personKeyFormatted.Length != configuration.PersonBirthdayFormat.Length)
|
||||
continue;
|
||||
yearDirectories = Directory.GetDirectories(personKeyDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string yearDirectory in yearDirectories)
|
||||
{
|
||||
@ -196,27 +184,24 @@ public class ByDeterministicHashCode
|
||||
personFirstInitial = Path.GetFileName(personNameDirectory)[..1];
|
||||
if (personFirstInitial is null)
|
||||
continue;
|
||||
personFirstInitialDirectory = Path.Combine(yearDirectory, personFirstInitial);
|
||||
files = Directory.GetFiles(personNameDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
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!");
|
||||
if (personBirthday is null)
|
||||
continue;
|
||||
foreach (string file in files)
|
||||
{
|
||||
if (file.EndsWith(".lnk") || file.EndsWith(".json"))
|
||||
continue;
|
||||
(id, normalizedPixelPercentage) = Shared.Models.Stateless.Methods.IMapping.GetReversedDeterministicHashCodeKey(Shared.Models.Stateless.ILocation.Digits, keyValuePairsAny, keyValuePairs, file);
|
||||
(id, normalizedPixelPercentage, faces) = Shared.Models.Stateless.Methods.IMapping.GetReversedDeterministicHashCodeKey(configuration.LocationDigits, keyValuePairsAny, keyValuePairs, file);
|
||||
if (id is null || normalizedPixelPercentage is null)
|
||||
continue;
|
||||
if (personFirstInitial != "!")
|
||||
idThenNormalizedPixelPercentageCollection.Add(new(personBirthday, id.Value, normalizedPixelPercentage.Value));
|
||||
else
|
||||
incorrectIdThenNormalizedPixelPercentageCollection.Add(new(personBirthday, id.Value, normalizedPixelPercentage.Value));
|
||||
results.Add(new(personKeyFormatted, personFirstInitial[0], file, id, normalizedPixelPercentage, faces));
|
||||
}
|
||||
personNameLinkDirectories = Directory.GetDirectories(personNameDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
personNameLinkDirectories = Directory.GetDirectories(personFirstInitialDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string personNameLinkDirectory in personNameLinkDirectories)
|
||||
{
|
||||
files = Directory.GetFiles(personNameLinkDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
@ -228,10 +213,7 @@ public class ByDeterministicHashCode
|
||||
}
|
||||
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(personNameLinkDirectory);
|
||||
}
|
||||
if (personNameDirectory == personFirstInitialDirectory)
|
||||
continue;
|
||||
Directory.Move(personNameDirectory, personFirstInitialDirectory);
|
||||
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(personNameDirectory);
|
||||
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(personFirstInitialDirectory);
|
||||
}
|
||||
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(yearDirectory);
|
||||
}
|
||||
@ -240,9 +222,10 @@ public class ByDeterministicHashCode
|
||||
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(ticksDirectory);
|
||||
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(ticksDirectory);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private static void SetKeyValuePairs(List<(PersonBirthday, int, int)> idThenNormalizedPixelPercentageCollection, List<(PersonBirthday, int, int)> incorrectIdThenNormalizedPixelPercentageCollection, Dictionary<int, Dictionary<int, PersonBirthday[]>> idThenNormalizedPixelPercentageKeyValuePairs, Dictionary<int, Dictionary<int, PersonBirthday[]>> incorrectIdThenNormalizedPixelPercentageKeyValuePairs)
|
||||
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;
|
||||
@ -252,7 +235,7 @@ public class ByDeterministicHashCode
|
||||
if (!idThenNormalizedPixelPercentageScope.ContainsKey(id))
|
||||
idThenNormalizedPixelPercentageScope.Add(id, new());
|
||||
check = normalizedPixelPercentage.ToString();
|
||||
if (check.Length == Shared.Models.Stateless.ILocation.Digits)
|
||||
if (check.Length == configuration.LocationDigits)
|
||||
{
|
||||
if (!idThenNormalizedPixelPercentageScope[id].ContainsKey(normalizedPixelPercentage))
|
||||
idThenNormalizedPixelPercentageScope[id].Add(normalizedPixelPercentage, new());
|
||||
@ -260,7 +243,7 @@ public class ByDeterministicHashCode
|
||||
}
|
||||
else
|
||||
{
|
||||
normalizedPixelPercentageInDecimalForm = int.Parse(check.PadRight(Shared.Models.Stateless.ILocation.Digits, '0'));
|
||||
normalizedPixelPercentageInDecimalForm = int.Parse(check.PadRight(configuration.LocationDigits, '0'));
|
||||
if (!idThenNormalizedPixelPercentageScope[id].ContainsKey(normalizedPixelPercentageInDecimalForm))
|
||||
idThenNormalizedPixelPercentageScope[id].Add(normalizedPixelPercentageInDecimalForm, new());
|
||||
idThenNormalizedPixelPercentageScope[id][normalizedPixelPercentageInDecimalForm].Add(personBirthday);
|
||||
@ -278,7 +261,7 @@ public class ByDeterministicHashCode
|
||||
if (!incorrectIdThenNormalizedPixelPercentageScope.ContainsKey(id))
|
||||
incorrectIdThenNormalizedPixelPercentageScope.Add(id, new());
|
||||
check = normalizedPixelPercentage.ToString();
|
||||
if (check.Length == Shared.Models.Stateless.ILocation.Digits)
|
||||
if (check.Length == configuration.LocationDigits)
|
||||
{
|
||||
if (!incorrectIdThenNormalizedPixelPercentageScope[id].ContainsKey(normalizedPixelPercentage))
|
||||
incorrectIdThenNormalizedPixelPercentageScope[id].Add(normalizedPixelPercentage, new());
|
||||
@ -286,7 +269,7 @@ public class ByDeterministicHashCode
|
||||
}
|
||||
else
|
||||
{
|
||||
normalizedPixelPercentageInDecimalForm = int.Parse(check.PadRight(Shared.Models.Stateless.ILocation.Digits, '0'));
|
||||
normalizedPixelPercentageInDecimalForm = int.Parse(check.PadRight(configuration.LocationDigits, '0'));
|
||||
if (!incorrectIdThenNormalizedPixelPercentageScope[id].ContainsKey(normalizedPixelPercentageInDecimalForm))
|
||||
incorrectIdThenNormalizedPixelPercentageScope[id].Add(normalizedPixelPercentageInDecimalForm, new());
|
||||
incorrectIdThenNormalizedPixelPercentageScope[id][normalizedPixelPercentageInDecimalForm].Add(personBirthday);
|
||||
@ -300,19 +283,151 @@ public class ByDeterministicHashCode
|
||||
}
|
||||
}
|
||||
|
||||
internal static void SetByRef(int maxDegreeOfParallelism, long ticks, string resizeFilenameExtension, Person[] people, 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, string zPropertyHolderContentDirectory, string zPropertyHolderPeopleContentDirectory)
|
||||
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 zPropertyHolderContentDirectory, string zPropertyHolderPeopleContentDirectory, 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> idThenNormalizedPixelPercentagePersonKeys = new();
|
||||
List<(string, int?, PersonBirthday[], long)> peopleCollection = new();
|
||||
List<(PersonBirthday, int, int)> idThenNormalizedPixelPercentageCollection = new();
|
||||
List<(PersonBirthday, int, int)> incorrectIdThenNormalizedPixelPercentageCollection = new();
|
||||
SetOther(resizeFilenameExtension, people, zPropertyHolderPeopleContentDirectory, skipCollection, personKeyAliases, peopleCollection);
|
||||
SetCollections(maxDegreeOfParallelism, ticks, zPropertyHolderContentDirectory, personKeyAliases, idThenNormalizedPixelPercentageCollection, incorrectIdThenNormalizedPixelPercentageCollection, keyValuePairs);
|
||||
SetKeyValuePairs(idThenNormalizedPixelPercentageCollection, incorrectIdThenNormalizedPixelPercentageCollection, idThenNormalizedPixelPercentageKeyValuePairs, incorrectIdThenNormalizedPixelPercentageKeyValuePairs);
|
||||
SetOther(propertyConfiguration, configuration, resizeFilenameExtension, people, zPropertyHolderPeopleContentDirectory, 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, zPropertyHolderContentDirectory, 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);
|
||||
}
|
||||
@ -337,7 +452,7 @@ public class ByDeterministicHashCode
|
||||
{
|
||||
int? approximateYears = null;
|
||||
PersonBirthday? personBirthday;
|
||||
const string displayDirectoryName = Property.Models.Stateless.IResult.AllInOne;
|
||||
string displayDirectoryName = propertyConfiguration.ResultAllInOne;
|
||||
foreach (long personKey in idThenNormalizedPixelPercentagePersonKeys)
|
||||
{
|
||||
if (!peopleKeyValuePairs.ContainsKey(personKey))
|
Reference in New Issue
Block a user