(637967784888423594)-2,042.zip
(637969699845057599)-548.zip
This commit is contained in:
2022-08-24 21:25:03 -07:00
parent 2d9c912ba7
commit 674555b4fc
17 changed files with 184 additions and 230 deletions

View File

@ -85,7 +85,7 @@ public class Item : Properties.IItem
else if (fileHolder.ExtensionLowered.Length > 3 && fileHolder.ExtensionLowered[3] == 'e' && fileHolder.ExtensionLowered.Remove(3, 1) == filenameExtension)
_ResizedFileHolder = fileHolder;
else
throw new NotImplementedException();
_ResizedFileHolder = fileHolder;
}
public bool Any() => (_Abandoned.HasValue && _Abandoned.Value) || (_Changed.HasValue && _Changed.Value) || (_Moved.HasValue && _Moved.Value) || (_NoJson.HasValue && _NoJson.Value);

View File

@ -108,8 +108,6 @@ public class Location : Properties.ILocation, IEquatable<Location>
{
int result;
double value;
int decimals = 6;
int factor = 1000000;
double total = width * height;
Check(bottom, left, right, top, zCount);
double xCenter = left + ((right - left) / 2);
@ -118,7 +116,7 @@ public class Location : Properties.ILocation, IEquatable<Location>
value = at / total;
if (value < 0)
value = 3;
result = (int)(Math.Round(value, decimals) * factor);
result = (int)(Math.Round(value, Stateless.ILocation.Decimals) * Stateless.ILocation.Factor);
return result;
}

View File

@ -0,0 +1,11 @@
namespace View_by_Distance.Shared.Models.Stateless;
public interface IClosest
{
const int MaximumPer = 50;
const float MaximumMinimum = 0.50f;
const bool SkipIsWrongYear = true;
const float MinimumMinimum = 0.05f;
}

View File

@ -0,0 +1,9 @@
namespace View_by_Distance.Shared.Models.Stateless;
public interface ILocation
{
const int Decimals = 6;
const int Factor = 1000000;
}

View File

@ -0,0 +1,7 @@
namespace View_by_Distance.Shared.Models.Stateless;
public interface IPerson
{
const string KeyFormat = "yyyy-MM-dd_HH";
}

View File

@ -3,6 +3,6 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
internal abstract class Closest
{
internal static Models.Closest[] Get(List<Models.Closest> collection) => (from l in collection orderby l.Minimum < IClosest.MinimumMinimum, l.Average select l).ToArray();
internal static Models.Closest[] Get(List<Models.Closest> collection) => (from l in collection orderby l.Minimum < Stateless.IClosest.MinimumMinimum, l.Average select l).ToArray();
}

View File

@ -3,11 +3,6 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
public interface IClosest
{ // ...
const int MaximumPer = 50;
const float MaximumMinimum = 0.50f;
const bool SkipIsWrongYear = true;
const float MinimumMinimum = 0.05f;
Models.Closest[] TestStatic_Get(List<Models.Closest> collection);
static Models.Closest[] Get(List<Models.Closest> collection) => Closest.Get(collection);

View File

@ -3,9 +3,9 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
public interface INamed
{ // ...
double? TestStatic_GetReversedDeterministicHashCode(string fileName);
static double? GetReversedDeterministicHashCode(string fileName) =>
Named.GetReversedDeterministicHashCode(fileName);
double? TestStatic_GetReversedDeterministicHashCodeKey(string file);
static double? GetReversedDeterministicHashCodeKey(bool keyValuePairsAny, Dictionary<int, List<Models.Face>> keyValuePairs, string file) =>
Named.GetReversedDeterministicHashCodeKey(keyValuePairsAny, keyValuePairs, file);
double TestStatic_GetDeterministicHashCodeKey(Models.Item item, Models.Face face);
static double GetDeterministicHashCodeKey(Models.Item item, Models.Face face) =>
@ -15,8 +15,4 @@ public interface INamed
static double GetDeterministicHashCodeKey(Models.Item item, Models.Closest closest) =>
Named.GetDeterministicHashCodeKey(item, closest);
(string?, double?) TestStatic_GetReversedDeterministicHashCode(Dictionary<int, List<Models.Face>> keyValuePairs, string file);
static (string?, double?) GetReversedDeterministicHashCode(Dictionary<int, List<Models.Face>> keyValuePairs, string file) =>
Named.GetReversedDeterministicHashCode(keyValuePairs, file);
}

View File

@ -1,17 +1,19 @@
using System.Text.Json;
namespace View_by_Distance.Shared.Models.Stateless.Methods;
internal abstract class Named
{
private static double GetDeterministicHashCodeFileName(int id, int normalizedPixelPercentage)
=> double.Parse($"{id}.{normalizedPixelPercentage}");
private static double GetDeterministicHashCodeKey(int id, int normalizedPixelPercentage)
=> Math.Round(double.Parse($"{id}.{normalizedPixelPercentage}"), Stateless.ILocation.Decimals);
internal static double GetDeterministicHashCodeKey(Models.Item item, Models.Closest closest)
{
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);
result = GetDeterministicHashCodeKey(item.Property.Id.Value, closest.NormalizedPixelPercentage.Value);
return result;
}
@ -20,127 +22,70 @@ internal abstract class Named
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);
result = GetDeterministicHashCodeKey(item.Property.Id.Value, face.Location.NormalizedPixelPercentage.Value);
return result;
}
private static double? GetReversedDeterministicHashCodeB(string fileName)
private static void UseKeyValuePairsSaveFaceEncoding(Dictionary<int, List<Models.Face>> keyValuePairs, string file, int id, int normalizedPixelPercentageValue, double deterministicHashCodeKey, string extensionLowered)
{
string json;
string checkFile;
string? directoryName;
List<Models.Face> collection = new();
List<Models.Face> faces = keyValuePairs[id];
foreach (Models.Face face in faces)
{
if (face.FaceEncoding is null || face.Location?.NormalizedPixelPercentage is null)
continue;
if (normalizedPixelPercentageValue != face.Location.NormalizedPixelPercentage.Value && deterministicHashCodeKey != GetDeterministicHashCodeKey(id, face.Location.NormalizedPixelPercentage.Value))
continue;
collection.Add(face);
}
if (collection.Count != 1)
throw new Exception();
foreach (Models.Face face in collection)
{
directoryName = Path.GetDirectoryName(file);
if (string.IsNullOrEmpty(directoryName))
continue;
checkFile = Path.Combine(directoryName, $"{deterministicHashCodeKey}{extensionLowered}.json");
if (File.Exists(checkFile))
continue;
json = JsonSerializer.Serialize(face.FaceEncoding);
_ = IPath.WriteAllText(checkFile, json, updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null);
}
}
private static double? GetReversedDeterministicHashCodeFromSegments(bool keyValuePairsAny, Dictionary<int, List<Models.Face>> keyValuePairs, string file, string[] segments)
{
double? result;
string[] segments = fileName.Split('.');
if (segments.Length < 2)
if (segments.Length != 3)
throw new Exception();
string id = segments[0];
string normalizedPixelPercentage = segments[1];
if (!double.TryParse(string.Concat(id, '.', normalizedPixelPercentage), out double resultValue))
if (!int.TryParse(id, out int idValue) || !int.TryParse(normalizedPixelPercentage, out int normalizedPixelPercentageValue))
result = null;
else
result = resultValue;
{
result = GetDeterministicHashCodeKey(idValue, normalizedPixelPercentageValue);
if (keyValuePairsAny && keyValuePairs.ContainsKey(idValue))
UseKeyValuePairsSaveFaceEncoding(keyValuePairs, file, idValue, normalizedPixelPercentageValue, result.Value, $".{segments[2]}");
}
return result;
}
internal static double? GetReversedDeterministicHashCode(string fileName)
internal static double? GetReversedDeterministicHashCodeKey(bool keyValuePairsAny, Dictionary<int, List<Models.Face>> keyValuePairs, string file)
{
double? result;
string fileName = Path.GetFileName(file);
if (fileName.Length < 2 || fileName[1..].Contains('-'))
result = null;
else
result = GetReversedDeterministicHashCodeB(fileName);
{
string[] segments = fileName.Split('.');
result = GetReversedDeterministicHashCodeFromSegments(keyValuePairsAny, keyValuePairs, file, segments);
}
return result;
}
private static (string? check, int? normalizedPixelPercentage) GetReversedDeterministicHashCodeFromFace(string file, int idValue, int locationIndexValue, List<Models.Face> faces)
{
string? check;
int? normalizedPixelPercentage;
Models.Face face = faces[locationIndexValue];
if (face.Location?.NormalizedPixelPercentage is null)
{
check = null;
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}");
}
return (check, normalizedPixelPercentage);
}
private static (string? check, int? normalizedPixelPercentage) GetReversedDeterministicHashCodeAfterParse(Dictionary<int, List<Models.Face>> keyValuePairs, string file, int idValue, int locationIndexValue)
{
string? check;
int? normalizedPixelPercentage;
List<Models.Face> faces = keyValuePairs[idValue];
if (faces.Count > locationIndexValue)
(check, normalizedPixelPercentage) = GetReversedDeterministicHashCodeFromFace(file, idValue, locationIndexValue, faces);
else
{
check = null;
normalizedPixelPercentage = null;
}
return (check, normalizedPixelPercentage);
}
private static (string? check, string id, int? normalizedPixelPercentage) GetReversedDeterministicHashCodeFromCollection(Dictionary<int, List<Models.Face>> keyValuePairs, string file, string fileName)
{
string id;
string? check;
int? normalizedPixelPercentage;
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, normalizedPixelPercentage) = GetReversedDeterministicHashCodeAfterParse(keyValuePairs, file, idValue, locationIndexValue);
else
{
check = null;
id = string.Empty;
normalizedPixelPercentage = null;
}
if (normalizedPixelPercentage is null)
id = string.Empty;
return new(check, id, normalizedPixelPercentage);
}
private static (string?, double?) GetReversedDeterministicHashCode(Dictionary<int, List<Models.Face>> keyValuePairs, string file, string fileName)
{
double? result;
string? check;
string id;
int? normalizedPixelPercentage;
if (keyValuePairs.Any())
(check, id, normalizedPixelPercentage) = GetReversedDeterministicHashCodeFromCollection(keyValuePairs, file, fileName);
else
{
check = null;
id = string.Empty;
normalizedPixelPercentage = null;
}
if (normalizedPixelPercentage is null || !double.TryParse(string.Concat(id, '.', normalizedPixelPercentage.Value), out double resultValue))
result = null;
else
result = resultValue;
return new(check, result);
}
internal static (string?, double?) GetReversedDeterministicHashCode(Dictionary<int, List<Models.Face>> keyValuePairs, string file)
{
double? result;
string? check;
string fileName = Path.GetFileName(file);
if (fileName.Contains('-'))
(check, result) = GetReversedDeterministicHashCode(keyValuePairs, file, fileName);
else
{
check = null;
result = null;
}
return new(check, result);
}
}

View File

@ -65,7 +65,6 @@ internal abstract class Person
Dictionary<DateTime, string[]> results = new();
string[] segments;
DateTime personKey;
const string KeyFormat = "yyyy-MM-dd_HH";
DateTime incrementDate = new(1500, 1, 1);
string[] lines = File.ReadAllLines(knownPeopleFile);
_ = incrementDate.AddDays(lines.Length);
@ -77,8 +76,8 @@ internal abstract class Person
segments = line.Replace(" //", "\t//").Split('\t');
if (segments.Length < 1)
continue;
SetSegments(ref segments, KeyFormat, ref incrementDate);
personKey = DateTime.ParseExact(segments[0], KeyFormat, cultureInfo);
SetSegments(ref segments, Stateless.IPerson.KeyFormat, ref incrementDate);
personKey = DateTime.ParseExact(segments[0], Stateless.IPerson.KeyFormat, cultureInfo);
if (results.ContainsKey(personKey))
continue;
results.Add(personKey, segments);
@ -88,7 +87,7 @@ internal abstract class Person
for (int i = 1; i < (1000 - countBefore); i++)
{
personKey = minimumDateTime.AddDays(i * -1);
results.Add(personKey, new string[] { personKey.ToString(KeyFormat) });
results.Add(personKey, new string[] { personKey.ToString(Stateless.IPerson.KeyFormat) });
}
return results.OrderBy(l => l.Key).ToDictionary(l => l.Key, l => l.Value);
}