Move const usage out of Shared

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

30
.vscode/launch.json vendored
View File

@ -26,6 +26,34 @@
"console": "externalTerminal",
"stopAtEntry": false,
"requireExactSource": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
}
// "AmazonUsername": "phares36@gmail.com",
// "AmazonPassword": "JlPhgtv@63",
// Keep creating the .json file the same way
// However load all .json files at the beginning
// When looping through all files and file not in collection path&name or date is different from collection value
// Get id in normal fashion
// If id is in collection update collection to new path/name
// If not save and add to collection
// Nicéphore Niépce in 1826 or 182
// Stateless.ILocation.Digits
// locationDigits
// Stateless.ILocation.Factor
// locationFactor
// Stateless.IFaceDistance.Tolerance
// faceDistanceTolerance
// Stateless.IFaceDistance.Permyriad
// faceDistancePermyriad
// Stateless.IPersonBirthday.FirstYear
// personBirthdayFirstYear
// Stateless.IPersonBirthday.Format
// personBirthdayFormat
// Stateless.IPerson.KeyFormat
// personKeyFormat

View File

@ -82,6 +82,8 @@ public class FaceRecognition : DisposableObject
detectionConfidence,
height,
Math.Max(rectangle.Left, 0),
ILocation.Digits,
ILocation.Factor,
Math.Min(rectangle.Right, width),
Math.Max(rectangle.Top, 0),
width,

View File

@ -69,7 +69,7 @@ internal class A2_People
if (rootResultsDirectory is null)
throw new Exception();
Storage storage = new(rootDirectory, rootResultsDirectory, peopleRootDirectory);
results = Shared.Models.Stateless.Methods.IPerson.GetPeople(storage);
results = Shared.Models.Stateless.Methods.IPerson.GetPeople(storage, Shared.Models.Stateless.IPersonBirthday.FirstYear, Shared.Models.Stateless.IPersonBirthday.Format, Shared.Models.Stateless.IPerson.KeyFormat);
return results.ToArray();
}

View File

@ -159,7 +159,7 @@ public class D_Face
continue;
if (face.FaceEncoding is null || face?.Location is null)
continue;
location = Shared.Models.Stateless.Methods.ILocation.GetLocation(face.Location, source.Height, source.Width, collection.Count);
location = Shared.Models.Stateless.Methods.ILocation.GetLocation(face.Location, ILocation.Digits, ILocation.Factor, source.Height, source.Width, collection.Count);
if (location is null)
continue;
width = location.Right - location.Left;
@ -173,7 +173,7 @@ public class D_Face
}
if (File.Exists(fileName))
File.Delete(fileName);
location = Shared.Models.Stateless.Methods.ILocation.GetLocation(IFaceDistance.HiddenImageFactor, face.Location, source.Height, source.Width, collection.Count);
location = Shared.Models.Stateless.Methods.ILocation.GetLocation(IFaceDistance.HiddenImageFactor, face.Location, ILocation.Digits, ILocation.Factor, source.Height, source.Width, collection.Count);
if (location is null)
continue;
width = location.Right - location.Left;
@ -330,7 +330,7 @@ public class D_Face
}
if (_Configuration.ForceFaceLastWriteTimeToCreationTime)
{
results = (from l in results select new Face(results.Count, l)).ToList();
results = (from l in results select new Face(ILocation.Digits, ILocation.Factor, results.Count, l)).ToList();
normalizedPixelPercentageCollection = Shared.Models.Stateless.Methods.IFace.GetInts(results);
normalizedPixelPercentageDistinctCount = normalizedPixelPercentageCollection.Distinct().Count();
if (normalizedPixelPercentageDistinctCount != normalizedPixelPercentageCollection.Length)

View File

@ -35,9 +35,9 @@ internal class E_Distance
Sorting[] collection = Shared.Models.Stateless.Methods.ISorting.Sort(sortingCollection);
foreach (Sorting sorting in collection)
{
if (faceDistanceEncoding.NormalizedPixelPercentage is null)
if (face.Mapping is null || faceDistanceEncoding.NormalizedPixelPercentage is null)
throw new NotSupportedException();
if (sorting.DistancePermyriad > IFaceDistance.Permyriad || sorting.DaysDelta > ISorting.DaysDeltaTolerance)
if (face.Mapping.MappingFromLocation.Confidence < IFaceDistance.MinimumConfidence || sorting.DistancePermyriad > IFaceDistance.Permyriad || sorting.DaysDelta > ISorting.DaysDeltaTolerance)
continue;
sortingContainer = new(face, sorting);
results.Add(sortingContainer);
@ -135,8 +135,7 @@ internal class E_Distance
SetFaceDistances(maxDegreeOfParallelism, ticks, outputResolution, selectedFilteredFaces);
FaceDistanceContainer[] faceDistanceContainers = GetFaceDistanceContainers(selectedFilteredFaces);
results = GetSortingContainersThenSetFaceMappingSortingCollection(maxDegreeOfParallelism, ticks, mapLogic, outputResolution, faceDistanceContainers);
if (results.Length < IFaceDistance.Permyriad)
SaveFaceDistances(eDistanceContentFileName, results);
SaveFaceDistances(eDistanceContentFileName, results);
return results;
}

View File

@ -89,7 +89,7 @@ public class G2_Identify : Shared.Models.Properties.IIdentify, IIdentify
json = File.ReadAllText(named.FullName);
Person[] people = a2People.GetPeople(configuration);
Dictionary<string, string[]> resultKeyValuePairs = new();
string[] peopleBirthDates = (from l in people select Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(l.Birthday)).ToArray();
string[] peopleBirthDates = (from l in people select Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(Shared.Models.Stateless.IPersonBirthday.Format, l.Birthday)).ToArray();
Dictionary<string, string[]> sourceKeyValuePairs = JsonSerializer.Deserialize<Dictionary<string, string[]>>(json);
foreach (KeyValuePair<string, string[]> keyValuePair in sourceKeyValuePairs)
{

View File

@ -206,7 +206,7 @@ public class MapLogic
if (!keyValuePairs.ContainsKey(faceDistanceLength.NormalizedPixelPercentage.Value))
continue;
personKeysRangesCollection = GetPersonKeysRangesCollection(keyValuePairs[faceDistanceLength.NormalizedPixelPercentage.Value]);
sorting = ISorting.Get(faceDistanceEncoding, faceDistanceLength, anyLowerThanTolerance, personKeysRangesCollection);
sorting = ISorting.Get(Shared.Models.Stateless.IFaceDistance.Permyriad, Shared.Models.Stateless.IFaceDistance.Tolerance, faceDistanceEncoding, faceDistanceLength, anyLowerThanTolerance, personKeysRangesCollection);
if (sorting.DistancePermyriad == 0)
continue;
if (sorting.Id == faceDistanceEncoding.Id)
@ -254,7 +254,7 @@ public class MapLogic
if (personKey is null)
continue;
personBirthday = IPersonBirthday.GetPersonBirthday(personKey.Value);
personKeyFormatted = IPersonBirthday.GetFormatted(personBirthday);
personKeyFormatted = IPersonBirthday.GetFormatted(Shared.Models.Stateless.IPersonBirthday.Format, personBirthday);
if (juliePhares.Contains(personKeyFormatted) && !string.IsNullOrEmpty(copyDirectory))
{
if (!Directory.Exists(copyDirectory))
@ -346,7 +346,7 @@ public class MapLogic
personBirthdays = new();
foreach (string personKey in keyValuePair.Value)
{
personBirthday = IPersonBirthday.GetPersonBirthday(personKey);
personBirthday = IPersonBirthday.GetPersonBirthday(Shared.Models.Stateless.IPersonBirthday.Format, personKey);
if (personBirthday is null)
continue;
}
@ -398,7 +398,7 @@ public class MapLogic
approximateYears = person.ApproximateYears;
personBirthday = person.PersonBirthdays[zero];
displayDirectoryName = person.DisplayDirectoryName;
personKeyFormatted = IPersonBirthday.GetFormatted(personBirthday);
personKeyFormatted = IPersonBirthday.GetFormatted(Shared.Models.Stateless.IPersonBirthday.Format, personBirthday);
mappingSegmentB = GetMappingSegmentB(_Ticks, personBirthday, approximateYears, face.Mapping.MappingFromItem);
face.Mapping.UpdateMappingFromPerson(approximateYears, by, displayDirectoryName, personBirthday, mappingSegmentB);
}
@ -415,7 +415,7 @@ public class MapLogic
approximateYears = person.ApproximateYears;
personBirthday = person.PersonBirthdays[zero];
displayDirectoryName = person.DisplayDirectoryName;
personKeyFormatted = IPersonBirthday.GetFormatted(personBirthday);
personKeyFormatted = IPersonBirthday.GetFormatted(Shared.Models.Stateless.IPersonBirthday.Format, personBirthday);
mappingSegmentB = GetMappingSegmentB(_Ticks, personBirthday, approximateYears, face.Mapping.MappingFromItem);
face.Mapping.UpdateMappingFromPerson(approximateYears, by, displayDirectoryName, personBirthday, mappingSegmentB);
}
@ -490,7 +490,7 @@ public class MapLogic
foreach (long personKey in _NotMappedPersonKeys)
{
personBirthday = IPersonBirthday.GetPersonBirthday(personKey);
personKeyFormatted = IPersonBirthday.GetFormatted(personBirthday);
personKeyFormatted = IPersonBirthday.GetFormatted(Shared.Models.Stateless.IPersonBirthday.Format, personBirthday);
directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, $"{facePopulatedKey}NotMapped", personKeyFormatted, Property.Models.Stateless.IResult.AllInOne);
saveContainer = new(directory);
saveContainers.Add(saveContainer);
@ -583,7 +583,7 @@ public class MapLogic
}
}
face = faceCollection[zero];
personKeyFormatted = IPersonBirthday.GetFormatted(personBirthday);
personKeyFormatted = IPersonBirthday.GetFormatted(Shared.Models.Stateless.IPersonBirthday.Format, personBirthday);
directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, "Shortcuts", personKeyFormatted, subDirectoryName);
if (face.FaceEncoding is not null && face.Location?.NormalizedPixelPercentage is not null)
copyDirectory = Path.Combine(_ZPropertyHolderContentTicksDirectory, "Images", personKeyFormatted, subDirectoryName);
@ -691,7 +691,7 @@ public class MapLogic
if (!keyValuePairs.ContainsKey(sortingContainer.Sorting.NormalizedPixelPercentage))
throw new NotSupportedException();
personBirthdays = keyValuePairs[sortingContainer.Sorting.NormalizedPixelPercentage];
if (sortingContainer.Sorting.DistancePermyriad > Shared.Models.Stateless.IFaceDistance.Permyriad || sortingContainer.Sorting.DaysDelta > Shared.Models.Stateless.ISorting.DaysDeltaTolerance)
if (sortingContainer.Face.Mapping.MappingFromLocation.Confidence < Shared.Models.Stateless.IFaceDistance.MinimumConfidence || sortingContainer.Sorting.DistancePermyriad > Shared.Models.Stateless.IFaceDistance.Permyriad || sortingContainer.Sorting.DaysDelta > Shared.Models.Stateless.ISorting.DaysDeltaTolerance)
continue;
for (int i = 0; i < personBirthdays.Length; i++)
{
@ -700,7 +700,7 @@ public class MapLogic
continue;
person = _PeopleKeyValuePairs[personKey];
personBirthday = person.PersonBirthdays[zero];
personKeyFormatted = IPersonBirthday.GetFormatted(personBirthday);
personKeyFormatted = IPersonBirthday.GetFormatted(Shared.Models.Stateless.IPersonBirthday.Format, personBirthday);
mappingSegmentB = GetMappingSegmentB(_Ticks, personBirthday, person.ApproximateYears, sortingContainer.Face.Mapping.MappingFromItem);
key = string.Concat(personKeyFormatted, '\t', mappingSegmentB);
if (!checkKeyValuePairs.ContainsKey(key))
@ -770,7 +770,7 @@ public class MapLogic
continue;
if (string.IsNullOrEmpty(face.Mapping.MappingFromPerson.SegmentB))
throw new NotSupportedException();
personKeyFormatted = IPersonBirthday.GetFormatted(face.Mapping.MappingFromPerson.PersonBirthday);
personKeyFormatted = IPersonBirthday.GetFormatted(Shared.Models.Stateless.IPersonBirthday.Format, face.Mapping.MappingFromPerson.PersonBirthday);
if (face.Mapping.MappingFromPerson.By is null)
by = $"{nameof(Mapping)}Null";
else

View File

@ -32,7 +32,7 @@ public class ByDeterministicHashCode
Dictionary<string, Person> personKeyValuePairs = new();
foreach (Person person in people)
{
personKeyFormatted = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(person.Birthday);
personKeyFormatted = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(Shared.Models.Stateless.IPersonBirthday.Format, person.Birthday);
if (personKeyValuePairs.ContainsKey(personKeyFormatted))
break;
personKeyValuePairs.Add(personKeyFormatted, person);
@ -71,11 +71,11 @@ public class ByDeterministicHashCode
{
personKeyFormatted = Path.GetFileName(personKeyDirectory);
if (!DateTime.TryParseExact(personKeyFormatted, "MM.dd.yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime birthday))
personBirthday = Shared.Models.Stateless.Methods.IPersonBirthday.GetPersonBirthday(personKeyFormatted);
personBirthday = Shared.Models.Stateless.Methods.IPersonBirthday.GetPersonBirthday(Shared.Models.Stateless.IPersonBirthday.Format, personKeyFormatted);
else
{
personBirthday = new PersonBirthday(birthday);
personKeyFormatted = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(personBirthday);
personKeyFormatted = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(Shared.Models.Stateless.IPersonBirthday.Format, personBirthday);
convertedPersonKeyDirectory = Path.Combine(personDisplayDirectory, personKeyFormatted);
if (!Directory.Exists(convertedPersonKeyDirectory))
Directory.Move(personKeyDirectory, convertedPersonKeyDirectory);
@ -89,7 +89,7 @@ public class ByDeterministicHashCode
foreach (string personKeyDirectory in personKeyDirectories)
{
personKeyFormatted = Path.GetFileName(personKeyDirectory);
personBirthday = Shared.Models.Stateless.Methods.IPersonBirthday.GetPersonBirthday(personKeyFormatted);
personBirthday = Shared.Models.Stateless.Methods.IPersonBirthday.GetPersonBirthday(Shared.Models.Stateless.IPersonBirthday.Format, personKeyFormatted);
if (personBirthday is null)
continue;
if (personKeyValuePairs.ContainsKey(personKeyFormatted))
@ -130,7 +130,7 @@ public class ByDeterministicHashCode
personKey = incrementDate.Ticks;
personBirthday = new(incrementDate);
incrementDate = incrementDate.AddDays(1);
personKeyFormatted = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(personBirthday);
personKeyFormatted = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(Shared.Models.Stateless.IPersonBirthday.Format, personBirthday);
if (personKeys.Contains(personKey))
continue;
personKeys.Add(personKey);
@ -174,7 +174,7 @@ public class ByDeterministicHashCode
personBirthday = null;
else
{
personBirthday = Shared.Models.Stateless.Methods.IPersonBirthday.GetPersonBirthday(personKeyFormatted);
personBirthday = Shared.Models.Stateless.Methods.IPersonBirthday.GetPersonBirthday(Shared.Models.Stateless.IPersonBirthday.Format, personKeyFormatted);
if (personBirthday is null)
continue;
personKey = personBirthday.Value.Ticks;
@ -208,7 +208,7 @@ public class ByDeterministicHashCode
{
if (file.EndsWith(".lnk") || file.EndsWith(".json"))
continue;
(id, normalizedPixelPercentage) = Shared.Models.Stateless.Methods.IMapping.GetReversedDeterministicHashCodeKey(keyValuePairsAny, keyValuePairs, file);
(id, normalizedPixelPercentage) = Shared.Models.Stateless.Methods.IMapping.GetReversedDeterministicHashCodeKey(Shared.Models.Stateless.ILocation.Digits, keyValuePairsAny, keyValuePairs, file);
if (id is null || normalizedPixelPercentage is null)
continue;
idThenNormalizedPixelPercentageCollection.Add(new(personBirthday, id.Value, normalizedPixelPercentage.Value));

View File

@ -5,10 +5,10 @@ namespace View_by_Distance.Property.Models.Stateless;
public interface IResult
{
public const string Content = "()";
public const string Singleton = "{}";
public const string Collection = "[]";
public const string AllInOne = "_ _ _";
const string Content = "()";
const string Singleton = "{}";
const string Collection = "[]";
const string AllInOne = "_ _ _";
string TestStatic_GetRelativePath(Configuration configuration, string path);
static string GetRelativePath(Configuration configuration, string path)

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)

View File

@ -85,8 +85,8 @@ public class UnitTestResize
width = 100;
height = 100;
Location location = new(bottom, confidence, left, null, right, top);
_ = new Location(confidence, height, location, width, 1);
_ = new Location(bottom, confidence, height, left, right, top, width, 1);
_ = new Location(confidence, height, location, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, width, 1);
_ = new Location(bottom, confidence, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width, 1);
}
[TestMethod]
@ -100,7 +100,7 @@ public class UnitTestResize
bottom = 10;
width = 100;
height = 100;
normalizedPixelPercentage = Shared.Models.Stateless.Methods.ILocation.GetNormalizedPixelPercentage(bottom, height, left, right, top, width, 1);
normalizedPixelPercentage = Shared.Models.Stateless.Methods.ILocation.GetNormalizedPixelPercentage(bottom, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width, 1);
Assert.IsTrue(normalizedPixelPercentage == 40500);
left = 50;
top = 50;
@ -108,7 +108,7 @@ public class UnitTestResize
bottom = 60;
width = 100;
height = 100;
normalizedPixelPercentage = Shared.Models.Stateless.Methods.ILocation.GetNormalizedPixelPercentage(bottom, height, left, right, top, width, 1);
normalizedPixelPercentage = Shared.Models.Stateless.Methods.ILocation.GetNormalizedPixelPercentage(bottom, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width, 1);
Assert.IsTrue(normalizedPixelPercentage == 545500);
}
@ -123,7 +123,7 @@ public class UnitTestResize
bottom = 260;
width = 500;
height = 500;
normalizedPixelPercentage = Shared.Models.Stateless.Methods.ILocation.GetNormalizedPixelPercentage(bottom, height, left, right, top, width, 1);
normalizedPixelPercentage = Shared.Models.Stateless.Methods.ILocation.GetNormalizedPixelPercentage(bottom, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width, 1);
Assert.IsTrue(normalizedPixelPercentage == 499000);
left = 490;
top = 490;
@ -131,7 +131,7 @@ public class UnitTestResize
bottom = 510;
width = 1000;
height = 1000;
normalizedPixelPercentage = Shared.Models.Stateless.Methods.ILocation.GetNormalizedPixelPercentage(bottom, height, left, right, top, width, 1);
normalizedPixelPercentage = Shared.Models.Stateless.Methods.ILocation.GetNormalizedPixelPercentage(bottom, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width, 1);
Assert.IsTrue(normalizedPixelPercentage == 499500);
}
@ -146,7 +146,7 @@ public class UnitTestResize
bottom = 80;
width = 100;
height = 100;
normalizedPixelPercentage = Shared.Models.Stateless.Methods.ILocation.GetNormalizedPixelPercentage(bottom, height, left, right, top, width, 1);
normalizedPixelPercentage = Shared.Models.Stateless.Methods.ILocation.GetNormalizedPixelPercentage(bottom, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width, 1);
Assert.IsTrue(normalizedPixelPercentage == 594000);
left = 20;
top = 40;
@ -154,7 +154,7 @@ public class UnitTestResize
bottom = 80;
width = 100;
height = 100;
normalizedPixelPercentage = Shared.Models.Stateless.Methods.ILocation.GetNormalizedPixelPercentage(bottom, height, left, right, top, width, 10);
normalizedPixelPercentage = Shared.Models.Stateless.Methods.ILocation.GetNormalizedPixelPercentage(bottom, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width, 10);
Assert.IsTrue(normalizedPixelPercentage == 594000);
}

View File

@ -20,16 +20,5 @@
"Z-Compare-Publish-": "dotnet publish \"Compare\\Compare.csproj\" --configuration Release --runtime win-x64 --verbosity normal --self-contained true -o \"D:\\net6.0\\View-by-Distance\\Compare\\\"",
"Z-Instance-Publish-": "dotnet publish \"Instance\\Instance.csproj\" --configuration Release --runtime win-x64 --verbosity normal --self-contained true -o \"D:\\net6.0\\View-by-Distance\\Instance\\\"",
"Z-Instance-CUDA-Publish-": "dotnet publish \"Instance\\Instance.csproj\" --configuration Release --runtime win-x64 --verbosity normal --self-contained true -o \"D:\\net6.0\\View-by-Distance\\Instance-CUDA\\\""
},
"Notes": {
"AmazonUsername": "phares36@gmail.com",
"AmazonPassword": "JlPhgtv@63",
"a": "Keep creating the .json file the same way",
"b": "However load all .json files at the beginning",
"c": "When looping through all files and file not in collection path&name or date is different from collection value",
"d": "Get id in normal fashion",
"e": "If id is in collection update collection to new path/name",
"f": "If not save and add to collection",
"g": "Nicéphore Niépce in 1826 or 1827"
}
}