Re-Write without checking mapped
This commit is contained in:
@ -5,24 +5,11 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
internal abstract class Mapping
|
||||
{
|
||||
|
||||
private static double GetDeterministicHashCodeKey(int id, int normalizedPixelPercentage)
|
||||
=> Math.Round(double.Parse($"{id}.{normalizedPixelPercentage}"), Stateless.ILocation.Digits);
|
||||
|
||||
internal static double GetDeterministicHashCodeKey(Models.Item item, Models.Closest closest)
|
||||
{
|
||||
double result;
|
||||
if (item.Property?.Id is null || item.ImageFileHolder is null)
|
||||
throw new NullReferenceException();
|
||||
result = GetDeterministicHashCodeKey(item.Property.Id.Value, closest.NormalizedPixelPercentage);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static double GetDeterministicHashCodeKey(Models.Item item, Models.Face face)
|
||||
{
|
||||
double result;
|
||||
if (item.Property?.Id is null || item.ImageFileHolder is null || face.Location?.NormalizedPixelPercentage is null)
|
||||
throw new NullReferenceException();
|
||||
result = GetDeterministicHashCodeKey(item.Property.Id.Value, face.Location.NormalizedPixelPercentage.Value);
|
||||
double result = IMapping.GetDeterministicHashCodeKeyValue(item.Property.Id.Value, face.Location.NormalizedPixelPercentage.Value);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -37,7 +24,7 @@ internal abstract class Mapping
|
||||
{
|
||||
if (face.FaceEncoding is null || face.Location?.NormalizedPixelPercentage is null)
|
||||
continue;
|
||||
if (normalizedPixelPercentageValue != face.Location.NormalizedPixelPercentage.Value && deterministicHashCodeKey != GetDeterministicHashCodeKey(id, face.Location.NormalizedPixelPercentage.Value))
|
||||
if (normalizedPixelPercentageValue != face.Location.NormalizedPixelPercentage.Value && deterministicHashCodeKey != IMapping.GetDeterministicHashCodeKeyValue(id, face.Location.NormalizedPixelPercentage.Value))
|
||||
continue;
|
||||
collection.Add(face);
|
||||
}
|
||||
@ -56,36 +43,46 @@ internal abstract class Mapping
|
||||
}
|
||||
}
|
||||
|
||||
private static double? GetReversedDeterministicHashCodeFromSegments(bool keyValuePairsAny, Dictionary<int, List<Models.Face>> keyValuePairs, string file, string[] segments)
|
||||
private static (int?, int?, double?) GetReversedDeterministicHashCodeKeysFromSegments(bool keyValuePairsAny, Dictionary<int, List<Models.Face>> keyValuePairs, string file, string[] segments)
|
||||
{
|
||||
double? result;
|
||||
if (segments.Length != 3)
|
||||
throw new Exception();
|
||||
string id = segments[0];
|
||||
int normalizedPixelPercentageValue;
|
||||
string normalizedPixelPercentage = segments[1];
|
||||
if (!int.TryParse(id, out int idValue) || !int.TryParse(normalizedPixelPercentage, out int normalizedPixelPercentageValue))
|
||||
if (!int.TryParse(id, out int idValue) | !int.TryParse(normalizedPixelPercentage, out normalizedPixelPercentageValue))
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
result = GetDeterministicHashCodeKey(idValue, normalizedPixelPercentageValue);
|
||||
result = IMapping.GetDeterministicHashCodeKeyValue(idValue, normalizedPixelPercentageValue);
|
||||
if (keyValuePairsAny && keyValuePairs.ContainsKey(idValue))
|
||||
UseKeyValuePairsSaveFaceEncoding(keyValuePairs, file, idValue, normalizedPixelPercentageValue, result.Value, $".{segments[2]}");
|
||||
}
|
||||
return result;
|
||||
return new(idValue, normalizedPixelPercentageValue, result);
|
||||
}
|
||||
|
||||
internal static double? GetReversedDeterministicHashCodeKey(bool keyValuePairsAny, Dictionary<int, List<Models.Face>> keyValuePairs, string file)
|
||||
internal static (int?, int?) GetReversedDeterministicHashCodeKey(bool keyValuePairsAny, Dictionary<int, List<Models.Face>> keyValuePairs, string file)
|
||||
{
|
||||
double? result;
|
||||
int? id;
|
||||
int? normalizedPixelPercentage;
|
||||
string fileName = Path.GetFileName(file);
|
||||
if (fileName.Length < 2 || fileName[1..].Contains('-'))
|
||||
result = null;
|
||||
{
|
||||
id = null;
|
||||
normalizedPixelPercentage = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] segments = fileName.Split('.');
|
||||
result = GetReversedDeterministicHashCodeFromSegments(keyValuePairsAny, keyValuePairs, file, segments);
|
||||
(id, normalizedPixelPercentage, double? result) = GetReversedDeterministicHashCodeKeysFromSegments(keyValuePairsAny, keyValuePairs, file, segments);
|
||||
if (result is null)
|
||||
{
|
||||
id = null;
|
||||
normalizedPixelPercentage = null;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return new(id, normalizedPixelPercentage);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user