Move const usage out of Shared

This commit is contained in:
2022-09-14 22:32:37 -07:00
parent ad28ab2d38
commit 409c020426
28 changed files with 190 additions and 160 deletions

View File

@ -1,5 +1,6 @@
{
"cSpell.words": [
"Permyriad",
"Phares"
]
}

View File

@ -39,11 +39,11 @@ public class Face : Properties.IFace
_RelativePath = relativePath;
}
public Face(int facesCount, Face face) :
public Face(int locationDigits, int locationFactor, int facesCount, Face face) :
this(face.DateTime, null, face.FaceEncoding, face.FaceParts, face.Location, face.LocationIndex, null, face.OutputResolution, face.RelativePath)
{
if (face.Location?.Confidence is not null && face.OutputResolution is not null)
_Location = new(face.Location.Confidence, face.OutputResolution.Height, face.Location, face.OutputResolution.Width, facesCount);
_Location = new(face.Location.Confidence, face.OutputResolution.Height, face.Location, locationDigits, locationFactor, face.OutputResolution.Width, facesCount);
}
public Face(Property property, int outputResolutionWidth, int outputResolutionHeight, int outputResolutionOrientation, string relativePath, int? i, Location? location) :

View File

@ -31,15 +31,15 @@ public class Location : Properties.ILocation, IEquatable<Location>
Stateless.Methods.Location.Check(bottom, left, normalizedPixelPercentage, right, top, zCount: 1);
}
public Location(double confidence, int height, Location location, int width, int zCount) :
this(location.Bottom, confidence, location.Left, Stateless.Methods.Location.GetNormalizedPixelPercentage(location.Bottom, height, location.Left, location.Right, location.Top, width, zCount), location.Right, location.Top) =>
public Location(double confidence, int height, Location location, int locationDigits, int locationFactor, int width, int zCount) :
this(location.Bottom, confidence, location.Left, Stateless.Methods.Location.GetNormalizedPixelPercentage(location.Bottom, height, location.Left, locationDigits, locationFactor, location.Right, location.Top, width, zCount), location.Right, location.Top) =>
Stateless.Methods.Location.Check(_Bottom, _Left, _NormalizedPixelPercentage, _Right, _Top, zCount);
public Location(int bottom, double confidence, int height, int left, int right, int top, int width, int zCount) :
this(bottom, confidence, left, Stateless.Methods.Location.GetNormalizedPixelPercentage(bottom, height, left, right, top, width, zCount), right, top) =>
public Location(int bottom, double confidence, int height, int left, int locationDigits, int locationFactor, int right, int top, int width, int zCount) :
this(bottom, confidence, left, Stateless.Methods.Location.GetNormalizedPixelPercentage(bottom, height, left, locationDigits, locationFactor, right, top, width, zCount), right, top) =>
Stateless.Methods.Location.Check(_Bottom, height, _Left, _NormalizedPixelPercentage, _Right, _Top, width, zCount);
public Location(double confidence, int factor, int height, Location location, int width, int zCount)
public Location(double confidence, int factor, int height, Location location, int locationDigits, int locationFactor, int width, int zCount)
{
int x = (location.Right - location.Left) / factor;
int y = (location.Bottom - location.Top) / factor;
@ -47,7 +47,7 @@ public class Location : Properties.ILocation, IEquatable<Location>
int left = Math.Max(location.Left - x, 0);
int right = Math.Min(location.Right + x, width);
int top = Math.Max(location.Top - y, 0);
int normalizedPixelPercentage = Stateless.Methods.Location.GetNormalizedPixelPercentage(location.Bottom, height, location.Left, location.Right, location.Top, width, zCount);
int normalizedPixelPercentage = Stateless.Methods.Location.GetNormalizedPixelPercentage(location.Bottom, height, location.Left, locationDigits, locationFactor, location.Right, location.Top, width, zCount);
Stateless.Methods.Location.Check(bottom, left, _NormalizedPixelPercentage, right, top, zCount);
_Confidence = confidence;
_Bottom = bottom;

View File

@ -10,5 +10,5 @@ public interface IFaceDistance
public double? Length { init; get; }
public DateTime? MinimumDateTime { init; get; }
public int? NormalizedPixelPercentage { init; get; }
}

View File

@ -2,11 +2,13 @@
public interface IFaceDistance
{
// 637972153144596958
// const int MaximumPer = 999;
const int HiddenImageFactor = 2;
const int Permyriad = 10000;
const double Tolerance = 0.2d;
const double MinimumConfidence = 0.95d;
const double Tolerance = 0.21d;
// (637987888254767613) Tolerance = 0.31d; MinimumConfidence = 0.80d; => 1003 in 20 minutes with 9 failures
// (637987913910140924) Tolerance = 0.21d; MinimumConfidence = 0.95d;
}

View File

@ -3,7 +3,6 @@
public interface ILocation
{
const double MinimumConfidence = 0.8d;
const int Digits = 6;
const int Factor = 1000000;

View File

@ -4,7 +4,7 @@ public interface ISorting
{
const int FacesToSkipAfterSortBeforeLoad = 0;
const int FacesToTakeAfterSortBeforeLoad = 21000;
const int FacesToTakeAfterSortBeforeLoad = 123000;
const int MaximumPerFaceShouldBeHigh = 1000;
const int DaysDeltaTolerance = 700;
const int MaximumPerKey = 27;

View File

@ -3,24 +3,24 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
public interface ILocation
{ // ...
Models.Location? TestStatic_GetLocation(Models.Location? location, int height, int width, int zCount) =>
GetLocation(location, height, width, zCount);
static Models.Location? GetLocation(Models.Location? location, int height, int width, int zCount) =>
location is null ? null : new(location.Confidence, height, location, width, zCount);
Models.Location? TestStatic_GetLocation(Models.Location? location, int locationDigits, int locationFactor, int height, int width, int zCount) =>
GetLocation(location, locationDigits, locationFactor, height, width, zCount);
static Models.Location? GetLocation(Models.Location? location, int locationDigits, int locationFactor, int height, int width, int zCount) =>
location is null ? null : new(location.Confidence, height, location, locationDigits, locationFactor, width, zCount);
Models.Location? TestStatic_GetLocation(int factor, Models.Location? location, int height, int width, int zCount) =>
GetLocation(location, height, width, zCount);
static Models.Location? GetLocation(int factor, Models.Location? location, int height, int width, int zCount) =>
location is null ? null : new(location.Confidence, factor, height, location, width, zCount);
Models.Location? TestStatic_GetLocation(int factor, Models.Location? location, int locationDigits, int locationFactor, int height, int width, int zCount) =>
GetLocation(location, locationDigits, locationFactor, height, width, zCount);
static Models.Location? GetLocation(int factor, Models.Location? location, int locationDigits, int locationFactor, int height, int width, int zCount) =>
location is null ? null : new(location.Confidence, factor, height, location, locationDigits, locationFactor, width, zCount);
int?[] TestStatic_GetInts(List<Models.Location> locations) =>
GetInts(locations);
static int?[] GetInts(List<Models.Location> locations) =>
(from l in locations where l.NormalizedPixelPercentage is not null select l.NormalizedPixelPercentage).ToArray();
int TestStatic_GetNormalizedPixelPercentage(int bottom, int height, int left, int right, int top, int width, int zCount) =>
GetNormalizedPixelPercentage(bottom, height, left, right, top, width, zCount);
static int GetNormalizedPixelPercentage(int bottom, int height, int left, int right, int top, int width, int zCount) =>
Location.GetNormalizedPixelPercentage(bottom, height, left, right, top, width, zCount);
int TestStatic_GetNormalizedPixelPercentage(int bottom, int height, int left, int locationDigits, int locationFactor, int right, int top, int width, int zCount) =>
GetNormalizedPixelPercentage(bottom, height, left, locationDigits, locationFactor, right, top, width, zCount);
static int GetNormalizedPixelPercentage(int bottom, int height, int left, int locationDigits, int locationFactor, int right, int top, int width, int zCount) =>
Location.GetNormalizedPixelPercentage(bottom, height, left, locationDigits, locationFactor, right, top, width, zCount);
}

View File

@ -6,12 +6,12 @@ public interface IMapping
static string GetDeterministicHashCodeKeyDisplay(int id, int normalizedPixelPercentage)
=> $"{id}.{normalizedPixelPercentage}";
static double GetDeterministicHashCodeKeyValue(int id, int normalizedPixelPercentage)
=> Math.Round(double.Parse($"{id}.{normalizedPixelPercentage}"), Stateless.ILocation.Digits);
static double GetDeterministicHashCodeKeyValue(int locationDigits, int id, int normalizedPixelPercentage)
=> Math.Round(double.Parse($"{id}.{normalizedPixelPercentage}"), locationDigits);
(int?, int?) TestStatic_GetReversedDeterministicHashCodeKey(bool keyValuePairsAny, Dictionary<int, List<Models.Face>> keyValuePairs, string file) =>
GetReversedDeterministicHashCodeKey(keyValuePairsAny, keyValuePairs, file);
static (int?, int?) GetReversedDeterministicHashCodeKey(bool keyValuePairsAny, Dictionary<int, List<Models.Face>> keyValuePairs, string file) =>
Mapping.GetReversedDeterministicHashCodeKey(keyValuePairsAny, keyValuePairs, file);
(int?, int?) TestStatic_GetReversedDeterministicHashCodeKey(int locationDigits, bool keyValuePairsAny, Dictionary<int, List<Models.Face>> keyValuePairs, string file) =>
GetReversedDeterministicHashCodeKey(locationDigits, keyValuePairsAny, keyValuePairs, file);
static (int?, int?) GetReversedDeterministicHashCodeKey(int locationDigits, bool keyValuePairsAny, Dictionary<int, List<Models.Face>> keyValuePairs, string file) =>
Mapping.GetReversedDeterministicHashCodeKey(locationDigits, keyValuePairsAny, keyValuePairs, file);
}

View File

@ -5,19 +5,29 @@ public interface IPerson
// ...
Dictionary<DateTime, string[]> TestStatic_Split(string knownPeopleFile);
static Dictionary<DateTime, string[]> Split(string knownPeopleFile) => Person.Split(knownPeopleFile);
Dictionary<DateTime, string[]> TestStatic_Split(int personBirthdayFirstYear, string personKeyFormat, string knownPeopleFile) =>
Split(personBirthdayFirstYear, personKeyFormat, knownPeopleFile);
static Dictionary<DateTime, string[]> Split(int personBirthdayFirstYear, string personKeyFormat, string knownPeopleFile) =>
Person.Split(personBirthdayFirstYear, personKeyFormat, knownPeopleFile);
Models.Person[] TestStatic_GetPeople(Properties.IStorage storage);
static Models.Person[] GetPeople(Properties.IStorage storage) => Person.GetPeople(storage);
Models.Person[] TestStatic_GetPeople(Properties.IStorage storage, int personBirthdayFirstYear, string personBirthdayFormat, string personKeyFormat) =>
GetPeople(storage, personBirthdayFirstYear, personBirthdayFormat, personKeyFormat);
static Models.Person[] GetPeople(Properties.IStorage storage, int personBirthdayFirstYear, string personBirthdayFormat, string personKeyFormat) =>
Person.GetPeople(storage, personBirthdayFirstYear, personBirthdayFormat, personKeyFormat);
void TestStatic_SavePerson(Properties.IStorage storage, Models.Person person);
static void SavePerson(Properties.IStorage storage, Models.Person person) => Person.SavePerson(storage, person);
void TestStatic_SavePerson(Properties.IStorage storage, string personBirthdayFormat, Models.Person person) =>
SavePerson(storage, personBirthdayFormat, person);
static void SavePerson(Properties.IStorage storage, string personBirthdayFormat, Models.Person person) =>
Person.SavePerson(storage, personBirthdayFormat, person);
string TestStatic_GetFileFullName(Properties.IStorage storage, Models.Person person);
static string GetFileFullName(Properties.IStorage storage, Models.Person person) => PersonBirthday.GetFileFullName(storage, person.Birthday);
string TestStatic_GetFileFullName(Properties.IStorage storage, string personBirthdayFormat, Models.Person person) =>
GetFileFullName(storage, personBirthdayFormat, person);
static string GetFileFullName(Properties.IStorage storage, string personBirthdayFormat, Models.Person person) =>
PersonBirthday.GetFileFullName(storage, personBirthdayFormat, person.Birthday);
Models.Person TestStatic_CreatePerson(Properties.IStorage storage, Models.PersonBirthday birthday, Models.PersonName name, List<Models.PersonComment> comments, List<Models.PersonURL> urls, List<Models.PersonNumber> numbers, List<Models.PersonEmail> emails, List<Models.PersonAddress> addresses);
static Models.Person CreatePerson(Properties.IStorage storage, Models.PersonBirthday birthday, Models.PersonName name, List<Models.PersonComment> comments, List<Models.PersonURL> urls, List<Models.PersonNumber> numbers, List<Models.PersonEmail> emails, List<Models.PersonAddress> addresses) => Person.CreatePerson(storage, birthday, name, comments, urls, numbers, emails, addresses);
Models.Person TestStatic_CreatePerson(Properties.IStorage storage, string personBirthdayFormat, Models.PersonBirthday birthday, Models.PersonName name, List<Models.PersonComment> comments, List<Models.PersonURL> urls, List<Models.PersonNumber> numbers, List<Models.PersonEmail> emails, List<Models.PersonAddress> addresses) =>
CreatePerson(storage, personBirthdayFormat, birthday, name, comments, urls, numbers, emails, addresses);
static Models.Person CreatePerson(Properties.IStorage storage, string personBirthdayFormat, Models.PersonBirthday birthday, Models.PersonName name, List<Models.PersonComment> comments, List<Models.PersonURL> urls, List<Models.PersonNumber> numbers, List<Models.PersonEmail> emails, List<Models.PersonAddress> addresses) =>
Person.CreatePerson(storage, personBirthdayFormat, birthday, name, comments, urls, numbers, emails, addresses);
}

View File

@ -16,20 +16,20 @@ public interface IPersonBirthday
static double? GetAge(Models.PersonBirthday birthday) =>
PersonBirthday.GetAge(birthday);
DateTime? TestStatic_GetDateTime(string personKey) =>
PersonBirthday.GetDateTime(personKey);
static DateTime? GetDateTime(string personKey) =>
PersonBirthday.GetDateTime(personKey);
DateTime? TestStatic_GetDateTime(string personBirthdayFormat, string personKey) =>
PersonBirthday.GetDateTime(personBirthdayFormat, personKey);
static DateTime? GetDateTime(string personBirthdayFormat, string personKey) =>
PersonBirthday.GetDateTime(personBirthdayFormat, personKey);
Models.PersonBirthday TestStatic_GetPersonBirthday(long ticks) =>
new(new(ticks));
static Models.PersonBirthday GetPersonBirthday(long ticks) =>
new(new(ticks));
string TestStatic_GetFileName(Models.PersonBirthday personBirthday) =>
PersonBirthday.GetFileName(personBirthday);
static string GetFileName(Models.PersonBirthday personBirthday) =>
PersonBirthday.GetFileName(personBirthday);
string TestStatic_GetFileName(string personBirthdayFormat, Models.PersonBirthday personBirthday) =>
PersonBirthday.GetFileName(personBirthdayFormat, personBirthday);
static string GetFileName(string personBirthdayFormat, Models.PersonBirthday personBirthday) =>
PersonBirthday.GetFileName(personBirthdayFormat, personBirthday);
(int, TimeSpan) TestStatic_GetAge(DateTime dateTime, Models.PersonBirthday birthday) =>
GetAge(dateTime, birthday);
@ -41,15 +41,15 @@ public interface IPersonBirthday
static (int, TimeSpan) GetAge(long dateTimeTicks, Models.PersonBirthday birthday) =>
PersonBirthday.GetAge(dateTimeTicks, birthday);
string TestStatic_GetFormatted(Models.PersonBirthday personBirthday) =>
PersonBirthday.GetFormatted(personBirthday);
static string GetFormatted(Models.PersonBirthday personBirthday) =>
PersonBirthday.GetFormatted(personBirthday);
string TestStatic_GetFormatted(string personBirthdayFormat, Models.PersonBirthday personBirthday) =>
PersonBirthday.GetFormatted(personBirthdayFormat, personBirthday);
static string GetFormatted(string personBirthdayFormat, Models.PersonBirthday personBirthday) =>
PersonBirthday.GetFormatted(personBirthdayFormat, personBirthday);
Models.PersonBirthday? TestStatic_GetPersonBirthday(string personKey) =>
PersonBirthday.GetPersonBirthday(personKey);
static Models.PersonBirthday? GetPersonBirthday(string personKey) =>
PersonBirthday.GetPersonBirthday(personKey);
Models.PersonBirthday? TestStatic_GetPersonBirthday(string personBirthdayFormat, string personKey) =>
PersonBirthday.GetPersonBirthday(personBirthdayFormat, personKey);
static Models.PersonBirthday? GetPersonBirthday(string personBirthdayFormat, string personKey) =>
PersonBirthday.GetPersonBirthday(personBirthdayFormat, personKey);
bool TestStatic_IsCounterPersonBirthday(Models.PersonBirthday personBirthday);
static bool IsCounterPersonBirthday(Models.PersonBirthday personBirthday) =>
@ -70,10 +70,10 @@ public interface IPersonBirthday
static TimeSpan? GetTimeSpan(long minimumDateTimeTicks, bool? isWrongYear, Models.PersonBirthday personBirthday) =>
PersonBirthday.GetTimeSpan(minimumDateTimeTicks, isWrongYear, personBirthday);
string TestStatic_GetFileFullName(Properties.IStorage storage, Models.PersonBirthday personBirthday) =>
PersonBirthday.GetFileFullName(storage, personBirthday);
static string GetFileFullName(Properties.IStorage storage, Models.PersonBirthday personBirthday) =>
PersonBirthday.GetFileFullName(storage, personBirthday);
string TestStatic_GetFileFullName(Properties.IStorage storage, string personBirthdayFormat, Models.PersonBirthday personBirthday) =>
PersonBirthday.GetFileFullName(storage, personBirthdayFormat, personBirthday);
static string GetFileFullName(Properties.IStorage storage, string personBirthdayFormat, Models.PersonBirthday personBirthday) =>
PersonBirthday.GetFileFullName(storage, personBirthdayFormat, personBirthday);
bool TestStatic_DoesBirthDateExits(Properties.IStorage storage, Models.PersonBirthday personBirthday) =>
DoesBirthDateExits(storage, personBirthday);

View File

@ -8,9 +8,9 @@ public interface ISorting
static Models.Sorting[] Sort(List<Models.Sorting> collection) =>
(from l in collection orderby l.WithinRange, l.DistancePermyriad, l.DaysDelta select l).ToArray();
Models.Sorting TestStatic_Get(Models.FaceDistance faceDistanceEncoding, Models.FaceDistance faceDistanceLength, bool anyLowerThanTolerance, List<(long lcl, long minimum, long maximum, long ucl)> personKeysRangesCollection) =>
Get(faceDistanceEncoding, faceDistanceLength, anyLowerThanTolerance, personKeysRangesCollection);
static Models.Sorting Get(Models.FaceDistance faceDistanceEncoding, Models.FaceDistance faceDistanceLength, bool anyLowerThanTolerance, List<(long lcl, long minimum, long maximum, long ucl)> personKeysRangesCollection) =>
Sorting.Get(faceDistanceEncoding, faceDistanceLength, anyLowerThanTolerance, personKeysRangesCollection);
Models.Sorting TestStatic_Get(int faceDistancePermyriad, double faceDistanceTolerance, Models.FaceDistance faceDistanceEncoding, Models.FaceDistance faceDistanceLength, bool anyLowerThanTolerance, List<(long lcl, long minimum, long maximum, long ucl)> personKeysRangesCollection) =>
Get(faceDistancePermyriad, faceDistanceTolerance, faceDistanceEncoding, faceDistanceLength, anyLowerThanTolerance, personKeysRangesCollection);
static Models.Sorting Get(int faceDistancePermyriad, double faceDistanceTolerance, Models.FaceDistance faceDistanceEncoding, Models.FaceDistance faceDistanceLength, bool anyLowerThanTolerance, List<(long lcl, long minimum, long maximum, long ucl)> personKeysRangesCollection) =>
Sorting.Get(faceDistancePermyriad, faceDistanceTolerance, faceDistanceEncoding, faceDistanceLength, anyLowerThanTolerance, personKeysRangesCollection);
}

View File

@ -3,7 +3,7 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
internal abstract class Location
{
internal static int GetNormalizedPixelPercentage(int bottom, int height, int left, int right, int top, int width, int zCount)
internal static int GetNormalizedPixelPercentage(int bottom, int height, int left, int locationDigits, int locationFactor, int right, int top, int width, int zCount)
{
int result;
double value;
@ -15,7 +15,7 @@ internal abstract class Location
value = at / total;
if (value < 0)
value = 3;
result = (int)(Math.Round(value, Stateless.ILocation.Digits) * Stateless.ILocation.Factor);
result = (int)(Math.Round(value, locationDigits) * locationFactor);
return result;
}

View File

@ -5,15 +5,15 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
internal abstract class Mapping
{
internal static double GetDeterministicHashCodeKey(Models.Item item, Models.Face face)
internal static double GetDeterministicHashCodeKey(int locationDigits, Models.Item item, Models.Face face)
{
if (item.Property?.Id is null || item.ImageFileHolder is null || face.Location?.NormalizedPixelPercentage is null)
throw new NullReferenceException();
double result = IMapping.GetDeterministicHashCodeKeyValue(item.Property.Id.Value, face.Location.NormalizedPixelPercentage.Value);
double result = IMapping.GetDeterministicHashCodeKeyValue(locationDigits, item.Property.Id.Value, face.Location.NormalizedPixelPercentage.Value);
return result;
}
private static void UseKeyValuePairsSaveFaceEncoding(Dictionary<int, List<Models.Face>> keyValuePairs, string file, int id, int normalizedPixelPercentageValue, double deterministicHashCodeKey, string extensionLowered)
private static void UseKeyValuePairsSaveFaceEncoding(int locationDigits, Dictionary<int, List<Models.Face>> keyValuePairs, string file, int id, int normalizedPixelPercentageValue, double deterministicHashCodeKey, string extensionLowered)
{
string json;
string checkFile;
@ -24,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 != IMapping.GetDeterministicHashCodeKeyValue(id, face.Location.NormalizedPixelPercentage.Value))
if (normalizedPixelPercentageValue != face.Location.NormalizedPixelPercentage.Value && deterministicHashCodeKey != IMapping.GetDeterministicHashCodeKeyValue(locationDigits, id, face.Location.NormalizedPixelPercentage.Value))
continue;
collection.Add(face);
}
@ -43,7 +43,7 @@ internal abstract class Mapping
}
}
private static (int?, int?, double?) GetReversedDeterministicHashCodeKeysFromSegments(bool keyValuePairsAny, Dictionary<int, List<Models.Face>> keyValuePairs, string file, string[] segments)
private static (int?, int?, double?) GetReversedDeterministicHashCodeKeysFromSegments(int locationDigits, bool keyValuePairsAny, Dictionary<int, List<Models.Face>> keyValuePairs, string file, string[] segments)
{
double? result;
if (segments.Length != 3)
@ -55,14 +55,14 @@ internal abstract class Mapping
result = null;
else
{
result = IMapping.GetDeterministicHashCodeKeyValue(idValue, normalizedPixelPercentageValue);
result = IMapping.GetDeterministicHashCodeKeyValue(locationDigits, idValue, normalizedPixelPercentageValue);
if (keyValuePairsAny && keyValuePairs.ContainsKey(idValue))
UseKeyValuePairsSaveFaceEncoding(keyValuePairs, file, idValue, normalizedPixelPercentageValue, result.Value, $".{segments[2]}");
UseKeyValuePairsSaveFaceEncoding(locationDigits, keyValuePairs, file, idValue, normalizedPixelPercentageValue, result.Value, $".{segments[2]}");
}
return new(idValue, normalizedPixelPercentageValue, result);
}
internal static (int?, int?) GetReversedDeterministicHashCodeKey(bool keyValuePairsAny, Dictionary<int, List<Models.Face>> keyValuePairs, string file)
internal static (int?, int?) GetReversedDeterministicHashCodeKey(int locationDigits, bool keyValuePairsAny, Dictionary<int, List<Models.Face>> keyValuePairs, string file)
{
int? id;
int? normalizedPixelPercentage;
@ -75,7 +75,7 @@ internal abstract class Mapping
else
{
string[] segments = fileName.Split('.');
(id, normalizedPixelPercentage, double? result) = GetReversedDeterministicHashCodeKeysFromSegments(keyValuePairsAny, keyValuePairs, file, segments);
(id, normalizedPixelPercentage, double? result) = GetReversedDeterministicHashCodeKeysFromSegments(locationDigits, keyValuePairsAny, keyValuePairs, file, segments);
if (result is null)
{
id = null;

View File

@ -8,7 +8,7 @@ internal abstract class Person
// ...
private static List<string> ValidatePerson(Properties.IStorage storage, Models.PersonId id, Models.PersonBirthday birthday, Models.PersonName name)
private static List<string> ValidatePerson(Properties.IStorage storage, string personBirthdayFormat, Models.PersonId id, Models.PersonBirthday birthday, Models.PersonName name)
{
List<string> results = new();
if (birthday is null)
@ -21,18 +21,18 @@ internal abstract class Person
results.Add("Id must be Birthday ticks!");
if (name.First is null || string.IsNullOrEmpty(name.First.Value))
results.Add("Fist Name must be supplied!");
if (PersonBirthday.DoesBirthDateExits(storage, birthday))
if (PersonBirthday.DoesBirthDateExits(storage, personBirthdayFormat, birthday))
results.Add("BirthDate already exits!");
return results;
}
internal static Models.Person CreatePerson(Properties.IStorage storage, Models.PersonBirthday birthday, Models.PersonName name, List<Models.PersonComment> comments, List<Models.PersonURL> urls, List<Models.PersonNumber> numbers, List<Models.PersonEmail> emails, List<Models.PersonAddress> addresses)
internal static Models.Person CreatePerson(Properties.IStorage storage, string personBirthdayFormat, Models.PersonBirthday birthday, Models.PersonName name, List<Models.PersonComment> comments, List<Models.PersonURL> urls, List<Models.PersonNumber> numbers, List<Models.PersonEmail> emails, List<Models.PersonAddress> addresses)
{
Models.Person result;
Models.PersonId id = new(birthday.Value.Ticks);
if (birthday.Value == DateTime.MinValue)
birthday = PersonBirthday.GetNextBirthDate(storage);
List<string> results = ValidatePerson(storage, id, birthday, name);
List<string> results = ValidatePerson(storage, personBirthdayFormat, id, birthday, name);
if (results.Any())
throw new Exception(string.Join(Environment.NewLine, results));
if (comments is null)
@ -61,12 +61,12 @@ internal abstract class Person
}
}
internal static Dictionary<DateTime, string[]> Split(string knownPeopleFile)
internal static Dictionary<DateTime, string[]> Split(int personBirthdayFirstYear, string personKeyFormat, string knownPeopleFile)
{
Dictionary<DateTime, string[]> results = new();
string[] segments;
DateTime personKey;
DateTime incrementDate = new(Stateless.IPersonBirthday.FirstYear, 1, 1);
DateTime incrementDate = new(personBirthdayFirstYear, 1, 1);
string[] lines = File.ReadAllLines(knownPeopleFile);
_ = incrementDate.AddDays(lines.Length);
System.Globalization.CultureInfo cultureInfo = System.Globalization.CultureInfo.InvariantCulture;
@ -77,8 +77,8 @@ internal abstract class Person
segments = line.Replace(" //", "\t//").Split('\t');
if (segments.Length < 1)
continue;
SetSegments(ref segments, Stateless.IPerson.KeyFormat, ref incrementDate);
personKey = DateTime.ParseExact(segments[0], Stateless.IPerson.KeyFormat, cultureInfo);
SetSegments(ref segments, personKeyFormat, ref incrementDate);
personKey = DateTime.ParseExact(segments[0], personKeyFormat, cultureInfo);
if (results.ContainsKey(personKey))
continue;
results.Add(personKey, segments);
@ -90,7 +90,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(Stateless.IPerson.KeyFormat) });
results.Add(personKey, new string[] { personKey.ToString(personKeyFormat) });
}
}
return results.OrderBy(l => l.Key).ToDictionary(l => l.Key, l => l.Value);
@ -118,7 +118,7 @@ internal abstract class Person
SetValues(ref name, ref comment, ref mergeName, splitLine);
}
private static Dictionary<DateTime, PersonImport> GetPersonCollection(string knownPeopleFile)
private static Dictionary<DateTime, PersonImport> GetPersonCollection(int personBirthdayFirstYear, string personKeyFormat, string knownPeopleFile)
{
Dictionary<DateTime, PersonImport> results = new();
string name;
@ -127,7 +127,7 @@ internal abstract class Person
string oldName;
string mergeName;
PersonImport person;
Dictionary<DateTime, string[]> splitLines = Split(knownPeopleFile);
Dictionary<DateTime, string[]> splitLines = Split(personBirthdayFirstYear, personKeyFormat, knownPeopleFile);
foreach (KeyValuePair<DateTime, string[]> splitLine in splitLines)
{
name = string.Empty;
@ -142,9 +142,9 @@ internal abstract class Person
return results;
}
internal static void SavePerson(Properties.IStorage storage, Models.Person person)
internal static void SavePerson(Properties.IStorage storage, string personBirthdayFormat, Models.Person person)
{
string fileName = IPerson.GetFileFullName(storage, person);
string fileName = IPerson.GetFileFullName(storage, personBirthdayFormat, person);
string json = JsonSerializer.Serialize(person, new JsonSerializerOptions { WriteIndented = true });
_ = IStorage.WriteAllText(fileName, json, updateDateWhenMatches: true, compareBeforeWrite: true);
}
@ -162,7 +162,7 @@ internal abstract class Person
return result;
}
private static List<Models.Person> GetPeopleFromText(Properties.IStorage storage, string localKnownPeopleFile)
private static List<Models.Person> GetPeopleFromText(Properties.IStorage storage, int personBirthdayFirstYear, string personBirthdayFormat, string personKeyFormat, string localKnownPeopleFile)
{
List<Models.Person> results = new();
string comment;
@ -174,7 +174,7 @@ internal abstract class Person
List<Models.PersonEmail> emails = new();
List<Models.PersonNumber> numbers = new();
List<Models.PersonAddress> addresses = new();
Dictionary<DateTime, PersonImport> keyValuePairs = GetPersonCollection(localKnownPeopleFile);
Dictionary<DateTime, PersonImport> keyValuePairs = GetPersonCollection(personBirthdayFirstYear, personKeyFormat, localKnownPeopleFile);
foreach (KeyValuePair<DateTime, PersonImport> keyValuePair in keyValuePairs)
{
if (string.IsNullOrEmpty(keyValuePair.Value.Name))
@ -189,14 +189,14 @@ internal abstract class Person
comment = GetComment(urls, comments, keyValuePair);
if (!string.IsNullOrEmpty(keyValuePair.Value.OldName))
comments.Add(new(new(keyValuePair.Value.OldName)));
person = IPerson.CreatePerson(storage, birthday, name, comments, urls, numbers, emails, addresses);
SavePerson(storage, person);
person = IPerson.CreatePerson(storage, personBirthdayFormat, birthday, name, comments, urls, numbers, emails, addresses);
SavePerson(storage, personBirthdayFormat, person);
results.Add(person);
}
return results;
}
internal static Models.Person[] GetPeople(Properties.IStorage storage)
internal static Models.Person[] GetPeople(Properties.IStorage storage, int personBirthdayFirstYear, string personBirthdayFormat, string personKeyFormat)
{
List<Models.Person> results = new();
string json;
@ -234,7 +234,7 @@ internal abstract class Person
results.Add(person);
}
if (!results.Any())
results = GetPeopleFromText(storage, localKnownPeopleFile);
results = GetPeopleFromText(storage, personBirthdayFirstYear, personBirthdayFormat, personKeyFormat, localKnownPeopleFile);
else if (!string.IsNullOrEmpty(localKnownPeopleFile))
{
fileInfo = new FileInfo(localKnownPeopleFile);
@ -242,14 +242,14 @@ internal abstract class Person
{
foreach (string file in files)
File.Delete(file);
results = GetPeopleFromText(storage, localKnownPeopleFile);
results = GetPeopleFromText(storage, personBirthdayFirstYear, personBirthdayFormat, personKeyFormat, localKnownPeopleFile);
}
}
SaveToDirectory(storage, results);
SaveToDirectory(storage, personBirthdayFormat, results);
return results.ToArray();
}
private static void SaveToDirectory(Properties.IStorage storage, List<Models.Person> people)
private static void SaveToDirectory(Properties.IStorage storage, string personBirthdayFormat, List<Models.Person> people)
{
int years;
TimeSpan? timeSpan;
@ -265,7 +265,7 @@ internal abstract class Person
const string pattern = @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]";
foreach (Models.Person person in people)
{
personJsonFileName = IPerson.GetFileFullName(storage, person);
personJsonFileName = IPerson.GetFileFullName(storage, personBirthdayFormat, person);
if (string.IsNullOrEmpty(peopleDirectory))
peopleDirectory = Path.GetDirectoryName(personJsonFileName);
if (string.IsNullOrEmpty(peopleDirectory))

View File

@ -8,17 +8,17 @@ internal abstract class PersonBirthday
internal static DateTime GetDefaultValue() => DateTime.MinValue; // {{1}}SingletonValue
// ...
internal static string GetFormatted(Models.PersonBirthday personBirthday) => personBirthday.Value.ToString(Stateless.IPersonBirthday.Format);
internal static string GetFileName(Models.PersonBirthday personBirthday) => $"{personBirthday.Value.ToString(Stateless.IPersonBirthday.Format)}.json";
internal static bool DoesBirthDateExits(Properties.IStorage storage, Models.PersonBirthday personBirthday) => File.Exists(GetFileFullName(storage, personBirthday));
internal static string GetFormatted(string personBirthdayFormat, Models.PersonBirthday personBirthday) => personBirthday.Value.ToString(personBirthdayFormat);
internal static string GetFileName(string personBirthdayFormat, Models.PersonBirthday personBirthday) => $"{personBirthday.Value.ToString(personBirthdayFormat)}.json";
internal static bool DoesBirthDateExits(Properties.IStorage storage, string personBirthdayFormat, Models.PersonBirthday personBirthday) => File.Exists(GetFileFullName(storage, personBirthdayFormat, personBirthday));
internal static Models.PersonBirthday GetNextBirthDate(Properties.IStorage storage) => throw new Exception(storage.ToString()); // Person.GetNextBirthDate(storage);
internal static string GetFileFullName(Properties.IStorage storage, Models.PersonBirthday personBirthday) => Path.Combine(storage.PeopleRootDirectory, "{}", GetFileName(personBirthday));
internal static DateTime? GetDateTime(string personKey) => DateTime.TryParseExact(personKey, Stateless.IPersonBirthday.Format, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dateTime) ? dateTime : null;
internal static string GetFileFullName(Properties.IStorage storage, string personBirthdayFormat, Models.PersonBirthday personBirthday) => Path.Combine(storage.PeopleRootDirectory, "{}", GetFileName(personBirthdayFormat, personBirthday));
internal static DateTime? GetDateTime(string personBirthdayFormat, string personKey) => DateTime.TryParseExact(personKey, personBirthdayFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dateTime) ? dateTime : null;
internal static Models.PersonBirthday? GetPersonBirthday(string personKey)
internal static Models.PersonBirthday? GetPersonBirthday(string personBirthdayFormat, string personKey)
{
Models.PersonBirthday? result;
DateTime? dateTime = GetDateTime(personKey);
DateTime? dateTime = GetDateTime(personBirthdayFormat, personKey);
if (dateTime is null)
result = null;
else

View File

@ -3,7 +3,7 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
internal abstract class Sorting
{
internal static Models.Sorting Get(Models.FaceDistance faceDistanceEncoding, Models.FaceDistance faceDistanceLength, bool anyLowerThanTolerance, List<(long lcl, long minimum, long maximum, long ucl)> personKeysRangesCollection)
internal static Models.Sorting Get(int faceDistancePermyriad, double faceDistanceTolerance, Models.FaceDistance faceDistanceEncoding, Models.FaceDistance faceDistanceLength, bool anyLowerThanTolerance, List<(long lcl, long minimum, long maximum, long ucl)> personKeysRangesCollection)
{
Models.Sorting result;
if (faceDistanceLength.Length is null)
@ -14,7 +14,7 @@ internal abstract class Sorting
int daysDelta;
int withinRange;
int distancePermyriad;
if (faceDistanceLength.Length.Value == 0 || (anyLowerThanTolerance && faceDistanceLength.Length.Value >= Stateless.IFaceDistance.Tolerance))
if (faceDistanceLength.Length.Value == 0 || (anyLowerThanTolerance && faceDistanceLength.Length.Value >= faceDistanceTolerance))
{
older = false;
daysDelta = 0;
@ -30,7 +30,7 @@ internal abstract class Sorting
TimeSpan timeSpan = new(faceDistanceLength.MinimumDateTime.Value.Ticks - ticks);
older = timeSpan.TotalMilliseconds < 0;
daysDelta = (int)Math.Round(Math.Abs(timeSpan.TotalDays), 0);
distancePermyriad = (int)(faceDistanceLength.Length.Value / Stateless.IFaceDistance.Tolerance * Stateless.IFaceDistance.Permyriad);
distancePermyriad = (int)(faceDistanceLength.Length.Value / faceDistanceTolerance * faceDistancePermyriad);
foreach ((long lcl, long minimum, long maximum, long ucl) in personKeysRangesCollection)
{
if (ticks > minimum && ticks < maximum)