After testing E_Distance.SaveGroupedFaceEncodings
This commit is contained in:
@ -1,4 +1,3 @@
|
||||
using System.Drawing;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using View_by_Distance.Shared.Models.Methods;
|
||||
@ -8,37 +7,40 @@ namespace View_by_Distance.Shared.Models;
|
||||
public class Location : Properties.ILocation, ILocation, IEquatable<Location>
|
||||
{
|
||||
|
||||
public double Confidence => _Confidence;
|
||||
protected double _Confidence;
|
||||
protected int _Bottom;
|
||||
protected int _Left;
|
||||
protected double? _PixelPercentage;
|
||||
protected int _Right;
|
||||
protected int _Top;
|
||||
public double Confidence => _Confidence;
|
||||
public int Bottom => _Bottom;
|
||||
public int Left => _Left;
|
||||
public double? PixelPercentage => _PixelPercentage;
|
||||
public int Right => _Right;
|
||||
public int Top => _Top;
|
||||
|
||||
[JsonConstructor]
|
||||
public Location(double confidence, int bottom, int left, int right, int top)
|
||||
public Location(double confidence, int bottom, int left, double? pixelPercentage, int right, int top)
|
||||
{
|
||||
_Confidence = confidence;
|
||||
_Bottom = bottom;
|
||||
_Left = left;
|
||||
_PixelPercentage = pixelPercentage;
|
||||
_Right = right;
|
||||
_Top = top;
|
||||
}
|
||||
|
||||
public Location(int left, int top, int right, int bottom) :
|
||||
this(-1.0d, bottom, left, right, top)
|
||||
public Location(double confidence, int bottom, int left, int right, int top, int width, int height) :
|
||||
this(confidence, bottom, left, GetPixelPercentage(bottom, left, right, top, width, height), right, top)
|
||||
{ }
|
||||
|
||||
public Location(Rectangle rectangle, double confidence) :
|
||||
this(-1.0d, rectangle.Bottom, rectangle.Left, rectangle.Right, rectangle.Top)
|
||||
public Location(double confidence, Location location, int width, int height) :
|
||||
this(confidence, location.Bottom, location.Left, location.Right, location.Top, width, height)
|
||||
{ }
|
||||
|
||||
public Location(Location location, double confidence) :
|
||||
this(-1.0d, location.Bottom, location.Left, location.Right, location.Top)
|
||||
public Location(int left, int top, int right, int bottom, int width, int height) :
|
||||
this(-1.0d, bottom, left, right, top, width, height)
|
||||
{ }
|
||||
|
||||
public override bool Equals(object? obj) => Equals(obj as Location);
|
||||
@ -59,6 +61,15 @@ public class Location : Properties.ILocation, ILocation, IEquatable<Location>
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
public static double GetPixelPercentage(int left, int top, int right, int bottom, int width, int height)
|
||||
{
|
||||
double result;
|
||||
double xCenter = left + ((right - left) / 2);
|
||||
double yCenter = top + ((bottom - top) / 2);
|
||||
result = ((yCenter * width) + xCenter) / (width * height);
|
||||
return (double)Math.Round((decimal)result, 4);
|
||||
}
|
||||
|
||||
public bool Equals(Location? location)
|
||||
{
|
||||
return location is not null
|
||||
|
@ -26,7 +26,7 @@
|
||||
// public int? mappedMaxIndex;
|
||||
// public int? maxImagesInDirectoryForTopLevelFirstPass;
|
||||
// public int? maxItemsInDistanceCollection;
|
||||
// public int? numJitters;
|
||||
// public int? numberOfJitters;
|
||||
// public int? outputQuality;
|
||||
// public int? paddingLoops;
|
||||
// public string dateGroup;
|
||||
|
@ -9,51 +9,46 @@ public enum FacePart
|
||||
/// <summary>
|
||||
/// Specifies the chin.
|
||||
/// </summary>
|
||||
Chin,
|
||||
Chin = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the left eyebrow.
|
||||
/// </summary>
|
||||
LeftEyebrow,
|
||||
LeftEyebrow = 17,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the right eyebrow.
|
||||
/// </summary>
|
||||
RightEyebrow,
|
||||
RightEyebrow = 22,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the nose bridge.
|
||||
/// </summary>
|
||||
NoseBridge,
|
||||
NoseBridge = 27,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the nose tip.
|
||||
/// </summary>
|
||||
NoseTip,
|
||||
NoseTip = 31,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the left eye.
|
||||
/// </summary>
|
||||
LeftEye,
|
||||
LeftEye = 36,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the right eye.
|
||||
/// </summary>
|
||||
RightEye,
|
||||
RightEye = 42,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the top lip.
|
||||
/// </summary>
|
||||
TopLip,
|
||||
TopLip = 48,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the bottom lip.
|
||||
/// </summary>
|
||||
BottomLip,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the nose.
|
||||
/// </summary>
|
||||
Nose,
|
||||
BottomLip = 55
|
||||
|
||||
}
|
@ -12,17 +12,23 @@ public interface IPersonBirthday
|
||||
string TestStatic_GetFormat() => PersonBirthday.GetFormat();
|
||||
static string GetFormat() => PersonBirthday.GetFormat();
|
||||
|
||||
Models.PersonBirthday TestStatic_GetNextBirthDate(Properties.IStorage storage) => PersonBirthday.GetNextBirthDate(storage);
|
||||
static Models.PersonBirthday GetNextBirthDate(Properties.IStorage storage) => PersonBirthday.GetNextBirthDate(storage);
|
||||
string[] TestStatic_GetSegments(string personKey) => PersonBirthday.GetSegments(personKey);
|
||||
static string[] GetSegments(string personKey) => PersonBirthday.GetSegments(personKey);
|
||||
|
||||
DateTime? TestStatic_GetDateTime(string personKey) => PersonBirthday.GetDateTime(personKey);
|
||||
static DateTime? GetDateTime(string personKey) => PersonBirthday.GetDateTime(personKey);
|
||||
|
||||
string TestStatic_GetFileName(Models.PersonBirthday personBirthday) => PersonBirthday.GetFileName(personBirthday);
|
||||
static string GetFileName(Models.PersonBirthday personBirthday) => PersonBirthday.GetFileName(personBirthday);
|
||||
|
||||
Models.PersonBirthday? TestStatic_GetPersonBirthday(string personKey) => PersonBirthday.GetPersonBirthday(personKey);
|
||||
static Models.PersonBirthday? GetPersonBirthday(string personKey) => PersonBirthday.GetPersonBirthday(personKey);
|
||||
|
||||
string TestStatic_GetFormatted(Models.PersonBirthday personBirthday) => PersonBirthday.GetFormatted(personBirthday);
|
||||
static string GetFormatted(Models.PersonBirthday personBirthday) => PersonBirthday.GetFormatted(personBirthday);
|
||||
|
||||
DateTime? TestStatic_Get(string personKey) => PersonBirthday.Get(personKey);
|
||||
static DateTime? Get(string personKey) => PersonBirthday.Get(personKey);
|
||||
|
||||
string TestStatic_GetFileName(Models.PersonBirthday personBirthday) => PersonBirthday.GetFileName(personBirthday);
|
||||
static string GetFileName(Models.PersonBirthday personBirthday) => PersonBirthday.GetFileName(personBirthday);
|
||||
Models.PersonBirthday TestStatic_GetNextBirthDate(Properties.IStorage storage) => PersonBirthday.GetNextBirthDate(storage);
|
||||
static Models.PersonBirthday GetNextBirthDate(Properties.IStorage storage) => PersonBirthday.GetNextBirthDate(storage);
|
||||
|
||||
bool TestStatic_DoesBirthDateExits(Properties.IStorage storage, Models.PersonBirthday personBirthday) => DoesBirthDateExits(storage, personBirthday);
|
||||
static bool DoesBirthDateExits(Properties.IStorage storage, Models.PersonBirthday personBirthday) => DoesBirthDateExits(storage, personBirthday);
|
||||
@ -30,4 +36,7 @@ public interface IPersonBirthday
|
||||
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);
|
||||
|
||||
TimeSpan? TestStatic_Get(DateTime minimumDateTime, bool? isWrongYear, Models.PersonBirthday personBirthday) => PersonBirthday.GetTimeSpan(minimumDateTime, isWrongYear, personBirthday);
|
||||
static TimeSpan? GetTimeSpan(DateTime minimumDateTime, bool? isWrongYear, Models.PersonBirthday personBirthday) => PersonBirthday.GetTimeSpan(minimumDateTime, isWrongYear, personBirthday);
|
||||
|
||||
}
|
@ -5,8 +5,8 @@ public interface IStorage
|
||||
|
||||
// ...
|
||||
|
||||
bool TestStatic_WriteAllText(string path, string contents, bool compareBeforeWrite);
|
||||
static bool WriteAllText(string path, string contents, bool compareBeforeWrite) => Storage.WriteAllText(path, contents, compareBeforeWrite);
|
||||
bool TestStatic_WriteAllText(string path, string contents, bool updateDateWhenMatches, bool compareBeforeWrite);
|
||||
static bool WriteAllText(string path, string contents, bool updateDateWhenMatches, bool compareBeforeWrite) => Storage.WriteAllText(path, contents, updateDateWhenMatches, compareBeforeWrite);
|
||||
|
||||
(string RootResultsDirectoryAbsoluteUri, string C_ResizeContentDirectory, string D_FacesContentDirectory, string E_DistanceCollectionDirectory) TestStatic_GetTuple(Properties.IStorage storage);
|
||||
static (string RootResultsDirectoryAbsoluteUri, string C_ResizeContentDirectory, string D_FacesContentDirectory, string E_DistanceCollectionDirectory) GetTuple(Properties.IStorage storage) => new(new Uri(storage.RootResultsDirectory).AbsoluteUri, Path.Combine(storage.ResizeRootDirectory, "()"), Path.Combine(storage.FaceRootDirectory, "()"), Path.Combine(storage.DistanceResultRootDirectory, "[]"));
|
||||
|
@ -130,7 +130,7 @@ internal abstract class Person
|
||||
{
|
||||
string fileName = IPerson.GetFileFullName(storage, person);
|
||||
string json = JsonSerializer.Serialize(person, new JsonSerializerOptions { WriteIndented = true });
|
||||
_ = IStorage.WriteAllText(fileName, json, compareBeforeWrite: true);
|
||||
_ = IStorage.WriteAllText(fileName, json, updateDateWhenMatches: true, compareBeforeWrite: true);
|
||||
}
|
||||
|
||||
private static List<Models.Person> GetPeopleFromText(Properties.IStorage storage, string localKnownPeopleFile)
|
||||
@ -189,7 +189,7 @@ internal abstract class Person
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
string? rootDirectoryParent = Path.GetDirectoryName(storage.RootDirectory);
|
||||
if (string.IsNullOrEmpty(rootDirectoryParent))
|
||||
throw new Exception($"{nameof(rootDirectoryParent)} is null!");
|
||||
throw new ArgumentNullException(nameof(rootDirectoryParent));
|
||||
if (!Directory.Exists(rootDirectoryParent))
|
||||
localKnownPeopleFile = string.Empty;
|
||||
else
|
||||
|
@ -10,10 +10,33 @@ internal abstract class PersonBirthday
|
||||
// ...
|
||||
|
||||
internal static string GetFormat() => "yyyy-MM-dd_HH";
|
||||
internal static Models.PersonBirthday GetNextBirthDate(Properties.IStorage storage) => throw new Exception(storage.ToString()); // Person.GetNextBirthDate(storage);
|
||||
internal static string[] GetSegments(string personKey) => personKey.Split('\t');
|
||||
internal static string GetFormatted(Models.PersonBirthday personBirthday) => personBirthday.Value.ToString(GetFormat());
|
||||
internal static string GetFileName(Models.PersonBirthday personBirthday) => $"{personBirthday.Value.ToString(GetFormat())}.json";
|
||||
internal static bool DoesBirthDateExits(Properties.IStorage storage, Models.PersonBirthday personBirthday) => File.Exists(GetFileFullName(storage, 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? Get(string personKey) => DateTime.TryParseExact(personKey, GetFormat(), CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dateTime) ? dateTime : null;
|
||||
internal static DateTime? GetDateTime(string personKey) => DateTime.TryParseExact(personKey, GetFormat(), CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dateTime) ? dateTime : null;
|
||||
|
||||
internal static Models.PersonBirthday? GetPersonBirthday(string personKey)
|
||||
{
|
||||
Models.PersonBirthday? result;
|
||||
string[] segments = GetSegments(personKey);
|
||||
DateTime? dateTime = GetDateTime(segments[0]);
|
||||
if (dateTime is null)
|
||||
result = null;
|
||||
else
|
||||
result = new(dateTime.Value);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static TimeSpan? GetTimeSpan(DateTime minimumDateTime, bool? isWrongYear, Models.PersonBirthday personBirthday)
|
||||
{
|
||||
TimeSpan? timeSpan;
|
||||
if (isWrongYear is null || isWrongYear.Value || personBirthday.Value.Year < 1900)
|
||||
timeSpan = null;
|
||||
else
|
||||
timeSpan = new(minimumDateTime.Ticks - personBirthday.Value.Ticks);
|
||||
return timeSpan;
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ internal abstract class Storage
|
||||
|
||||
// ...
|
||||
|
||||
internal static bool WriteAllText(string path, string contents, bool compareBeforeWrite)
|
||||
internal static bool WriteAllText(string path, string contents, bool updateDateWhenMatches, bool compareBeforeWrite)
|
||||
{
|
||||
bool result;
|
||||
string text;
|
||||
@ -18,9 +18,24 @@ internal abstract class Storage
|
||||
else
|
||||
text = File.ReadAllText(path);
|
||||
result = text != contents;
|
||||
if (!result && updateDateWhenMatches)
|
||||
File.SetLastWriteTime(path, DateTime.Now);
|
||||
}
|
||||
if (result)
|
||||
File.WriteAllText(path, contents);
|
||||
{
|
||||
if (path.Contains("()"))
|
||||
File.WriteAllText(path, contents);
|
||||
else if (path.Contains("{}") && !path.EndsWith(".json"))
|
||||
File.WriteAllText(path, contents);
|
||||
else if (path.Contains("[]") && !path.EndsWith(".json"))
|
||||
File.WriteAllText(path, contents);
|
||||
else if (path.Contains("{}") && path.EndsWith(".json") && contents[0] == '{')
|
||||
File.WriteAllText(path, contents);
|
||||
else if (path.Contains("[]") && path.EndsWith(".json") && contents[0] == '[')
|
||||
File.WriteAllText(path, contents);
|
||||
else
|
||||
File.WriteAllText(path, contents);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user