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,26 +5,26 @@ namespace View_by_Distance.Shared.Models;
public class FileHolder : Properties.IFileHolder
{
protected readonly DateTime _CreationTime;
protected readonly DateTime? _CreationTime;
protected readonly string? _DirectoryName;
protected readonly bool _Exists;
protected readonly string _ExtensionLowered;
protected readonly string _FullName;
protected readonly DateTime _LastWriteTime;
protected readonly DateTime? _LastWriteTime;
protected readonly long? _Length;
protected readonly string _Name;
protected readonly string _NameWithoutExtension;
public DateTime CreationTime => _CreationTime;
public DateTime? CreationTime => _CreationTime;
public string? DirectoryName => _DirectoryName;
public bool Exists => _Exists;
public string ExtensionLowered => _ExtensionLowered;
public string FullName => _FullName;
public DateTime LastWriteTime => _LastWriteTime;
public DateTime? LastWriteTime => _LastWriteTime;
public long? Length => _Length;
public string Name => _Name;
public string NameWithoutExtension => _NameWithoutExtension;
public FileHolder(DateTime creationTime, string? directoryName, bool exists, string extensionLowered, string fullName, DateTime lastWriteTime, long? length, string name, string nameWithoutExtension)
public FileHolder(DateTime? creationTime, string? directoryName, bool exists, string extensionLowered, string fullName, DateTime? lastWriteTime, long? length, string name, string nameWithoutExtension)
{
_CreationTime = creationTime;
_DirectoryName = directoryName;
@ -37,36 +37,26 @@ public class FileHolder : Properties.IFileHolder
_NameWithoutExtension = nameWithoutExtension;
}
public FileHolder(string fileName)
public FileHolder(FileInfo fileInfo)
{
FileInfo fileInfo = new(fileName);
_CreationTime = fileInfo.CreationTime;
_CreationTime = fileInfo.CreationTime;
if (fileInfo.Exists)
{
_CreationTime = fileInfo.CreationTime;
_CreationTime = fileInfo.CreationTime;
_LastWriteTime = fileInfo.LastWriteTime;
_Length = fileInfo.Length;
}
_DirectoryName = fileInfo.DirectoryName;
_Exists = fileInfo.Exists;
_ExtensionLowered = fileInfo.Extension.ToLower();
_FullName = fileInfo.FullName;
_LastWriteTime = fileInfo.LastWriteTime;
if (fileInfo.Exists)
_Length = fileInfo.Length;
_Name = fileInfo.Name;
_NameWithoutExtension = Path.GetFileNameWithoutExtension(fileInfo.FullName);
}
public FileHolder(FileInfo fileInfo)
{
_CreationTime = fileInfo.CreationTime;
_CreationTime = fileInfo.CreationTime;
_DirectoryName = fileInfo.DirectoryName;
_Exists = fileInfo.Exists;
_ExtensionLowered = fileInfo.Extension.ToLower();
_FullName = fileInfo.FullName;
_LastWriteTime = fileInfo.LastWriteTime;
if (fileInfo.Exists)
_Length = fileInfo.Length;
_Name = fileInfo.Name;
_NameWithoutExtension = Path.GetFileNameWithoutExtension(fileInfo.FullName);
}
public FileHolder(string fileName) :
this(new FileInfo(fileName))
{ }
public override string ToString()
{

View File

@ -39,6 +39,24 @@ public class Location : Properties.ILocation, IEquatable<Location>
this(bottom, confidence, left, GetNormalizedPixelPercentage(bottom, height, left, right, top, width, zCount), right, top) =>
Check(_Bottom, height, _Left, _NormalizedPixelPercentage, _Right, _Top, width, zCount);
public Location(double confidence, int factor, int height, Location location, int width, int zCount)
{
int x = (location.Right - location.Left) / factor;
int y = (location.Bottom - location.Top) / factor;
int bottom = Math.Min(location.Bottom + y, height);
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 = GetNormalizedPixelPercentage(location.Bottom, height, location.Left, location.Right, location.Top, width, zCount);
Check(bottom, left, _NormalizedPixelPercentage, right, top, zCount);
_Confidence = confidence;
_Bottom = bottom;
_Left = left;
_NormalizedPixelPercentage = normalizedPixelPercentage;
_Right = right;
_Top = top;
}
public override bool Equals(object? obj) => Equals(obj as Location);
public override string ToString()

View File

@ -46,4 +46,6 @@ public class Mapping : Properties.IMapping
public void SetFiltered() => _Filtered = true;
public void SetFiltered(bool value) => _Filtered = value;
}

View File

@ -3,12 +3,12 @@ namespace View_by_Distance.Shared.Models.Properties;
public interface IFileHolder
{
public DateTime CreationTime { get; }
public DateTime? CreationTime { get; }
public string? DirectoryName { get; }
public bool Exists { get; }
public string ExtensionLowered { get; }
public string FullName { get; }
public DateTime LastWriteTime { get; }
public DateTime? LastWriteTime { get; }
public long? Length { get; }
public string Name { get; }
public string NameWithoutExtension { get; }

View File

@ -0,0 +1,53 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace View_by_Distance.Shared.Models;
public class SaveContainer
{
protected readonly string _CheckFile;
protected readonly string _Directory;
protected readonly FileHolder? _FaceFileHolder;
protected readonly FileHolder? _HiddenFaceFileHolder;
protected readonly string _Json;
protected readonly FileHolder? _FacePartsFileHolder;
protected readonly FileHolder? _ResizedFileHolder;
protected readonly string _ShortcutFile;
public string CheckFile => _CheckFile;
public string Directory => _Directory;
public FileHolder? FaceFileHolder => _FaceFileHolder;
public FileHolder? HiddenFaceFileHolder => _HiddenFaceFileHolder;
public string Json => _Json;
public FileHolder? FacePartsFileHolder => _FacePartsFileHolder;
public FileHolder? ResizedFileHolder => _ResizedFileHolder;
public string ShortcutFile => _ShortcutFile;
[JsonConstructor]
public SaveContainer(string checkFile, string directory, FileHolder? faceFileHolder, FileHolder? hiddenFaceFileHolder, string json, FileHolder? facePartsFileHolder, FileHolder? resizedFileHolder, string shortcutFile)
{
_CheckFile = checkFile;
_Directory = directory;
_FaceFileHolder = faceFileHolder;
_HiddenFaceFileHolder = hiddenFaceFileHolder;
_Json = json;
_FacePartsFileHolder = facePartsFileHolder;
_ResizedFileHolder = resizedFileHolder;
_ShortcutFile = shortcutFile;
}
public SaveContainer(string directory) :
this(string.Empty, directory, null, null, string.Empty, null, null, string.Empty)
{ }
public SaveContainer(string checkFile, string directory, string json) :
this(checkFile, directory, null, null, json, null, null, string.Empty)
{ }
public override string ToString()
{
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
return result;
}
}

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;
}