Tested first run

This commit is contained in:
2022-08-29 19:30:36 -07:00
parent 659e0e39bf
commit 753eeaba2a
26 changed files with 711 additions and 458 deletions

View File

@ -5,6 +5,7 @@ public interface IFaceDistance
// 637972153144596958
// const int MaximumPer = 999;
const int HiddenImageFactor = 2;
const int MaximumPer = 9999;
const double Tolerance = 0.6d;

View File

@ -3,6 +3,7 @@
public interface IPersonBirthday
{
const int FirstYear = 1500;
const string Format = "yyyy-MM-dd_HH";
}

View File

@ -7,6 +7,10 @@ public interface ILocation
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(int factor, Models.Location? location, int height, int width, int 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);
int?[] TestStatic_GetInts(List<Models.Location> locations);
static int?[] GetInts(List<Models.Location> locations) => (from l in locations where l.NormalizedPixelPercentage is not null select l.NormalizedPixelPercentage).ToArray();

View File

@ -5,7 +5,7 @@ public interface IPath
string TestStatic_GetRelativePath(string path, int length);
static string GetRelativePath(string path, int length)
=> XPath.GetRelativePath(path, length);
=> XPath.GetRelativePath(path, length, forceExtensionToLower: false);
bool TestStatic_DeleteEmptyDirectories(string rootDirectory);
static bool DeleteEmptyDirectories(string rootDirectory)
@ -15,6 +15,10 @@ public interface IPath
static List<string> GetDirectoryNames(string directory)
=> XPath.GetDirectoryNames(directory);
string TestStatic_GetRelativePath(string path, int length, bool forceExtensionToLower);
static string GetRelativePath(string path, int length, bool forceExtensionToLower)
=> XPath.GetRelativePath(path, length, forceExtensionToLower);
bool TestStatic_WriteAllText(string path, string contents, bool updateDateWhenMatches, bool compareBeforeWrite);
static bool WriteAllText(string path, string contents, bool updateDateWhenMatches, bool compareBeforeWrite, DateTime? updateToWhenMatches = null)
=> XPath.WriteAllText(path, contents, updateDateWhenMatches, compareBeforeWrite, updateToWhenMatches);

View File

@ -66,7 +66,7 @@ internal abstract class Person
Dictionary<DateTime, string[]> results = new();
string[] segments;
DateTime personKey;
DateTime incrementDate = new(1500, 1, 1);
DateTime incrementDate = new(Stateless.IPersonBirthday.FirstYear, 1, 1);
string[] lines = File.ReadAllLines(knownPeopleFile);
_ = incrementDate.AddDays(lines.Length);
System.Globalization.CultureInfo cultureInfo = System.Globalization.CultureInfo.InvariantCulture;
@ -83,12 +83,15 @@ internal abstract class Person
continue;
results.Add(personKey, segments);
}
int countBefore = results.Count;
DateTime minimumDateTime = results.Keys.Min();
for (int i = 1; i < (1000 - countBefore); i++)
if (results.Any())
{
personKey = minimumDateTime.AddDays(i * -1);
results.Add(personKey, new string[] { personKey.ToString(Stateless.IPerson.KeyFormat) });
int countBefore = results.Count;
DateTime minimumDateTime = results.Keys.Min();
for (int i = 1; i < (1000 - countBefore); i++)
{
personKey = minimumDateTime.AddDays(i * -1);
results.Add(personKey, new string[] { personKey.ToString(Stateless.IPerson.KeyFormat) });
}
}
return results.OrderBy(l => l.Key).ToDictionary(l => l.Key, l => l.Value);
}
@ -202,23 +205,21 @@ internal abstract class Person
Models.Person? person;
string localKnownPeopleFile;
DateTime dateTime = DateTime.MinValue;
string directory = Path.Combine(storage.PeopleRootDirectory, "{}");
if (!Directory.Exists(directory))
_ = Directory.CreateDirectory(directory);
string? rootDirectoryParent = Path.GetDirectoryName(storage.RootDirectory);
if (string.IsNullOrEmpty(rootDirectoryParent))
throw new NullReferenceException(nameof(rootDirectoryParent));
if (!Directory.Exists(rootDirectoryParent))
string peopleContentDirectory = Path.Combine(storage.PeopleRootDirectory, "()");
string peopleSingletonDirectory = Path.Combine(storage.PeopleRootDirectory, "{}");
if (!Directory.Exists(peopleSingletonDirectory))
_ = Directory.CreateDirectory(peopleSingletonDirectory);
if (!Directory.Exists(peopleContentDirectory))
localKnownPeopleFile = string.Empty;
else
{
files = Directory.GetFiles(rootDirectoryParent, "*People*.txt", SearchOption.TopDirectoryOnly);
files = Directory.GetFiles(peopleContentDirectory, "*People*.txt", SearchOption.TopDirectoryOnly);
if (files.Any())
localKnownPeopleFile = files[0];
else
localKnownPeopleFile = string.Empty;
}
files = Directory.GetFiles(directory, "*.json", SearchOption.TopDirectoryOnly);
files = Directory.GetFiles(peopleSingletonDirectory, "*.json", SearchOption.TopDirectoryOnly);
if (!files.Any() && string.IsNullOrEmpty(localKnownPeopleFile))
throw new Exception("Copy \"KnownPeople.txt\" file from server!");
foreach (string file in files)

View File

@ -3,9 +3,25 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
internal abstract class XPath
{
internal static string GetRelativePath(string path, int length)
internal static string GetRelativePath(string path, int length, bool forceExtensionToLower)
{
string result = path[length..].Replace(@"\", "/");
string result;
if (forceExtensionToLower)
{
string extension = Path.GetExtension(path);
string extensionLowered = Path.GetExtension(path).ToLower();
if (extension != extensionLowered)
{
string? directoryName = Path.GetDirectoryName(path);
if (string.IsNullOrEmpty(directoryName))
throw new NullReferenceException(directoryName);
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path);
if (string.IsNullOrEmpty(fileNameWithoutExtension))
throw new NullReferenceException(fileNameWithoutExtension);
path = Path.Combine(directoryName, $"{fileNameWithoutExtension}{extensionLowered}");
}
}
result = path[length..].Replace(@"\", "/");
return result;
}