Save Closest is ready again with
all Deterministic Hash Code Key
This commit is contained in:
@ -96,7 +96,7 @@ public class Item
|
||||
bool? isWrongYear;
|
||||
DateTime minimumDateTime;
|
||||
PersonBirthday? personBirthday;
|
||||
float deterministicHashCodeKey;
|
||||
double deterministicHashCodeKey;
|
||||
List<string> personKeys = new();
|
||||
foreach (Item item in items)
|
||||
{
|
||||
@ -300,7 +300,7 @@ public class Item
|
||||
continue;
|
||||
if (named.PersonBirthday is null)
|
||||
continue;
|
||||
if (named.NormalizedPixelPercentage.HasValue && named.NormalizedPixelPercentage.Value != face.Location.NormalizedPixelPercentage)
|
||||
if (named.NormalizedPixelPercentage.HasValue && named.NormalizedPixelPercentage.Value != face.Location?.NormalizedPixelPercentage)
|
||||
continue;
|
||||
key = GetKey(named.MinimumDateTime, named.IsWrongYear, named.PersonBirthday);
|
||||
if (!results.ContainsKey(key))
|
||||
|
@ -29,57 +29,114 @@ public class Named
|
||||
this(isWrongYear, minimumDateTime, null, personBirthday)
|
||||
{ }
|
||||
|
||||
private static float GetDeterministicHashCodeFileName(int id, int normalizedPixelPercentage)
|
||||
=> float.Parse($"{id}.{normalizedPixelPercentage}");
|
||||
private static double GetDeterministicHashCodeFileName(int id, int normalizedPixelPercentage)
|
||||
=> double.Parse($"{id}.{normalizedPixelPercentage}");
|
||||
|
||||
public static float GetDeterministicHashCodeKey(Item item, Closest closest)
|
||||
public static double GetDeterministicHashCodeKey(Item item, Closest closest)
|
||||
{
|
||||
float result;
|
||||
double result;
|
||||
if (item.Property?.Id is null || item.ImageFileHolder is null || closest.NormalizedPixelPercentage is null)
|
||||
throw new NullReferenceException();
|
||||
result = GetDeterministicHashCodeFileName(item.Property.Id.Value, closest.NormalizedPixelPercentage.Value);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static float GetDeterministicHashCodeKey(Item item, IFace face)
|
||||
public static double GetDeterministicHashCodeKey(Item item, IFace face)
|
||||
{
|
||||
float result;
|
||||
double result;
|
||||
if (item.Property?.Id is null || item.ImageFileHolder is null || face.Location?.NormalizedPixelPercentage is null)
|
||||
throw new NullReferenceException();
|
||||
result = GetDeterministicHashCodeFileName(item.Property.Id.Value, face.Location.NormalizedPixelPercentage.Value);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static float? GetReversedDeterministicHashCode(Dictionary<int, List<IFace>> keyValuePairs, string fileName)
|
||||
public static double? GetReversedDeterministicHashCode(string fileName)
|
||||
{
|
||||
float? result;
|
||||
string[] segments = fileName.Split('.');
|
||||
if (segments.Length < 2)
|
||||
throw new Exception();
|
||||
string id = segments[0];
|
||||
string normalizedPixelPercentage;
|
||||
if (!id.Contains('-'))
|
||||
normalizedPixelPercentage = segments[1];
|
||||
else
|
||||
{
|
||||
segments = fileName.Split(' ');
|
||||
if (segments.Length < 3)
|
||||
throw new Exception();
|
||||
id = segments[2];
|
||||
string locationIdex = segments[0];
|
||||
if (int.TryParse(id, out int idValue) && int.TryParse(locationIdex, out int locationIndexValue) && keyValuePairs.ContainsKey(idValue) && keyValuePairs[idValue].Count > locationIndexValue)
|
||||
normalizedPixelPercentage = string.Concat(keyValuePairs[idValue][locationIndexValue].Location.NormalizedPixelPercentage);
|
||||
else
|
||||
{
|
||||
id = string.Empty;
|
||||
normalizedPixelPercentage = string.Empty;
|
||||
}
|
||||
}
|
||||
if (!float.TryParse(string.Concat(id, '.', normalizedPixelPercentage), out float resultValue))
|
||||
double? result;
|
||||
if (fileName.Length < 2 || fileName[1..].Contains('-'))
|
||||
result = null;
|
||||
else
|
||||
result = resultValue;
|
||||
{
|
||||
string[] segments = fileName.Split('.');
|
||||
if (segments.Length < 2)
|
||||
throw new Exception();
|
||||
string id = segments[0];
|
||||
string normalizedPixelPercentage = segments[1];
|
||||
if (!double.TryParse(string.Concat(id, '.', normalizedPixelPercentage), out double resultValue))
|
||||
result = null;
|
||||
else
|
||||
result = resultValue;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static (string?, double?) GetReversedDeterministicHashCode(Dictionary<int, List<IFace>> keyValuePairs, string file)
|
||||
{
|
||||
double? result;
|
||||
string? check;
|
||||
string fileName = Path.GetFileName(file);
|
||||
if (!fileName.Contains('-'))
|
||||
{
|
||||
check = null;
|
||||
result = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
string id;
|
||||
int? normalizedPixelPercentage;
|
||||
if (!keyValuePairs.Any())
|
||||
{
|
||||
check = null;
|
||||
id = string.Empty;
|
||||
normalizedPixelPercentage = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] segments = fileName.Split(' ');
|
||||
if (segments.Length < 3)
|
||||
throw new Exception();
|
||||
id = segments[2].Split('.')[0];
|
||||
string locationIdex = segments[0];
|
||||
if (!int.TryParse(id, out int idValue) || !int.TryParse(locationIdex, out int locationIndexValue) || !keyValuePairs.ContainsKey(idValue))
|
||||
{
|
||||
check = null;
|
||||
id = string.Empty;
|
||||
normalizedPixelPercentage = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
List<IFace> faces = keyValuePairs[idValue];
|
||||
if (faces.Count <= locationIndexValue)
|
||||
{
|
||||
check = null;
|
||||
id = string.Empty;
|
||||
normalizedPixelPercentage = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
IFace face = faces[locationIndexValue];
|
||||
if (face.Location?.NormalizedPixelPercentage is null)
|
||||
{
|
||||
check = null;
|
||||
id = string.Empty;
|
||||
normalizedPixelPercentage = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
string extensionLowered = Path.GetExtension(file).ToLower();
|
||||
normalizedPixelPercentage = face.Location.NormalizedPixelPercentage.Value;
|
||||
double deterministicHashCodeKey = GetDeterministicHashCodeFileName(idValue, normalizedPixelPercentage.Value);
|
||||
check = Path.Combine(string.Concat(Path.GetDirectoryName(file)), $"{deterministicHashCodeKey}{extensionLowered}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (normalizedPixelPercentage is null || !double.TryParse(string.Concat(id, '.', normalizedPixelPercentage.Value), out double resultValue))
|
||||
result = null;
|
||||
else
|
||||
result = resultValue;
|
||||
}
|
||||
return new(check, result);
|
||||
}
|
||||
|
||||
}
|
@ -22,8 +22,8 @@ public class PropertyLogic
|
||||
protected readonly string _DeterministicHashCodeRootDirectory;
|
||||
protected readonly Dictionary<int, string[]> _SixCharacterNamedFaceInfo;
|
||||
protected readonly Dictionary<int, string[]> _NamedFaceInfoDeterministicHashCodeKeyValuePairs;
|
||||
protected readonly Dictionary<float, string[]> _NamedDeterministicHashCodeKeyValuePairs;
|
||||
protected readonly Dictionary<float, string[]> _IncorrectDeterministicHashCodeKeyValuePairs;
|
||||
protected readonly Dictionary<double, string[]> _NamedDeterministicHashCodeKeyValuePairs;
|
||||
protected readonly Dictionary<double, string[]> _IncorrectDeterministicHashCodeKeyValuePairs;
|
||||
|
||||
public bool Reverse { get; }
|
||||
public List<string> AngleBracketCollection { get; }
|
||||
@ -31,8 +31,8 @@ public class PropertyLogic
|
||||
public Dictionary<int, int[]> IndicesFromNew => _IndicesFromNew;
|
||||
public List<string> ExceptionsDirectories => _ExceptionsDirectories;
|
||||
public string DeterministicHashCodeRootDirectory => _DeterministicHashCodeRootDirectory;
|
||||
public Dictionary<float, string[]> NamedDeterministicHashCodeKeyValuePairs => _NamedDeterministicHashCodeKeyValuePairs;
|
||||
public Dictionary<float, string[]> IncorrectDeterministicHashCodeKeyValuePairs => _IncorrectDeterministicHashCodeKeyValuePairs;
|
||||
public Dictionary<double, string[]> NamedDeterministicHashCodeKeyValuePairs => _NamedDeterministicHashCodeKeyValuePairs;
|
||||
public Dictionary<double, string[]> IncorrectDeterministicHashCodeKeyValuePairs => _IncorrectDeterministicHashCodeKeyValuePairs;
|
||||
public Dictionary<int, string[]> NamedFaceInfoDeterministicHashCodeKeyValuePairs => _NamedFaceInfoDeterministicHashCodeKeyValuePairs;
|
||||
|
||||
private readonly Model? _Model;
|
||||
@ -69,8 +69,8 @@ public class PropertyLogic
|
||||
List<KeyValuePair<int, int[]>>? collection;
|
||||
Dictionary<int, int[]> indicesFromNew = new();
|
||||
Dictionary<int, string[]>? sixCharacterNamedFaceInfo;
|
||||
Dictionary<float, string[]> namedDeterministicHashCode = new();
|
||||
Dictionary<float, string[]> incorrectDeterministicHashCode = new();
|
||||
Dictionary<double, string[]> namedDeterministicHashCode = new();
|
||||
Dictionary<double, string[]> incorrectDeterministicHashCode = new();
|
||||
string? rootDirectoryParent = Path.GetDirectoryName(configuration.RootDirectory);
|
||||
if (string.IsNullOrEmpty(rootDirectoryParent))
|
||||
throw new NullReferenceException(nameof(rootDirectoryParent));
|
||||
@ -84,9 +84,19 @@ public class PropertyLogic
|
||||
if (namedFaceInfoDeterministicHashCode is null)
|
||||
throw new NullReferenceException(nameof(namedFaceInfoDeterministicHashCode));
|
||||
}
|
||||
if (namedFaceInfoDeterministicHashCode.Any())
|
||||
{
|
||||
string[] directories = Directory.GetDirectories(rootDirectoryParent, "*DeterministicHashCode*", SearchOption.TopDirectoryOnly);
|
||||
if (!directories.Any())
|
||||
deterministicHashCodeRootDirectory = string.Empty;
|
||||
else
|
||||
{
|
||||
Dictionary<int, List<IFace>> faces = new();
|
||||
deterministicHashCodeRootDirectory = directories[0];
|
||||
SetKeyValuePairs(deterministicHashCodeRootDirectory, namedDeterministicHashCode, incorrectDeterministicHashCode, faces);
|
||||
}
|
||||
if (!namedFaceInfoDeterministicHashCode.Any())
|
||||
sixCharacterNamedFaceInfo = new();
|
||||
else
|
||||
{
|
||||
files = Directory.GetFiles(rootDirectoryParent, "*SixCharacter*.json", SearchOption.TopDirectoryOnly);
|
||||
if (files.Length != 1)
|
||||
sixCharacterNamedFaceInfo = new();
|
||||
@ -98,19 +108,6 @@ public class PropertyLogic
|
||||
throw new NullReferenceException(nameof(sixCharacterNamedFaceInfo));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sixCharacterNamedFaceInfo = new();
|
||||
string[] directories = Directory.GetDirectories(rootDirectoryParent, "*DeterministicHashCode*", SearchOption.TopDirectoryOnly);
|
||||
if (!directories.Any())
|
||||
deterministicHashCodeRootDirectory = string.Empty;
|
||||
else
|
||||
{
|
||||
Dictionary<int, List<IFace>> faces = new();
|
||||
deterministicHashCodeRootDirectory = directories[0];
|
||||
SetKeyValuePairs(deterministicHashCodeRootDirectory, namedDeterministicHashCode, incorrectDeterministicHashCode, faces);
|
||||
}
|
||||
}
|
||||
files = Directory.GetFiles(rootDirectoryParent, "*keyValuePairs*.json", SearchOption.TopDirectoryOnly);
|
||||
if (files.Length != 1)
|
||||
keyValuePairs = new();
|
||||
@ -148,15 +145,16 @@ public class PropertyLogic
|
||||
_NamedFaceInfoDeterministicHashCodeKeyValuePairs = namedFaceInfoDeterministicHashCode;
|
||||
}
|
||||
|
||||
private static void SetKeyValuePairs(string deterministicHashCodeRootDirectory, List<(string, float)> named, List<(string, float)> incorrect, Dictionary<int, List<IFace>> keyValuePairs)
|
||||
private static void SetKeyValuePairs(string deterministicHashCodeRootDirectory, List<(string, double)> named, List<(string, double)> incorrect, Dictionary<int, List<IFace>> keyValuePairs)
|
||||
{
|
||||
string[] files;
|
||||
string fileName;
|
||||
string personKey;
|
||||
string? checkFile;
|
||||
string[] yearDirectories;
|
||||
string[] personKeyDirectories;
|
||||
string[] personNameDirectories;
|
||||
float? idAndNormalizedPixelPercentage;
|
||||
double? idAndNormalizedPixelPercentage;
|
||||
string[] ticksDirectories = Directory.GetDirectories(deterministicHashCodeRootDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string ticksDirectory in ticksDirectories)
|
||||
{
|
||||
@ -176,9 +174,15 @@ public class PropertyLogic
|
||||
if (file.EndsWith(".lnk"))
|
||||
continue;
|
||||
fileName = Path.GetFileName(file);
|
||||
idAndNormalizedPixelPercentage = Named.GetReversedDeterministicHashCode(keyValuePairs, fileName);
|
||||
idAndNormalizedPixelPercentage = Named.GetReversedDeterministicHashCode(fileName);
|
||||
if (idAndNormalizedPixelPercentage is null)
|
||||
break;
|
||||
{
|
||||
(checkFile, idAndNormalizedPixelPercentage) = Named.GetReversedDeterministicHashCode(keyValuePairs, file);
|
||||
if (idAndNormalizedPixelPercentage is null)
|
||||
break;
|
||||
if (!string.IsNullOrEmpty(checkFile))
|
||||
File.Move(file, checkFile);
|
||||
}
|
||||
incorrect.Add(new(personKey, idAndNormalizedPixelPercentage.Value));
|
||||
}
|
||||
foreach (string personNameDirectory in personNameDirectories)
|
||||
@ -188,10 +192,16 @@ public class PropertyLogic
|
||||
{
|
||||
if (file.EndsWith(".lnk"))
|
||||
continue;
|
||||
fileName = Path.GetFileNameWithoutExtension(file);
|
||||
idAndNormalizedPixelPercentage = Named.GetReversedDeterministicHashCode(keyValuePairs, fileName);
|
||||
fileName = Path.GetFileName(file);
|
||||
idAndNormalizedPixelPercentage = Named.GetReversedDeterministicHashCode(fileName);
|
||||
if (idAndNormalizedPixelPercentage is null)
|
||||
break;
|
||||
{
|
||||
(checkFile, idAndNormalizedPixelPercentage) = Named.GetReversedDeterministicHashCode(keyValuePairs, file);
|
||||
if (idAndNormalizedPixelPercentage is null)
|
||||
break;
|
||||
if (!string.IsNullOrEmpty(checkFile))
|
||||
File.Move(file, checkFile);
|
||||
}
|
||||
named.Add(new(personKey, idAndNormalizedPixelPercentage.Value));
|
||||
}
|
||||
}
|
||||
@ -200,51 +210,57 @@ public class PropertyLogic
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetKeyValuePairs(string deterministicHashCodeRootDirectory, Dictionary<float, string[]> namedDeterministicHashCode, Dictionary<float, string[]> incorrectDeterministicHashCode, Dictionary<int, List<IFace>> keyValuePairs)
|
||||
private static void SetKeyValuePairs(string deterministicHashCodeRootDirectory, Dictionary<double, string[]> namedDeterministicHashCode, Dictionary<double, string[]> incorrectDeterministicHashCode, Dictionary<int, List<IFace>> keyValuePairs)
|
||||
{
|
||||
Dictionary<float, List<string>> namedKeyValuePairs = new();
|
||||
Dictionary<float, List<string>> incorrectKeyValuePairs = new();
|
||||
List<(string PersonKey, float IdAndNormalizedPixelPercentage)> named = new();
|
||||
List<(string PersonKey, float IdAndNormalizedPixelPercentage)> incorrect = new();
|
||||
Dictionary<double, List<string>> namedKeyValuePairs = new();
|
||||
Dictionary<double, List<string>> incorrectKeyValuePairs = new();
|
||||
List<(string PersonKey, double IdAndNormalizedPixelPercentage)> named = new();
|
||||
List<(string PersonKey, double IdAndNormalizedPixelPercentage)> incorrect = new();
|
||||
SetKeyValuePairs(deterministicHashCodeRootDirectory, named, incorrect, keyValuePairs);
|
||||
named = (from l in named orderby l.IdAndNormalizedPixelPercentage select l).ToList();
|
||||
incorrect = (from l in incorrect orderby l.IdAndNormalizedPixelPercentage select l).ToList();
|
||||
foreach ((string personKey, float idAndNormalizedPixelPercentage) in named)
|
||||
foreach ((string personKey, double idAndNormalizedPixelPercentage) in named)
|
||||
{
|
||||
if (!namedKeyValuePairs.ContainsKey(idAndNormalizedPixelPercentage))
|
||||
namedKeyValuePairs.Add(idAndNormalizedPixelPercentage, new());
|
||||
namedKeyValuePairs[idAndNormalizedPixelPercentage].Add(personKey);
|
||||
}
|
||||
foreach ((string personKey, float idAndNormalizedPixelPercentage) in incorrect)
|
||||
foreach ((string personKey, double idAndNormalizedPixelPercentage) in incorrect)
|
||||
{
|
||||
if (!incorrectKeyValuePairs.ContainsKey(idAndNormalizedPixelPercentage))
|
||||
incorrectKeyValuePairs.Add(idAndNormalizedPixelPercentage, new());
|
||||
incorrectKeyValuePairs[idAndNormalizedPixelPercentage].Add(personKey);
|
||||
}
|
||||
foreach (KeyValuePair<float, List<string>> keyValuePair in namedKeyValuePairs)
|
||||
foreach (KeyValuePair<double, List<string>> keyValuePair in namedKeyValuePairs)
|
||||
namedDeterministicHashCode.Add(keyValuePair.Key, keyValuePair.Value.Distinct().ToArray());
|
||||
foreach (KeyValuePair<float, List<string>> keyValuePair in incorrectKeyValuePairs)
|
||||
foreach (KeyValuePair<double, List<string>> keyValuePair in incorrectKeyValuePairs)
|
||||
incorrectDeterministicHashCode.Add(keyValuePair.Key, keyValuePair.Value.Distinct().ToArray());
|
||||
}
|
||||
|
||||
public void UpdateKeyValuePairs(List<Container> containers)
|
||||
{
|
||||
Dictionary<int, List<IFace>> keyValuePairs = new();
|
||||
Dictionary<float, string[]> namedDeterministicHashCode = new();
|
||||
Dictionary<float, string[]> incorrectDeterministicHashCode = new();
|
||||
Dictionary<double, string[]> namedDeterministicHashCode = new();
|
||||
Dictionary<double, string[]> incorrectDeterministicHashCode = new();
|
||||
foreach (Container container in containers)
|
||||
{
|
||||
foreach (Item item in container.Items)
|
||||
{
|
||||
if (item.ImageFileHolder is null || item.Property?.Id is null || !item.Faces.Any())
|
||||
continue;
|
||||
if (keyValuePairs.ContainsKey(item.Property.Id.Value))
|
||||
{
|
||||
if (keyValuePairs[item.Property.Id.Value].Count != item.Faces.Count)
|
||||
throw new Exception();
|
||||
continue;
|
||||
}
|
||||
keyValuePairs.Add(item.Property.Id.Value, item.Faces);
|
||||
}
|
||||
}
|
||||
SetKeyValuePairs(_DeterministicHashCodeRootDirectory, namedDeterministicHashCode, incorrectDeterministicHashCode, keyValuePairs);
|
||||
foreach (KeyValuePair<float, string[]> keyValuePair in namedDeterministicHashCode)
|
||||
foreach (KeyValuePair<double, string[]> keyValuePair in namedDeterministicHashCode)
|
||||
_NamedDeterministicHashCodeKeyValuePairs.Add(keyValuePair.Key, keyValuePair.Value);
|
||||
foreach (KeyValuePair<float, string[]> keyValuePair in incorrectDeterministicHashCode)
|
||||
foreach (KeyValuePair<double, string[]> keyValuePair in incorrectDeterministicHashCode)
|
||||
_IncorrectDeterministicHashCodeKeyValuePairs.Add(keyValuePair.Key, keyValuePair.Value);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user