Change to support 7680 x 4320 and
Configuration additions
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user