Bug fix and clean up
This commit is contained in:
@ -32,10 +32,7 @@ public class MapLogic
|
||||
private readonly string _ResizeFilenameExtension;
|
||||
private readonly string _FacePartsFilenameExtension;
|
||||
private readonly string _FacesHiddenFilenameExtension;
|
||||
private readonly string _ZPropertyHolderContentDirectory;
|
||||
private readonly string _ZPropertyHolderContentTicksDirectory;
|
||||
private readonly string _ZPropertyHolderSingletonTicksDirectory;
|
||||
private readonly Property.Models.Configuration _PropertyConfiguration;
|
||||
|
||||
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)
|
||||
{
|
||||
@ -43,14 +40,17 @@ public class MapLogic
|
||||
_PersonKeysRanges = new();
|
||||
_Configuration = configuration;
|
||||
_Log = Serilog.Log.ForContext<MapLogic>();
|
||||
_PropertyConfiguration = propertyConfiguration;
|
||||
_FacesFilenameExtension = facesFilenameExtension;
|
||||
_MaxDegreeOfParallelism = maxDegreeOfParallelism;
|
||||
_ResizeFilenameExtension = resizeFilenameExtension;
|
||||
_FacePartsFilenameExtension = facePartsFilenameExtension;
|
||||
_FacesHiddenFilenameExtension = facesHiddenFilenameExtension;
|
||||
if (_Log is null)
|
||||
{ }
|
||||
if (propertyConfiguration.VerifyToSeason is null || !propertyConfiguration.VerifyToSeason.Any())
|
||||
throw new Exception();
|
||||
if (_MaxDegreeOfParallelism == 0)
|
||||
{ }
|
||||
string json;
|
||||
string[] files;
|
||||
string fullPath;
|
||||
@ -60,15 +60,13 @@ public class MapLogic
|
||||
Dictionary<int, int[]>? keyValuePairs;
|
||||
List<KeyValuePair<int, int[]>>? collection;
|
||||
Dictionary<int, int[]> indicesFromNew = new();
|
||||
string? rootDirectoryParent = Path.GetDirectoryName(propertyConfiguration.RootDirectory);
|
||||
Dictionary<long, (string, int?, PersonBirthday[], long)> peopleKeyValuePairs = new();
|
||||
string zPropertyHolderContentDirectory = Path.Combine(zResultsFullGroupDirectory, "()");
|
||||
string zPropertyHolderSingletonDirectory = Path.Combine(zResultsFullGroupDirectory, "{}");
|
||||
string? rootDirectoryParent = Path.GetDirectoryName(propertyConfiguration.RootDirectory);
|
||||
Dictionary<int, Dictionary<int, PersonBirthday[]>> idThenNormalizedPixelPercentageKeyValuePairs = new();
|
||||
string zPropertyHolderContentTicksDirectory = Path.Combine(zPropertyHolderContentDirectory, $"({ticks})");
|
||||
string zPropertyHolderPeopleContentDirectory = Path.Combine(peopleDateGroupDirectory, "()", "(KnownPeople)");
|
||||
Dictionary<int, Dictionary<int, PersonBirthday[]>> incorrectIdThenNormalizedPixelPercentageKeyValuePairs = new();
|
||||
string zPropertyHolderSingletonTicksDirectory = Path.Combine(zPropertyHolderSingletonDirectory, string.Concat('{', _Ticks, '}'));
|
||||
for (int i = 1; i < 5; i++)
|
||||
_ = IPath.DeleteEmptyDirectories(zPropertyHolderContentDirectory);
|
||||
_ = IPath.DeleteEmptyDirectories(zPropertyHolderContentDirectory);
|
||||
@ -114,9 +112,7 @@ public class MapLogic
|
||||
_SkipCollection = skipCollection;
|
||||
_NotMappedPersonKeys = notMappedTicks;
|
||||
_PeopleKeyValuePairs = peopleKeyValuePairs;
|
||||
_ZPropertyHolderContentDirectory = zPropertyHolderContentDirectory;
|
||||
_ZPropertyHolderContentTicksDirectory = zPropertyHolderContentTicksDirectory;
|
||||
_ZPropertyHolderSingletonTicksDirectory = zPropertyHolderSingletonTicksDirectory;
|
||||
_IdThenNormalizedPixelPercentageKeyValuePairs = idThenNormalizedPixelPercentageKeyValuePairs;
|
||||
_IncorrectIdThenNormalizedPixelPercentageKeyValuePairs = incorrectIdThenNormalizedPixelPercentageKeyValuePairs;
|
||||
}
|
||||
@ -139,17 +135,6 @@ public class MapLogic
|
||||
|
||||
public bool Skip(double deterministicHashCodeKey) => _SkipCollection.Contains(deterministicHashCodeKey);
|
||||
|
||||
private long LogDelta(long ticks, string? methodName)
|
||||
{
|
||||
long result;
|
||||
if (_Log is null)
|
||||
throw new NullReferenceException(nameof(_Log));
|
||||
double delta = new TimeSpan(DateTime.Now.Ticks - ticks).TotalMilliseconds;
|
||||
_Log.Debug($"{methodName} took {Math.Floor(delta)} millisecond(s)");
|
||||
result = DateTime.Now.Ticks;
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<(long, long, long, long)> GetPersonKeysRangesCollection(PersonBirthday[] personBirthdays)
|
||||
{
|
||||
List<(long, long, long, long)> results = new();
|
||||
@ -295,32 +280,6 @@ public class MapLogic
|
||||
return result;
|
||||
}
|
||||
|
||||
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;
|
||||
Dictionary<int, string[]>? keyValuePairs = JsonSerializer.Deserialize<Dictionary<int, string[]>>(json);
|
||||
if (keyValuePairs is null)
|
||||
throw new NullReferenceException(nameof(keyValuePairs));
|
||||
foreach (KeyValuePair<int, string[]> keyValuePair in keyValuePairs)
|
||||
{
|
||||
personBirthdays = new();
|
||||
foreach (string personKey in keyValuePair.Value)
|
||||
{
|
||||
personBirthday = IPersonBirthday.GetPersonBirthday(_Configuration.PersonBirthdayFormat, personKey);
|
||||
if (personBirthday is null)
|
||||
continue;
|
||||
}
|
||||
if (!personBirthdays.Any())
|
||||
continue;
|
||||
results.Add(keyValuePair.Key, personBirthdays.ToArray());
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
public int AddToMapping(List<Face> distinctFilteredFaces)
|
||||
{
|
||||
if (_Configuration is null)
|
||||
@ -527,32 +486,6 @@ public class MapLogic
|
||||
return results;
|
||||
}
|
||||
|
||||
private static Dictionary<int, Dictionary<int, Face>> Convert(List<(int Id, Face Face)> collection)
|
||||
{
|
||||
Dictionary<int, Dictionary<int, Face>> results = new();
|
||||
Dictionary<int, Face> keyValuePairs;
|
||||
foreach ((int id, Face face) in collection)
|
||||
{
|
||||
if (!results.ContainsKey(id))
|
||||
results.Add(id, new());
|
||||
if (face.Location?.NormalizedPixelPercentage is null)
|
||||
throw new NotSupportedException();
|
||||
keyValuePairs = results[id];
|
||||
if (keyValuePairs.ContainsKey(face.Location.NormalizedPixelPercentage.Value))
|
||||
continue;
|
||||
results[id].Add(face.Location.NormalizedPixelPercentage.Value, face);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private Dictionary<int, List<int>> GetUsedIdThenNormalizedPixelPercentageKeyValuePairs()
|
||||
{
|
||||
Dictionary<int, List<int>> results = new();
|
||||
foreach (KeyValuePair<int, Dictionary<int, PersonBirthday[]>> keyValuePair in _IdThenNormalizedPixelPercentageKeyValuePairs)
|
||||
results.Add(keyValuePair.Key, (from l in keyValuePair.Value select l.Key).ToList());
|
||||
return results;
|
||||
}
|
||||
|
||||
private int UpdateFromSortingContainers(SortingContainer[] sortingContainers)
|
||||
{
|
||||
if (_Configuration is null)
|
||||
@ -687,11 +620,11 @@ public class MapLogic
|
||||
{
|
||||
_Mapping => nameof(_Mapping),
|
||||
_Sorting => nameof(_Sorting),
|
||||
_ForceSingleImage => nameof(MapLogic.ForceSingleImage),
|
||||
_ForceSingleImage => nameof(_ForceSingleImage),
|
||||
_ => throw new NotImplementedException()
|
||||
};
|
||||
}
|
||||
directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, by, personKeyFormatted, face.Mapping.MappingFromPerson.SegmentB);
|
||||
directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, by[1..], personKeyFormatted, face.Mapping.MappingFromPerson.SegmentB);
|
||||
if (!keyValuePairs.ContainsKey(directory))
|
||||
keyValuePairs.Add(directory, 0);
|
||||
keyValuePairs[directory]++;
|
||||
@ -704,8 +637,8 @@ public class MapLogic
|
||||
personDirectory = Path.Combine(directory, face.Mapping.MappingFromPerson.DisplayDirectoryName[..1], "lnk");
|
||||
saveContainer = new(personDirectory);
|
||||
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));
|
||||
facesDirectory = Path.Combine($"{dFacesContentDirectory}{directoryName}", face.Mapping.MappingFromItem.ImageFileHolder.NameWithoutExtension);
|
||||
facePartsDirectory = Path.Combine($"{d2ResultsFullGroupDirectory}{directoryName}", face.Mapping.MappingFromItem.ImageFileHolder.NameWithoutExtension);
|
||||
checkFile = Path.Combine(directory, $"{face.Mapping.MappingFromLocation.DeterministicHashCodeKey}{face.Mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}");
|
||||
faceFileHolder = new(Path.Combine(facesDirectory, $"{face.Mapping.MappingFromLocation.DeterministicHashCodeKey}{face.Mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}{_FacesFilenameExtension}"));
|
||||
hiddenFaceFileHolder = new(Path.Combine(facesDirectory, $"{face.Mapping.MappingFromLocation.DeterministicHashCodeKey}{face.Mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}{_FacesHiddenFilenameExtension}"));
|
||||
|
Reference in New Issue
Block a user