Sorting without ... improvements

This commit is contained in:
2022-12-21 22:54:50 -07:00
parent 44d8eaf5fb
commit 2da3db7aa5
25 changed files with 353 additions and 358 deletions

View File

@ -2,7 +2,6 @@ using Humanizer;
using ShellProgressBar;
using System.Text;
using System.Text.Json;
using View_by_Distance.Map.Models.Stateless;
using View_by_Distance.Shared.Models;
using View_by_Distance.Shared.Models.Stateless.Methods;
using WindowsShortcutFactory;
@ -15,7 +14,7 @@ public class MapLogic
protected readonly Dictionary<int, List<int>> _SkipCollection;
protected readonly List<PersonContainer> _NotMappedPersonContainers;
protected readonly Dictionary<long, PersonContainer> _PersonKeyToPersonContainer;
protected readonly Dictionary<long, (long LCL, long Minimum, long Maximum, long UCL)> _PersonKeyToRanges;
protected Dictionary<long, (long LCL, long Minimum, long Maximum, long UCL)>? _PersonKeyToRanges;
protected readonly Dictionary<int, Dictionary<int, PersonContainer[]>> _IdThenNormalizedRectangleToPersonContainers;
public Dictionary<int, int[]> KeyValuePairs => throw new NotImplementedException();
@ -29,7 +28,7 @@ public class MapLogic
private readonly Shared.Models.Methods.IMapLogicSupport? _MapLogicSupport;
private readonly Shared.Models.Properties.IPropertyConfiguration _PropertyConfiguration;
public MapLogic(int maxDegreeOfParallelism, Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, Configuration? configuration, long ticks, PersonContainer[] personContainers, string a2PeopleSingletonDirectory, string eDistanceContentDirectory, Mapping[] mappingCollection, Shared.Models.Methods.IMapLogicSupport? mapLogicSupport)
public MapLogic(int maxDegreeOfParallelism, Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, Configuration? configuration, long ticks, PersonContainer[] personContainers, string a2PeopleSingletonDirectory, string eDistanceContentDirectory, Shared.Models.Methods.IMapLogicSupport? mapLogicSupport)
{
_Ticks = ticks;
_Configuration = configuration;
@ -50,7 +49,6 @@ public class MapLogic
List<PersonContainer> notMappedPersonContainers = new();
Dictionary<long, PersonContainer> personKeyToPersonContainer = 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})");
Dictionary<int, Dictionary<int, PersonContainer[]>> idThenNormalizedRectangleToPersonContainers = new();
for (int i = 1; i < 5; i++)
@ -71,10 +69,8 @@ public class MapLogic
personContainerCollection,
a2PeopleSingletonDirectory,
eDistanceContentDirectory,
mappingCollection,
mapLogicSupport,
personKeyToPersonContainer,
personKeyToRanges,
notMappedPersonContainers,
skipCollection,
idThenNormalizedRectangleToPersonContainers);
@ -94,17 +90,12 @@ public class MapLogic
throw new NullReferenceException(nameof(collection));
}
_SkipCollection = skipCollection;
_PersonKeyToRanges = personKeyToRanges;
_NotMappedPersonContainers = notMappedPersonContainers;
_PersonKeyToPersonContainer = personKeyToPersonContainer;
_EDistanceContentTicksDirectory = eDistanceContentTicksDirectory;
_IdThenNormalizedRectangleToPersonContainers = idThenNormalizedRectangleToPersonContainers;
_NotMappedPersonContainers = notMappedPersonContainers.OrderByDescending(l => l.Key).ToList();
}
public MapLogic(int maxDegreeOfParallelism, Shared.Models.Properties.IPropertyConfiguration propertyConfiguration, Configuration? configuration, long ticks, PersonContainer[] personContainers, string a2PeopleSingletonDirectory, string eDistanceContentDirectory) :
this(maxDegreeOfParallelism, propertyConfiguration, configuration, ticks, personContainers, a2PeopleSingletonDirectory, eDistanceContentDirectory, Array.Empty<Mapping>(), null)
{ }
public override string ToString()
{
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
@ -119,7 +110,6 @@ public class MapLogic
long personKey;
const int zero = 0;
string mappingSegmentB;
int by = IMapLogic.Mapping;
PersonBirthday personBirthday;
PersonContainer[]? collection;
List<PersonContainer> personContainers = new();
@ -147,7 +137,7 @@ public class MapLogic
personKeyToCount.Add(personKey, 0);
personKeyToCount[personKey] += 1;
mappingSegmentB = Stateless.MapLogic.GetMappingSegmentB(_Ticks, personBirthday, personContainer.ApproximateYears, mapping.MappingFromItem);
mapping.UpdateMappingFromPerson(personContainer.ApproximateYears, by, personContainer.DisplayDirectoryName, personBirthday, mappingSegmentB);
mapping.UpdateMappingFromPerson(personContainer.ApproximateYears, personContainer.DisplayDirectoryName, personBirthday, mappingSegmentB);
}
}
return new(personKeyToCount, result);
@ -309,23 +299,23 @@ public class MapLogic
{
isByMapping = false;
isBySorting = false;
by = $"{nameof(IMapLogic.Mapping)}Null";
by = $"{nameof(Shared.Models.Stateless.IMapLogic.Mapping)}Null";
}
else
{
isByMapping = mapping.By == IMapLogic.Mapping;
isBySorting = mapping.By == IMapLogic.Sorting;
isByMapping = mapping.By == Shared.Models.Stateless.IMapLogic.Mapping;
isBySorting = mapping.By == Shared.Models.Stateless.IMapLogic.Sorting;
if (isBySorting && mapping.MappingFromPerson is null)
by = $"{nameof(IMapLogic.Sorting)} Without Person";
by = $"{nameof(Shared.Models.Stateless.IMapLogic.Sorting)} Without Person";
else if (isBySorting && useFiltersCounter.HasValue)
by = $"{nameof(IMapLogic.Sorting)} Modified Filters - {useFiltersCounter.Value}";
by = $"{nameof(Shared.Models.Stateless.IMapLogic.Sorting)} Modified Filters - {useFiltersCounter.Value}";
else
{
by = mapping.By.Value switch
{
IMapLogic.Mapping => nameof(IMapLogic.Mapping),
IMapLogic.Sorting => nameof(IMapLogic.Sorting),
IMapLogic.ForceSingleImage => forceSingleImageHumanized,
Shared.Models.Stateless.IMapLogic.Mapping => nameof(Shared.Models.Stateless.IMapLogic.Mapping),
Shared.Models.Stateless.IMapLogic.Sorting => nameof(Shared.Models.Stateless.IMapLogic.Sorting),
Shared.Models.Stateless.IMapLogic.ForceSingleImage => forceSingleImageHumanized,
_ => throw new NotImplementedException()
};
}
@ -344,7 +334,7 @@ public class MapLogic
PersonBirthday personBirthday;
PersonContainer personContainer;
result = Path.Combine(_EDistanceContentTicksDirectory, by, sortingContainer.Sorting.Id.ToString(), sortingContainer.Sorting.NormalizedRectangle.ToString());
for (int i = 0; i < _NotMappedPersonContainers.Count; i++)
for (int i = _NotMappedPersonContainers.Count - 1; i > 0; i--)
{
personContainer = _NotMappedPersonContainers[i];
if (personContainer.Key is null || personContainer.Birthdays is null || !personContainer.Birthdays.Any())
@ -376,12 +366,13 @@ public class MapLogic
string? facesDirectory;
FileHolder faceFileHolder;
string personKeyFormatted;
List<int> distinct = new();
string? facePartsDirectory;
SaveContainer? saveContainer;
FileHolder facePartsFileHolder;
FileHolder hiddenFaceFileHolder;
Dictionary<int, Mapping>? normalizedRectangleToMapping;
string forceSingleImageHumanized = nameof(IMapLogic.ForceSingleImage).Humanize(LetterCasing.Title);
string forceSingleImageHumanized = nameof(Shared.Models.Stateless.IMapLogic.ForceSingleImage).Humanize(LetterCasing.Title);
foreach (Mapping mapping in mappingCollection)
{
directoryName = Path.GetDirectoryName(mapping.MappingFromItem.RelativePath);
@ -396,8 +387,14 @@ public class MapLogic
continue;
if (mapping.SortingContainer is null)
continue;
if (distinct.Contains(mapping.MappingFromItem.Id))
continue;
if (distinct.Contains(mapping.SortingContainer.Sorting.Id))
continue;
directory = GetDirectory(by, mapping.MappingFromItem, mapping.SortingContainer);
personDirectory = Path.Combine(directory, _Configuration.MappingDefaultName);
personDirectory = Path.Combine(directory, $"Z]{DateTime.Now.Ticks}");
distinct.Add(mapping.MappingFromItem.Id);
distinct.Add(mapping.SortingContainer.Sorting.Id);
}
else
{
@ -441,10 +438,10 @@ public class MapLogic
facePartsDirectory = GetFacePartsDirectory(d2FacePartsContentDirectory, mapping.MappingFromItem);
if (facePartsDirectory is null)
continue;
if (!isBySorting || mapping.MappingFromPerson is not null)
checkFile = Path.Combine(directory, $"{mapping.MappingFromLocation.DeterministicHashCodeKey}{mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}");
else
checkFile = Path.Combine(directory, $"{mapping.MappingFromLocation.DeterministicHashCodeKey}-Source{mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}");
// if (!isBySorting || mapping.MappingFromPerson is not null)
checkFile = Path.Combine(directory, $"{mapping.MappingFromLocation.DeterministicHashCodeKey}{mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}");
// else
// checkFile = Path.Combine(directory, $"{mapping.MappingFromLocation.DeterministicHashCodeKey}-Source{mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}");
shortcutFile = Path.Combine(personDirectory, $"{mapping.MappingFromLocation.DeterministicHashCodeKey}{mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}.lnk");
hiddenFaceFileHolder = new(Path.Combine(facesDirectory, $"{mapping.MappingFromLocation.DeterministicHashCodeKey}{mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}{_Configuration.FacesHiddenFileNameExtension}"));
facePartsFileHolder = new(Path.Combine(facePartsDirectory, $"{mapping.MappingFromLocation.DeterministicHashCodeKey}{mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}{_Configuration.FacePartsFileNameExtension}"));
@ -488,7 +485,7 @@ public class MapLogic
bool saveMapped = true;
bool saveNullPerson = false;
int? useFiltersCounter = null;
string mappingDirectory = Path.Combine(_EDistanceContentTicksDirectory, nameof(IMapLogic.Mapping));
string mappingDirectory = Path.Combine(_EDistanceContentTicksDirectory, nameof(Shared.Models.Stateless.IMapLogic.Mapping));
List<SaveContainer> saveContainers = GetSaveContainers(dFacesContentDirectory, d2FacePartsContentDirectory, mappingCollection, idToNormalizedRectangleToMapping, personKeyToCount, useFiltersCounter, saveNullPerson, saveMapped);
SaveContainers(totalNotMapped, updated, saveContainers);
if (!string.IsNullOrEmpty(_EDistanceContentTicksDirectory) && Directory.Exists(mappingDirectory))
@ -497,6 +494,8 @@ public class MapLogic
private List<(long, long, long, long)> GetPersonKeysRangesCollection(PersonContainer[] personContainers)
{
if (_PersonKeyToRanges is null)
throw new NullReferenceException(nameof(_PersonKeyToRanges));
List<(long, long, long, long)> results = new();
(long, long, long, long) singleton;
foreach (PersonContainer personContainer in personContainers)
@ -576,7 +575,7 @@ public class MapLogic
if (sorting.Id == faceDistanceEncoding.Id)
{
if (sorting.NormalizedRectangle == faceDistanceEncoding.NormalizedRectangle.Value)
throw new NotSupportedException();
continue;
continue;
}
results.Add(sorting);
@ -599,12 +598,11 @@ public class MapLogic
string mappingSegmentB;
string personKeyFormatted;
PersonBirthday personBirthday;
const int by = IMapLogic.Sorting;
PersonContainer[] personContainers;
PersonContainer[]? personContainers;
Dictionary<string, int> keyToCount = new();
Dictionary<string, string> keyToSegmentC = new();
List<int> normalizedRectangleCollectionForA;
List<int> normalizedRectangleCollectionForB;
Dictionary<string, string> keyToSegmentC = new();
Dictionary<int, List<int>> idToNormalizedRectangleCollectionForA = new();
Dictionary<int, List<int>> idToNormalizedRectangleCollectionForB = new();
Dictionary<int, PersonContainer[]>? normalizedRectangleToPersonContainers;
@ -623,22 +621,13 @@ public class MapLogic
if (!idToNormalizedRectangleCollectionForB.ContainsKey(sortingContainer.Mapping.MappingFromItem.Id))
idToNormalizedRectangleCollectionForB.Add(sortingContainer.Mapping.MappingFromItem.Id, new());
normalizedRectangleCollectionForB = idToNormalizedRectangleCollectionForB[sortingContainer.Mapping.MappingFromItem.Id];
if (!_IdThenNormalizedRectangleToPersonContainers.TryGetValue(sortingContainer.Sorting.Id, out normalizedRectangleToPersonContainers))
if (!_IdThenNormalizedRectangleToPersonContainers.TryGetValue(sortingContainer.Sorting.Id, out normalizedRectangleToPersonContainers) || !normalizedRectangleToPersonContainers.TryGetValue(sortingContainer.Sorting.NormalizedRectangle, out personContainers))
{
if (!saveNullPerson)
continue;
personContainers = Array.Empty<PersonContainer>();
if (normalizedRectangleCollectionForA.Contains(sortingContainer.Mapping.MappingFromLocation.NormalizedRectangle))
continue;
key = string.Concat(sortingContainer.Mapping.MappingFromItem.Id, '\t', sortingContainer.Mapping.MappingFromLocation.NormalizedRectangle);
if (!keyToCount.ContainsKey(key))
keyToCount.Add(key, 0);
if (!keyToSegmentC.ContainsKey(key))
keyToSegmentC.Add(key, string.Empty);
keyToCount[key]++;
if (keyToCount[key] > _Configuration.SortingMaximumPerKey)
continue;
sortingContainer.Mapping.UpdateMappingFromUnknownPerson(by, sortingContainer);
sortingContainer.Mapping.UpdateMappingFromUnknownPerson(sortingContainer);
normalizedRectangleCollectionForA.Add(sortingContainer.Mapping.MappingFromLocation.NormalizedRectangle);
result += 1;
}
@ -646,10 +635,6 @@ public class MapLogic
{
if (normalizedRectangleCollectionForB.Contains(sortingContainer.Mapping.MappingFromLocation.NormalizedRectangle))
continue;
if (!normalizedRectangleToPersonContainers.ContainsKey(sortingContainer.Sorting.NormalizedRectangle))
personContainers = Array.Empty<PersonContainer>();
else
personContainers = normalizedRectangleToPersonContainers[sortingContainer.Sorting.NormalizedRectangle];
foreach (PersonContainer personContainer in personContainers)
{
if (personContainer.Key is null || personContainer.Birthdays is null || !personContainer.Birthdays.Any())
@ -670,7 +655,7 @@ public class MapLogic
keyToCount[key] = 0;
keyToSegmentC[key] = sortingContainer.Sorting.DistancePermyriad.ToString();
}
sortingContainer.Mapping.UpdateMappingFromPerson(personContainer.ApproximateYears, by, personContainer.DisplayDirectoryName, personBirthday, mappingSegmentB, keyToSegmentC[key], sortingContainer);
sortingContainer.Mapping.UpdateMappingFromPerson(personContainer.ApproximateYears, personContainer.DisplayDirectoryName, personBirthday, mappingSegmentB, keyToSegmentC[key], sortingContainer);
normalizedRectangleCollectionForB.Add(sortingContainer.Mapping.MappingFromLocation.NormalizedRectangle);
result += 1;
break;
@ -703,10 +688,10 @@ public class MapLogic
string? personDisplayDirectory;
int? normalizedRectangle;
WindowsShortcut windowsShortcut;
string by = nameof(IMapLogic.ManualCopy);
Dictionary<int, Mapping>? normalizedRectangleToMapping;
string by = nameof(Shared.Models.Stateless.IMapLogic.ManualCopy);
Dictionary<int, PersonContainer[]>? normalizedRectangleToPeronContainerCollection;
string successfull = $"_ {nameof(IMapLogic.ManualCopy).Humanize(LetterCasing.Title)} Successfull";
string successfull = $"_ {nameof(Shared.Models.Stateless.IMapLogic.ManualCopy).Humanize(LetterCasing.Title)} Successfull";
foreach (KeyValuePair<long, PersonContainer> keyValuePair in _PersonKeyToPersonContainer)
{
if (keyValuePair.Value.Key is null || keyValuePair.Value.Birthdays is null || !keyValuePair.Value.Birthdays.Any())
@ -718,7 +703,7 @@ public class MapLogic
continue;
if (!personDisplayDirectoryAllFile.EndsWith(_Configuration.FacesFileNameExtension))
continue;
(id, normalizedRectangle, _) = IMapping.GetConverted(_Configuration.FacesFileNameExtension, personDisplayDirectoryAllFile);
(id, normalizedRectangle) = IMapping.GetConverted(_Configuration.FacesFileNameExtension, personDisplayDirectoryAllFile);
if (id is null || normalizedRectangle is null)
continue;
fileInfo = new(personDisplayDirectoryAllFile);
@ -790,7 +775,7 @@ public class MapLogic
SaveContainer saveContainer;
PersonBirthday personBirthday;
List<SaveContainer> saveContainers = new();
const string facePopulatedKey = nameof(IMapLogic.Sorting);
const string facePopulatedKey = nameof(Shared.Models.Stateless.IMapLogic.Sorting);
foreach (PersonContainer personContainer in _NotMappedPersonContainers)
{
if (personContainer.Key is null || personContainer.Birthdays is null || !personContainer.Birthdays.Any())
@ -804,13 +789,12 @@ public class MapLogic
SaveContainers(totalNotMapped, updated, saveContainers);
}
private (string, PersonBirthday?) GetPersonBirthday(string windowsShortcutPath)
private (string, PersonBirthday?) GetPersonBirthday(string[] directoryNames)
{
if (_Configuration is null)
throw new NullReferenceException(nameof(_Configuration));
PersonBirthday? personBirthday = null;
string personKeyFormatted = string.Empty;
string[] directoryNames = IPath.GetDirectoryNames(windowsShortcutPath);
foreach (string directoryName in directoryNames)
{
personBirthday = IPersonBirthday.GetPersonBirthday(_Configuration.PersonBirthdayFormat, directoryName);
@ -823,6 +807,26 @@ public class MapLogic
return new(personKeyFormatted, personBirthday);
}
private (string, PersonBirthday?) GetPersonBirthday(string windowsShortcutPath)
{
if (_Configuration is null)
throw new NullReferenceException(nameof(_Configuration));
string[] directoryNames = IPath.GetDirectoryNames(windowsShortcutPath);
(string personKeyFormatted, PersonBirthday? personBirthday) = GetPersonBirthday(directoryNames);
if (personBirthday is null)
{
string[] directories = Directory.GetDirectories(windowsShortcutPath, "*", SearchOption.TopDirectoryOnly);
foreach (string directory in directories)
{
directoryNames = IPath.GetDirectoryNames(directory);
(personKeyFormatted, personBirthday) = GetPersonBirthday(directoryNames);
if (personBirthday is not null)
break;
}
}
return new(personKeyFormatted, personBirthday);
}
private List<string> GetPersonKeyFormattedCollection(string[] jLinks, string a2PeopleSingletonDirectory, PersonContainer[] personContainers, Dictionary<long, int> personKeyToCount)
{
if (_Configuration is null)
@ -831,7 +835,6 @@ public class MapLogic
throw new NullReferenceException(nameof(_MapLogicSupport));
List<string> results = new();
string[] files;
string[] directories;
string checkDirectory;
string[] checkDirectories;
string personKeyFormatted;
@ -861,30 +864,12 @@ public class MapLogic
continue;
}
(personKeyFormatted, personBirthday) = GetPersonBirthday(windowsShortcut.Path);
if (personBirthday is not null)
{
if (!personKeyToCount.ContainsKey(personBirthday.Value.Ticks))
collection.Add(new(personBirthday.Value.Ticks, Path.Combine(checkDirectory, personKeyFormatted, fileNameWithoutExtension)));
else
collection.Add(new(personBirthday.Value.Ticks, Path.Combine(checkDirectory, personKeyFormatted, fileNameWithoutExtension, $"{personKeyToCount[personBirthday.Value.Ticks]} Face(s)")));
}
else
{
directories = Directory.GetDirectories(windowsShortcut.Path, "*", SearchOption.TopDirectoryOnly);
foreach (string directory in directories)
{
personKeyFormatted = Path.GetFileName(directory);
personBirthday = IPersonBirthday.GetPersonBirthday(_Configuration.PersonBirthdayFormat, personKeyFormatted);
if (personBirthday is null)
continue;
if (!personKeyToCount.ContainsKey(personBirthday.Value.Ticks))
collection.Add(new(personBirthday.Value.Ticks, Path.Combine(checkDirectory, personKeyFormatted, fileNameWithoutExtension)));
else
collection.Add(new(personBirthday.Value.Ticks, Path.Combine(checkDirectory, personKeyFormatted, fileNameWithoutExtension, $"{personKeyToCount[personBirthday.Value.Ticks]} Face(s)")));
}
}
if (!collection.Any())
if (personBirthday is null)
throw new NotSupportedException(fileNameWithoutExtension);
if (!personKeyToCount.ContainsKey(personBirthday.Value.Ticks))
collection.Add(new(personBirthday.Value.Ticks, Path.Combine(checkDirectory, personKeyFormatted, fileNameWithoutExtension)));
else
collection.Add(new(personBirthday.Value.Ticks, Path.Combine(checkDirectory, personKeyFormatted, fileNameWithoutExtension, $"{personKeyToCount[personBirthday.Value.Ticks]} Face(s)")));
foreach ((long personKey, string displayDirectoryName) in collection)
{
matches = (from l in personContainers where l.Key == personKey && l.ApproximateYears.HasValue select l).ToArray();
@ -902,7 +887,7 @@ public class MapLogic
return results;
}
private (int, FileHolder, int, string, string, string, string)[] GetCollectionForSaveResizedImagesByPersonKeyFormatted(string[] jLinks, string a2PeopleSingletonDirectory, PersonContainer[] personContainers, Mapping[] mappingCollection, Dictionary<long, int> personKeyToCount)
private (int, FileHolder, int, string, string, string, string)[] GetCollectionForSaveFilteredOriginalImagesFromJLinks(string[] jLinks, string a2PeopleSingletonDirectory, PersonContainer[] personContainers, Mapping[] mappingCollection, Dictionary<long, int> personKeyToCount)
{
if (_Configuration is null)
throw new NullReferenceException(nameof(_Configuration));
@ -914,13 +899,13 @@ public class MapLogic
string personKeyFormatted;
bool usePersonKeyAndDeterministicHashCodeKey = false;
List<string> personKeyFormattedCollection = GetPersonKeyFormattedCollection(jLinks, a2PeopleSingletonDirectory, personContainers, personKeyToCount);
List<(int Id, FileHolder ResizedFileHolder, int ApproximateYears, string PersonKeyFormatted, string CheckFile, string Directory, string PersonDirectory)> collection = new();
List<(int Id, FileHolder ImageFileHolder, int ApproximateYears, string PersonKeyFormatted, string CheckFile, string Directory, string PersonDirectory)> collection = new();
foreach (Mapping mapping in mappingCollection)
{
directoryName = Path.GetDirectoryName(mapping.MappingFromItem.RelativePath);
if (directoryName is null)
throw new NotSupportedException();
if (mapping.By is null or IMapLogic.Sorting)
if (mapping.By is null or Shared.Models.Stateless.IMapLogic.Sorting)
continue;
if (mapping.MappingFromPerson?.ApproximateYears is null)
continue;
@ -945,28 +930,28 @@ public class MapLogic
personDirectory = Path.Combine(directory, mapping.MappingFromPerson.DisplayDirectoryName);
checkFile = Path.Combine(directory, $"{mapping.MappingFromLocation.DeterministicHashCodeKey}{mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}");
}
collection.Add(new(mapping.MappingFromItem.Id, mapping.MappingFromItem.ResizedFileHolder, mapping.MappingFromPerson.ApproximateYears.Value, personKeyFormatted, directory, personDirectory, checkFile));
collection.Add(new(mapping.MappingFromItem.Id, mapping.MappingFromItem.ImageFileHolder, mapping.MappingFromPerson.ApproximateYears.Value, personKeyFormatted, directory, personDirectory, checkFile));
}
results = (from l in collection orderby l.ApproximateYears descending, l.PersonKeyFormatted descending select l).ToArray();
return results;
}
public void SaveResizedImagesByPersonKeyFormatted(string[] jLinks, string a2PeopleSingletonDirectory, PersonContainer[] personContainers, Mapping[] mappingCollection, Dictionary<long, int> personKeyToCount, int totalNotMapped)
public void SaveFilteredOriginalImagesFromJLinks(string[] jLinks, string a2PeopleSingletonDirectory, PersonContainer[] personContainers, Mapping[] mappingCollection, Dictionary<long, int> personKeyToCount, int totalNotMapped)
{
if (_Configuration is null)
throw new NullReferenceException(nameof(_Configuration));
SaveContainer? saveContainer;
List<int> distinctCollection = new();
List<SaveContainer> saveContainers = new();
(int, FileHolder, int, string, string, string, string)[] collection = GetCollectionForSaveResizedImagesByPersonKeyFormatted(jLinks, a2PeopleSingletonDirectory, personContainers, mappingCollection, personKeyToCount);
foreach ((int id, FileHolder resizedFileHolder, int approximateYears, string personKeyFormatted, string directory, string personDirectory, string checkFile) in collection)
(int, FileHolder, int, string, string, string, string)[] collection = GetCollectionForSaveFilteredOriginalImagesFromJLinks(jLinks, a2PeopleSingletonDirectory, personContainers, mappingCollection, personKeyToCount);
foreach ((int id, FileHolder imageFileHolder, int approximateYears, string personKeyFormatted, string directory, string personDirectory, string checkFile) in collection)
{
if (distinctCollection.Contains(id))
continue;
distinctCollection.Add(id);
saveContainer = new(personDirectory);
saveContainers.Add(saveContainer);
saveContainer = new(resizedFileHolder, checkFile, directory);
saveContainer = new(imageFileHolder, checkFile, directory);
saveContainers.Add(saveContainer);
}
SaveContainers(totalNotMapped, null, saveContainers);
@ -1013,7 +998,7 @@ public class MapLogic
{
if (mapping.MappingFromItem.ResizedFileHolder.DirectoryName is null || !mapping.MappingFromItem.ResizedFileHolder.Exists)
continue;
if (mapping.By is null or IMapLogic.Sorting || mapping.MappingFromPerson?.ApproximateYears is null)
if (mapping.By is null or Shared.Models.Stateless.IMapLogic.Sorting || mapping.MappingFromPerson?.ApproximateYears is null)
continue;
if (string.IsNullOrEmpty(mapping.MappingFromPerson.SegmentB))
throw new NotSupportedException();
@ -1028,7 +1013,7 @@ public class MapLogic
throw new NotSupportedException();
if (mapping.MappingFromItem.ResizedFileHolder.DirectoryName is null || !mapping.MappingFromItem.ResizedFileHolder.Exists)
continue;
if (mapping.By is null or IMapLogic.Sorting || mapping.MappingFromPerson?.ApproximateYears is null)
if (mapping.By is null or Shared.Models.Stateless.IMapLogic.Sorting || mapping.MappingFromPerson?.ApproximateYears is null)
{
if (mapping.MappingFromItem.ContainerDateTimes.Any() && !distinct.Contains(mapping.MappingFromItem.ResizedFileHolder.DirectoryName))
{
@ -1115,7 +1100,7 @@ public class MapLogic
string? facesDirectory;
FileHolder faceFileHolder;
List<int>? normalizedRectangles;
string by = nameof(IMapLogic.CopyNotMappedFaces);
string by = nameof(Shared.Models.Stateless.IMapLogic.CopyNotMappedFaces);
Dictionary<int, PersonContainer[]>? normalizedRectangleToPersonContainers;
foreach (KeyValuePair<int, Dictionary<int, Mapping>> keyValuePair in idToNormalizedRectangleToMapping)
{
@ -1409,4 +1394,11 @@ public class MapLogic
return results;
}
public void UpdatedPersonKeyToRanges(Configuration configuration, long ticks, Mapping[] mappingCollection)
{
Dictionary<long, (long LCL, long Minimum, long Maximum, long UCL)> personKeyToRanges = new();
Stateless.MapLogic.SetPersonTicks(configuration, ticks, mappingCollection, personKeyToRanges, _IdThenNormalizedRectangleToPersonContainers);
_PersonKeyToRanges = personKeyToRanges;
}
}