Re-write
This commit is contained in:
1
Shared/.vscode/format-report.json
vendored
Normal file
1
Shared/.vscode/format-report.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
[]
|
47
Shared/Models/Closest.cs
Normal file
47
Shared/Models/Closest.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace View_by_Distance.Shared.Models;
|
||||
|
||||
public class Closest : Properties.IClosest
|
||||
{
|
||||
|
||||
protected readonly double? _Average;
|
||||
protected readonly int? _NormalizedPixelPercentage;
|
||||
protected readonly bool? _IsWrongYear;
|
||||
protected readonly double? _Minimum;
|
||||
protected readonly DateTime _MinimumDateTime;
|
||||
protected readonly PersonBirthday? _PersonBirthday;
|
||||
public double? Average => _Average;
|
||||
public int? NormalizedPixelPercentage => _NormalizedPixelPercentage;
|
||||
public bool? IsWrongYear => _IsWrongYear;
|
||||
public double? Minimum => _Minimum;
|
||||
public DateTime MinimumDateTime => _MinimumDateTime;
|
||||
public PersonBirthday? PersonBirthday => _PersonBirthday;
|
||||
|
||||
[JsonConstructor]
|
||||
public Closest(double? average, int? normalizedPixelPercentage, bool? isWrongYear, double? minimum, DateTime minimumDateTime, PersonBirthday? personBirthday)
|
||||
{
|
||||
_Average = average;
|
||||
_NormalizedPixelPercentage = normalizedPixelPercentage;
|
||||
_IsWrongYear = isWrongYear;
|
||||
_Minimum = minimum;
|
||||
_MinimumDateTime = minimumDateTime;
|
||||
_PersonBirthday = personBirthday;
|
||||
}
|
||||
|
||||
public Closest(int? normalizedPixelPercentage, DateTime minimumDateTime, bool? isWrongYear) :
|
||||
this(null, normalizedPixelPercentage, isWrongYear, null, minimumDateTime, null)
|
||||
{ }
|
||||
|
||||
public Closest(int? normalizedPixelPercentage, DateTime minimumDateTime, bool? isWrongYear, PersonBirthday? personBirthday, List<double> faceDistances) :
|
||||
this(faceDistances.Average(), normalizedPixelPercentage, isWrongYear, faceDistances.Min(), minimumDateTime, personBirthday)
|
||||
{ }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
41
Shared/Models/Container.cs
Normal file
41
Shared/Models/Container.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace View_by_Distance.Shared.Models;
|
||||
|
||||
public class Container : Properties.IContainer
|
||||
{
|
||||
|
||||
protected readonly int _G;
|
||||
protected readonly int _R;
|
||||
protected readonly List<Item> _Items;
|
||||
protected readonly string _SourceDirectory;
|
||||
public int G => _G;
|
||||
public List<Item> Items => _Items;
|
||||
public int R => _R;
|
||||
public string SourceDirectory => _SourceDirectory;
|
||||
|
||||
[JsonConstructor]
|
||||
public Container(int g, int r, List<Item> items, string sourceDirectory)
|
||||
{
|
||||
_G = g;
|
||||
_R = r;
|
||||
_Items = items;
|
||||
_SourceDirectory = sourceDirectory;
|
||||
}
|
||||
|
||||
public Container(int g, int r, string sourceDirectory)
|
||||
{
|
||||
_G = g;
|
||||
_R = r;
|
||||
_Items = new();
|
||||
_SourceDirectory = sourceDirectory;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -1,10 +1,9 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using View_by_Distance.Shared.Models.Methods;
|
||||
|
||||
namespace View_by_Distance.Shared.Models;
|
||||
|
||||
public class DirectoryFileSystem : FileSystem, Properties.IDirectoryFileSystem, IDirectoryFileSystem
|
||||
public class DirectoryFileSystem : FileSystem, Properties.IDirectoryFileSystem
|
||||
{
|
||||
|
||||
// protected new string _ClassName;
|
||||
|
42
Shared/Models/DistanceHolder.cs
Normal file
42
Shared/Models/DistanceHolder.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace View_by_Distance.Shared.Models;
|
||||
|
||||
public class DistanceHolder : Properties.IDistanceHolder
|
||||
{
|
||||
|
||||
public Face Face { init; get; }
|
||||
public FileHolder FileHolder { init; get; }
|
||||
public int Id { init; get; }
|
||||
public string JSONDirectory { init; get; }
|
||||
public Location? Location { init; get; }
|
||||
public string TSVDirectory { init; get; }
|
||||
public double Sort { get; set; }
|
||||
|
||||
[JsonConstructor]
|
||||
public DistanceHolder(
|
||||
Face face,
|
||||
FileHolder fileHolder,
|
||||
int id,
|
||||
string jsonDirectory,
|
||||
Location? location,
|
||||
string tsvDirectory
|
||||
)
|
||||
{
|
||||
FileHolder = fileHolder;
|
||||
Sort = double.MaxValue;
|
||||
Face = face;
|
||||
Id = id;
|
||||
JSONDirectory = jsonDirectory;
|
||||
Location = location;
|
||||
TSVDirectory = tsvDirectory;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -1,52 +1,68 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using View_by_Distance.Shared.Models.Methods;
|
||||
|
||||
namespace View_by_Distance.Shared.Models;
|
||||
|
||||
public class Face : Properties.IFace, IFace
|
||||
public class Face : Properties.IFace
|
||||
{
|
||||
|
||||
protected double? _Α;
|
||||
protected DateTime _DateTime;
|
||||
protected FaceEncoding _FaceEncoding;
|
||||
protected Dictionary<string, FacePoint[]> _FaceLandmarks;
|
||||
protected OutputResolution _OutputResolution;
|
||||
protected Location _Location;
|
||||
protected int? _LocationIndex;
|
||||
protected bool _Populated;
|
||||
protected string _RelativePath;
|
||||
public double? α => _Α;
|
||||
protected FaceEncoding? _FaceEncoding;
|
||||
protected Dictionary<Stateless.FacePart, FacePoint[]>? _FaceParts;
|
||||
protected readonly OutputResolution? _OutputResolution;
|
||||
protected Location? _Location;
|
||||
protected readonly int? _LocationIndex;
|
||||
protected readonly string _RelativePath;
|
||||
public DateTime DateTime => _DateTime;
|
||||
public FaceEncoding FaceEncoding => _FaceEncoding;
|
||||
public Dictionary<string, FacePoint[]> FaceLandmarks => _FaceLandmarks;
|
||||
public OutputResolution OutputResolution => _OutputResolution;
|
||||
public Location Location => _Location;
|
||||
public FaceEncoding? FaceEncoding => _FaceEncoding;
|
||||
public Dictionary<Stateless.FacePart, FacePoint[]>? FaceParts => _FaceParts;
|
||||
public Location? Location => _Location;
|
||||
public int? LocationIndex => _LocationIndex;
|
||||
public bool Populated => _Populated;
|
||||
public OutputResolution? OutputResolution => _OutputResolution;
|
||||
public string RelativePath => _RelativePath;
|
||||
|
||||
[JsonConstructor]
|
||||
public Face(double? α, DateTime dateTime, FaceEncoding faceEncoding, Dictionary<string, FacePoint[]> faceLandmarks, OutputResolution outputResolution, Location location, int? locationIndex, bool populated, string relativePath)
|
||||
public Face(DateTime dateTime, FaceEncoding? faceEncoding, Dictionary<Stateless.FacePart, FacePoint[]>? faceParts, Location? location, int? locationIndex, OutputResolution? outputResolution, string relativePath)
|
||||
{
|
||||
_Α = α;
|
||||
_DateTime = dateTime;
|
||||
_FaceEncoding = faceEncoding;
|
||||
_FaceLandmarks = faceLandmarks;
|
||||
_FaceParts = faceParts;
|
||||
_Location = location;
|
||||
_LocationIndex = locationIndex;
|
||||
_OutputResolution = outputResolution;
|
||||
_Populated = populated;
|
||||
_RelativePath = relativePath;
|
||||
}
|
||||
|
||||
double Stateless.Methods.IFace.TestStatic_Getα(int x1, int x2, int y1, int y2) => throw new NotImplementedException();
|
||||
public Face() :
|
||||
this(DateTime.MinValue, null, null, null, null, null, string.Empty)
|
||||
{ }
|
||||
|
||||
string Stateless.Methods.IFace.TestStatic_GetJson(string jsonFileFullName) => throw new NotImplementedException();
|
||||
public Face(Location location) :
|
||||
this(DateTime.MinValue, null, null, location, null, null, string.Empty)
|
||||
{ }
|
||||
|
||||
Face Stateless.Methods.IFace.TestStatic_GetFace(string jsonFileFullName) => throw new NotImplementedException();
|
||||
public Face(int facesCount, Face face) :
|
||||
this(face.DateTime, face.FaceEncoding, face.FaceParts, face.Location, face.LocationIndex, 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);
|
||||
}
|
||||
|
||||
Face[] Stateless.Methods.IFace.TestStatic_GetFaces(string jsonFileFullName) => throw new NotImplementedException();
|
||||
public Face(int outputResolutionWidth, int outputResolutionHeight, int outputResolutionOrientation, Face face) :
|
||||
this(face.DateTime, face.FaceEncoding, face.FaceParts, face.Location, face.LocationIndex, null, face.RelativePath)
|
||||
{
|
||||
if (outputResolutionHeight > 0)
|
||||
_OutputResolution = new(outputResolutionHeight, outputResolutionOrientation, outputResolutionWidth);
|
||||
}
|
||||
|
||||
public Face(Property property, int outputResolutionWidth, int outputResolutionHeight, int outputResolutionOrientation, string relativePath, int? i, Location? location) :
|
||||
this(DateTime.MinValue, null, null, location, i, null, relativePath)
|
||||
{
|
||||
DateTime?[] dateTimes;
|
||||
_OutputResolution = new(outputResolutionHeight, outputResolutionOrientation, outputResolutionWidth);
|
||||
dateTimes = new DateTime?[] { property.CreationTime, property.LastWriteTime, property.DateTime, property.DateTimeDigitized, property.DateTimeOriginal, property.GPSDateStamp };
|
||||
_DateTime = (from l in dateTimes where l.HasValue select l.Value).Min();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
@ -54,4 +70,7 @@ public class Face : Properties.IFace, IFace
|
||||
return result;
|
||||
}
|
||||
|
||||
public void SetFaceEncoding(FaceEncoding faceEncoding) => _FaceEncoding = faceEncoding;
|
||||
|
||||
public void SetFaceParts(Dictionary<Stateless.FacePart, FacePoint[]> faceParts) => _FaceParts = faceParts;
|
||||
}
|
@ -1,10 +1,9 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using View_by_Distance.Shared.Models.Methods;
|
||||
|
||||
namespace View_by_Distance.Shared.Models;
|
||||
|
||||
public class FaceEncoding : Properties.IFaceEncoding, IFaceEncoding
|
||||
public class FaceEncoding : Properties.IFaceEncoding
|
||||
{
|
||||
|
||||
protected double[] _RawEncoding;
|
||||
|
@ -1,10 +1,9 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using View_by_Distance.Shared.Models.Methods;
|
||||
|
||||
namespace View_by_Distance.Shared.Models;
|
||||
|
||||
public class FaceFileSystem : FileSystem, Properties.IFaceFileSystem, IFaceFileSystem
|
||||
public class FaceFileSystem : FileSystem, Properties.IFaceFileSystem
|
||||
{
|
||||
|
||||
// protected new string _ClassName;
|
||||
@ -77,6 +76,38 @@ public class FaceFileSystem : FileSystem, Properties.IFaceFileSystem, IFaceFileS
|
||||
_SourceSize = sourceSize;
|
||||
}
|
||||
|
||||
private static void FileExists(Face face, int? faceBottom, int? faceRight, out int imageHeight, out int imageWidth, out long sourceSize, FileInfo fileInfo)
|
||||
{
|
||||
sourceSize = fileInfo.Length;
|
||||
if (face.OutputResolution is not null)
|
||||
{
|
||||
imageWidth = face.OutputResolution.Width;
|
||||
imageHeight = face.OutputResolution.Height;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Drawing.Size size = Stateless.Methods.ImageHelper.GetDimensions(fileInfo.FullName, faceRight, faceBottom);
|
||||
imageWidth = size.Width;
|
||||
imageHeight = size.Height;
|
||||
}
|
||||
}
|
||||
|
||||
private static void FileDoesNotExist(string dataFullFileName, Face face, out int imageHeight, out int imageWidth, out long sourceSize, FileInfo fileInfo)
|
||||
{
|
||||
sourceSize = 0;
|
||||
if (face.OutputResolution is null)
|
||||
{
|
||||
imageWidth = 0;
|
||||
imageHeight = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
imageWidth = face.OutputResolution.Width;
|
||||
imageHeight = face.OutputResolution.Height;
|
||||
}
|
||||
Stateless.Methods.IFaceFileSystem.SearchForMissingFile(fileInfo.FullName, fileInfo, dataFullFileName);
|
||||
}
|
||||
|
||||
internal FaceFileSystem(string requestPath, int rootResultsDirectoryAbsoluteUriLength, string cResizeContent, string dFacesContentDirectory, string dataFullFileName, Face face) : base(string.Empty, string.Empty, dataFullFileName, string.Empty, DateTime.MinValue)
|
||||
{
|
||||
string confidence;
|
||||
@ -130,38 +161,12 @@ public class FaceFileSystem : FileSystem, Properties.IFaceFileSystem, IFaceFileS
|
||||
string faceRelativePath = string.Concat(requestPath, new Uri(faceFullFileName).AbsoluteUri[rootResultsDirectoryAbsoluteUriLength..]);
|
||||
string sourceRelativePath = string.Concat(requestPath, new Uri(sourceFullFileName).AbsoluteUri[rootResultsDirectoryAbsoluteUriLength..]);
|
||||
FileInfo fileInfo = new(sourceFullFileName);
|
||||
if (face.Populated && !File.Exists(faceFullFileName))
|
||||
if (face.FaceEncoding is not null && face.Location?.NormalizedPixelPercentage is not null && !File.Exists(faceFullFileName))
|
||||
Stateless.Methods.IFaceFileSystem.SearchForMissingFile(faceFullFileName, fileInfo: new FileInfo(string.Empty), dataFullFileName);
|
||||
if (!fileInfo.Exists)
|
||||
{
|
||||
sourceSize = 0;
|
||||
if (face.OutputResolution is null)
|
||||
{
|
||||
imageWidth = 0;
|
||||
imageHeight = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
imageWidth = face.OutputResolution.Width;
|
||||
imageHeight = face.OutputResolution.Height;
|
||||
}
|
||||
Stateless.Methods.IFaceFileSystem.SearchForMissingFile(fileInfo.FullName, fileInfo, dataFullFileName);
|
||||
}
|
||||
if (fileInfo.Exists)
|
||||
FileExists(face, faceBottom, faceRight, out imageHeight, out imageWidth, out sourceSize, fileInfo);
|
||||
else
|
||||
{
|
||||
sourceSize = fileInfo.Length;
|
||||
if (face.OutputResolution is not null)
|
||||
{
|
||||
imageWidth = face.OutputResolution.Width;
|
||||
imageHeight = face.OutputResolution.Height;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Drawing.Size size = Stateless.Methods.ImageHelper.GetDimensions(fileInfo.FullName, faceRight, faceBottom);
|
||||
imageWidth = size.Width;
|
||||
imageHeight = size.Height;
|
||||
}
|
||||
}
|
||||
FileDoesNotExist(dataFullFileName, face, out imageHeight, out imageWidth, out sourceSize, fileInfo);
|
||||
_ClassName = "file";
|
||||
_FaceBottom = faceBottom;
|
||||
_Confidence = confidence;
|
||||
@ -176,7 +181,7 @@ public class FaceFileSystem : FileSystem, Properties.IFaceFileSystem, IFaceFileS
|
||||
_FaceLeft = faceLeft;
|
||||
_LocationDisplayIndex = locationDisplayIndex;
|
||||
_LocationIndex = face.LocationIndex;
|
||||
_Populated = face.Populated;
|
||||
_Populated = face.FaceEncoding is not null && face.Location?.NormalizedPixelPercentage is not null;
|
||||
_RelativePath = string.Empty;
|
||||
_FaceRight = faceRight;
|
||||
_SourceFullFileName = sourceFullFileName;
|
||||
@ -187,13 +192,13 @@ public class FaceFileSystem : FileSystem, Properties.IFaceFileSystem, IFaceFileS
|
||||
_ImageWidth = imageWidth;
|
||||
}
|
||||
|
||||
string IFileSystem.GetDate()
|
||||
public override string ToString()
|
||||
{
|
||||
string result = _LastModified.ToString("MM/dd/yyyy hh:mm:ss tt");
|
||||
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
||||
return result;
|
||||
}
|
||||
|
||||
string IFaceFileSystem.GetSize()
|
||||
public string GetSize()
|
||||
{
|
||||
string result;
|
||||
if (_SourceSize is null)
|
||||
@ -208,19 +213,9 @@ public class FaceFileSystem : FileSystem, Properties.IFaceFileSystem, IFaceFileS
|
||||
order++;
|
||||
len /= 1024;
|
||||
}
|
||||
result = String.Format("{0:0.##} {1}", len, sizes[order]);
|
||||
result = string.Format("{0:0.##} {1}", len, sizes[order]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void Stateless.Methods.IFaceFileSystem.TestStatic_SearchForMissingFile(string fullFileName, FileInfo fileInfo, string dataFullFileName) => throw new NotImplementedException();
|
||||
|
||||
FaceFileSystem[][] Stateless.Methods.IFaceFileSystem.TestStatic_GetFaceFileSystemCollection(string requestPath, string rootResultsDirectory, (string RootResultsDirectoryAbsoluteUri, string C_ResizeContentDirectory, string D_FacesContentDirectory, string E_DistanceCollectionDirectory) tuple, string selectedFileFullName) => throw new NotImplementedException();
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -1,11 +1,10 @@
|
||||
using System.Drawing;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using View_by_Distance.Shared.Models.Methods;
|
||||
|
||||
namespace View_by_Distance.Shared.Models;
|
||||
|
||||
public class FacePoint : Properties.IFacePoint, IFacePoint
|
||||
public class FacePoint : Properties.IFacePoint
|
||||
{
|
||||
|
||||
protected int _Index;
|
||||
|
77
Shared/Models/FileHolder.cs
Normal file
77
Shared/Models/FileHolder.cs
Normal file
@ -0,0 +1,77 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace View_by_Distance.Shared.Models;
|
||||
|
||||
public class FileHolder : Properties.IFileHolder
|
||||
{
|
||||
|
||||
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 long? _Length;
|
||||
protected readonly string _Name;
|
||||
protected readonly string _NameWithoutExtension;
|
||||
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 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)
|
||||
{
|
||||
_CreationTime = creationTime;
|
||||
_DirectoryName = directoryName;
|
||||
_Exists = exists;
|
||||
_ExtensionLowered = extensionLowered;
|
||||
_FullName = fullName;
|
||||
_LastWriteTime = lastWriteTime;
|
||||
_Length = length;
|
||||
_Name = name;
|
||||
_NameWithoutExtension = nameWithoutExtension;
|
||||
}
|
||||
|
||||
public FileHolder(string fileName)
|
||||
{
|
||||
FileInfo fileInfo = new(fileName);
|
||||
_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(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 override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -1,10 +1,9 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using View_by_Distance.Shared.Models.Methods;
|
||||
|
||||
namespace View_by_Distance.Shared.Models;
|
||||
|
||||
public class FileSystem : Properties.IFileSystem, IFileSystem
|
||||
public class FileSystem : Properties.IFileSystem
|
||||
{
|
||||
|
||||
protected string _ClassName;
|
||||
@ -37,14 +36,12 @@ public class FileSystem : Properties.IFileSystem, IFileSystem
|
||||
_LastModified = DateTime.Now;
|
||||
}
|
||||
|
||||
string IFileSystem.GetDate()
|
||||
public string GetDate()
|
||||
{
|
||||
string result = _LastModified.ToString("MM/dd/yyyy hh:mm:ss tt");
|
||||
return result;
|
||||
}
|
||||
|
||||
List<FileSystem> Stateless.Methods.IFileSystem.TestStatic_GetFileSystemCollection(string requestPath, string rootResultsDirectory, (string RootResultsDirectoryAbsoluteUri, string C_ResizeContentDirectory, string D_FacesContentDirectory, string E_DistanceCollectionDirectory) tuple, string[] directories, string[] files, bool all) => throw new NotImplementedException();
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
||||
|
95
Shared/Models/Item.cs
Normal file
95
Shared/Models/Item.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace View_by_Distance.Shared.Models;
|
||||
|
||||
public class Item : Properties.IItem
|
||||
{
|
||||
|
||||
protected readonly bool? _Abandoned;
|
||||
protected readonly bool? _Changed;
|
||||
protected List<Closest> _Closest;
|
||||
protected List<Face> _Faces;
|
||||
protected readonly FileHolder? _ImageFileHolder;
|
||||
protected bool? _Moved;
|
||||
protected List<Named> _Named;
|
||||
protected readonly bool? _NoJson;
|
||||
protected Property? _Property;
|
||||
protected readonly string _RelativePath;
|
||||
protected FileHolder? _ResizedFileHolder;
|
||||
protected readonly string _SourceDirectoryFile;
|
||||
protected bool _ValidImageFormatExtension;
|
||||
public bool? Abandoned => _Abandoned;
|
||||
public bool? Changed => _Changed;
|
||||
public List<Closest> Closest => _Closest;
|
||||
public List<Face> Faces => _Faces;
|
||||
public FileHolder? ImageFileHolder => _ImageFileHolder;
|
||||
public bool? Moved => _Moved;
|
||||
public bool? NoJson => _NoJson;
|
||||
public List<Named> Named => _Named;
|
||||
public Property? Property => _Property;
|
||||
public string RelativePath => _RelativePath;
|
||||
public FileHolder? ResizedFileHolder => _ResizedFileHolder;
|
||||
public string SourceDirectoryFile => _SourceDirectoryFile;
|
||||
public bool ValidImageFormatExtension => _ValidImageFormatExtension;
|
||||
|
||||
[JsonConstructor]
|
||||
public Item(bool? abandoned, bool? changed, List<Closest> closest, List<Face> faces, FileHolder? imageFileHolder, bool? moved, List<Named> named, bool? noJson, Property? property, string relativePath, FileHolder? resizedFileHolder, string sourceDirectoryFile, bool validImageFormatExtension)
|
||||
{
|
||||
_Abandoned = abandoned;
|
||||
_Changed = changed;
|
||||
_Closest = closest;
|
||||
_Faces = faces;
|
||||
_ImageFileHolder = imageFileHolder;
|
||||
_Moved = moved;
|
||||
_Named = named;
|
||||
_NoJson = noJson;
|
||||
_Property = property;
|
||||
_RelativePath = relativePath;
|
||||
_ResizedFileHolder = resizedFileHolder;
|
||||
_SourceDirectoryFile = sourceDirectoryFile;
|
||||
_ValidImageFormatExtension = validImageFormatExtension;
|
||||
}
|
||||
|
||||
public Item(string sourceDirectoryFile, string relativePath, FileHolder? imageFileInfo, bool isValidImageFormatExtension, Property? property, bool? abandoned, bool? changed)
|
||||
{
|
||||
_Faces = new();
|
||||
_Named = new();
|
||||
_Closest = new();
|
||||
_Changed = changed;
|
||||
_Property = property;
|
||||
_Abandoned = abandoned;
|
||||
_NoJson = abandoned is null;
|
||||
_RelativePath = relativePath;
|
||||
_ImageFileHolder = imageFileInfo;
|
||||
_SourceDirectoryFile = sourceDirectoryFile;
|
||||
_ValidImageFormatExtension = isValidImageFormatExtension;
|
||||
if (relativePath.EndsWith(".json"))
|
||||
throw new ArgumentException("Can not be a *.json file!");
|
||||
if (imageFileInfo is not null && imageFileInfo.ExtensionLowered is ".json")
|
||||
throw new ArgumentException("Can not be a *.json file!");
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
||||
return result;
|
||||
}
|
||||
|
||||
public void SetMoved(bool moved) => _Moved = moved;
|
||||
|
||||
public void SetResizedFileHolder(string filenameExtension, FileHolder fileHolder)
|
||||
{
|
||||
if (fileHolder.ExtensionLowered == filenameExtension)
|
||||
_ResizedFileHolder = fileHolder;
|
||||
else if (fileHolder.ExtensionLowered.Length > 3 && fileHolder.ExtensionLowered[3] == 'e' && fileHolder.ExtensionLowered.Remove(3, 1) == filenameExtension)
|
||||
_ResizedFileHolder = fileHolder;
|
||||
else
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool Any() => (_Abandoned.HasValue && _Abandoned.Value) || (_Changed.HasValue && _Changed.Value) || (_Moved.HasValue && _Moved.Value) || (_NoJson.HasValue && _NoJson.Value);
|
||||
|
||||
public void Update(Property property) => _Property = property;
|
||||
|
||||
}
|
@ -1,10 +1,9 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using View_by_Distance.Shared.Models.Methods;
|
||||
|
||||
namespace View_by_Distance.Shared.Models;
|
||||
|
||||
public class Location : Properties.ILocation, ILocation, IEquatable<Location>
|
||||
public class Location : Properties.ILocation, IEquatable<Location>
|
||||
{
|
||||
|
||||
protected int _Bottom;
|
||||
@ -13,8 +12,8 @@ public class Location : Properties.ILocation, ILocation, IEquatable<Location>
|
||||
protected readonly int? _NormalizedPixelPercentage;
|
||||
protected int _Right;
|
||||
protected int _Top;
|
||||
public int Bottom => _Bottom;
|
||||
public double Confidence => _Confidence;
|
||||
public int Bottom => _Bottom;
|
||||
public int Left => _Left;
|
||||
public int? NormalizedPixelPercentage => _NormalizedPixelPercentage;
|
||||
public int Right => _Right;
|
||||
@ -23,27 +22,22 @@ public class Location : Properties.ILocation, ILocation, IEquatable<Location>
|
||||
[JsonConstructor]
|
||||
public Location(int bottom, double confidence, int left, int? normalizedPixelPercentage, int right, int top)
|
||||
{
|
||||
if (normalizedPixelPercentage < 0)
|
||||
normalizedPixelPercentage = 3;
|
||||
_Confidence = confidence;
|
||||
_Bottom = bottom;
|
||||
_Left = left;
|
||||
_NormalizedPixelPercentage = normalizedPixelPercentage;
|
||||
_Right = right;
|
||||
_Top = top;
|
||||
Check(bottom, left, normalizedPixelPercentage, right, top, zCount: 1);
|
||||
}
|
||||
|
||||
public Location(double confidence, int bottom, int left, int right, int top, int width, int height) :
|
||||
this(bottom, confidence, left, GetNormalizedPixelPercentage(bottom, height, left, right, top, width), right, top)
|
||||
{ }
|
||||
public Location(double confidence, int height, Location location, int width, int zCount) :
|
||||
this(location.Bottom, confidence, location.Left, GetNormalizedPixelPercentage(location.Bottom, height, location.Left, location.Right, location.Top, width, zCount), location.Right, location.Top) =>
|
||||
Check(_Bottom, _Left, _NormalizedPixelPercentage, _Right, _Top, zCount);
|
||||
|
||||
public Location(double confidence, Location location, int width, int height) :
|
||||
this(location.Bottom, confidence, location.Left, GetNormalizedPixelPercentage(location.Bottom, height, location.Left, location.Right, location.Top, width), location.Right, location.Top)
|
||||
{ }
|
||||
|
||||
public Location(int left, int top, int right, int bottom, int width, int height) :
|
||||
this(bottom, -1.0d, left, GetNormalizedPixelPercentage(bottom, height, left, right, top, width), right, top)
|
||||
{ }
|
||||
public Location(int bottom, double confidence, int height, int left, int right, int top, int width, int zCount) :
|
||||
this(bottom, confidence, left, GetNormalizedPixelPercentage(bottom, height, left, right, top, width, zCount), right, top) =>
|
||||
Check(_Bottom, height, _Left, _NormalizedPixelPercentage, _Right, _Top, width, zCount);
|
||||
|
||||
public override bool Equals(object? obj) => Equals(obj as Location);
|
||||
|
||||
@ -53,6 +47,53 @@ public class Location : Properties.ILocation, ILocation, IEquatable<Location>
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void Check(int bottom, int left, int right, int top, int zCount)
|
||||
{
|
||||
if (left < 0)
|
||||
throw new Exception();
|
||||
if (right < 0)
|
||||
throw new Exception();
|
||||
if (right < left)
|
||||
throw new Exception();
|
||||
if (top < 0)
|
||||
throw new Exception();
|
||||
if (bottom < 0)
|
||||
throw new Exception();
|
||||
if (bottom < top)
|
||||
throw new Exception();
|
||||
if (zCount < 0)
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
private static void Check(int bottom, int height, int left, int right, int top, int width, int zCount)
|
||||
{
|
||||
if (bottom > height)
|
||||
throw new Exception();
|
||||
if (left > width)
|
||||
throw new Exception();
|
||||
if (right > width)
|
||||
throw new Exception();
|
||||
if (top > height)
|
||||
throw new Exception();
|
||||
if (zCount < 0)
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
private static void Check(int bottom, int left, int? normalizedPixelPercentage, int right, int top, int zCount)
|
||||
{
|
||||
Check(bottom, left, right, top, zCount);
|
||||
if (normalizedPixelPercentage.HasValue && normalizedPixelPercentage.Value < 0)
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
private static void Check(int bottom, int height, int left, int? normalizedPixelPercentage, int right, int top, int width, int zCount)
|
||||
{
|
||||
Check(bottom, left, right, top, zCount);
|
||||
Check(bottom, height, left, right, top, width, zCount);
|
||||
if (normalizedPixelPercentage.HasValue && normalizedPixelPercentage.Value < 0)
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
int hashCode = -773114317;
|
||||
@ -63,16 +104,21 @@ public class Location : Properties.ILocation, ILocation, IEquatable<Location>
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
public static int GetNormalizedPixelPercentage(int bottom, int height, int left, int right, int top, int width)
|
||||
public static int GetNormalizedPixelPercentage(int bottom, int height, int left, int right, int top, int width, int zCount)
|
||||
{
|
||||
int result;
|
||||
double value;
|
||||
int decimals = 6;
|
||||
int factor = 1000000;
|
||||
double total = width * height;
|
||||
Check(bottom, left, right, top, zCount);
|
||||
double xCenter = left + ((right - left) / 2);
|
||||
double yCenter = top + ((bottom - top) / 2);
|
||||
value = ((yCenter * width) + xCenter) / (width * height);
|
||||
double at = ((yCenter - 1) * width) + xCenter;
|
||||
value = at / total;
|
||||
if (value < 0)
|
||||
value = 3;
|
||||
result = (int)(Math.Round((decimal)value, 4) * Stateless.Methods.ILocation.Factor);
|
||||
result = (int)(Math.Round(value, decimals) * factor);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
8
Shared/Models/Methods/IClosest.cs
Normal file
8
Shared/Models/Methods/IClosest.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace View_by_Distance.Shared.Models.Methods;
|
||||
|
||||
public interface IClosest : Stateless.Methods.IClosest
|
||||
{ // ...
|
||||
|
||||
//
|
||||
|
||||
}
|
8
Shared/Models/Methods/IContainer.cs
Normal file
8
Shared/Models/Methods/IContainer.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace View_by_Distance.Shared.Models.Methods;
|
||||
|
||||
public interface IContainer : Stateless.Methods.IContainer
|
||||
{ // ...
|
||||
|
||||
//
|
||||
|
||||
}
|
8
Shared/Models/Methods/IDistanceHolder.cs
Normal file
8
Shared/Models/Methods/IDistanceHolder.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace View_by_Distance.Shared.Models.Methods;
|
||||
|
||||
public interface IDistanceHolder : Stateless.Methods.IDistanceHolder
|
||||
{ // ...
|
||||
|
||||
//
|
||||
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
namespace View_by_Distance.Shared.Models.Methods;
|
||||
|
||||
public interface IFaceFileSystem : Stateless.Methods.IFaceFileSystem, IFileSystem
|
||||
public interface IFaceFileSystem : Stateless.Methods.IFaceFileSystem
|
||||
{
|
||||
|
||||
string GetSize();
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
namespace View_by_Distance.Shared.Models.Methods;
|
||||
|
||||
public interface IFacePoint
|
||||
public interface IFacePoint : Stateless.Methods.IFacePoint
|
||||
{
|
||||
|
||||
}
|
8
Shared/Models/Methods/IFileHolder.cs
Normal file
8
Shared/Models/Methods/IFileHolder.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace View_by_Distance.Shared.Models.Methods;
|
||||
|
||||
public interface IFileHolder : Stateless.Methods.IFileHolder
|
||||
{ // ...
|
||||
|
||||
//
|
||||
|
||||
}
|
@ -3,6 +3,4 @@ namespace View_by_Distance.Shared.Models.Methods;
|
||||
public interface IFileSystem : Stateless.Methods.IFileSystem
|
||||
{
|
||||
|
||||
string GetDate();
|
||||
|
||||
}
|
8
Shared/Models/Methods/IItem.cs
Normal file
8
Shared/Models/Methods/IItem.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace View_by_Distance.Shared.Models.Methods;
|
||||
|
||||
public interface IItem : Stateless.Methods.IItem
|
||||
{ // ...
|
||||
|
||||
//
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
namespace View_by_Distance.Shared.Models.Methods;
|
||||
|
||||
public interface ILocation
|
||||
public interface ILocation : Stateless.Methods.ILocation
|
||||
{
|
||||
|
||||
}
|
8
Shared/Models/Methods/INamed.cs
Normal file
8
Shared/Models/Methods/INamed.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace View_by_Distance.Shared.Models.Methods;
|
||||
|
||||
public interface INamed : Stateless.Methods.INamed
|
||||
{ // ...
|
||||
|
||||
//
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
namespace View_by_Distance.Shared.Models.Methods;
|
||||
|
||||
public interface IOutputResolution
|
||||
public interface IOutputResolution : Stateless.Methods.IPerson
|
||||
{
|
||||
|
||||
}
|
8
Shared/Models/Methods/IPath.cs
Normal file
8
Shared/Models/Methods/IPath.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace View_by_Distance.Shared.Models.Methods;
|
||||
|
||||
public interface IPath : Stateless.Methods.IPath
|
||||
{ // ...
|
||||
|
||||
//
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
namespace View_by_Distance.Shared.Models.Methods;
|
||||
|
||||
public interface IProperty
|
||||
public interface IProperty : Stateless.Methods.IProperty
|
||||
{
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
namespace View_by_Distance.Shared.Models.Methods;
|
||||
|
||||
public interface IRelativePaths
|
||||
public interface IRelativePaths : Stateless.Methods.IRelativePaths
|
||||
{
|
||||
|
||||
}
|
37
Shared/Models/Named.cs
Normal file
37
Shared/Models/Named.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace View_by_Distance.Shared.Models;
|
||||
|
||||
public class Named : Properties.INamed
|
||||
{
|
||||
|
||||
protected readonly bool? _IsWrongYear;
|
||||
protected readonly DateTime _MinimumDateTime;
|
||||
protected readonly int? _NormalizedPixelPercentage;
|
||||
protected readonly PersonBirthday? _PersonBirthday;
|
||||
public bool? IsWrongYear => _IsWrongYear;
|
||||
public DateTime MinimumDateTime => _MinimumDateTime;
|
||||
public int? NormalizedPixelPercentage => _NormalizedPixelPercentage;
|
||||
public PersonBirthday? PersonBirthday => _PersonBirthday;
|
||||
|
||||
[JsonConstructor]
|
||||
public Named(bool? isWrongYear, DateTime minimumDateTime, int? normalizedPixelPercentage, PersonBirthday? personBirthday)
|
||||
{
|
||||
_IsWrongYear = isWrongYear;
|
||||
_MinimumDateTime = minimumDateTime;
|
||||
_NormalizedPixelPercentage = normalizedPixelPercentage;
|
||||
_PersonBirthday = personBirthday;
|
||||
}
|
||||
|
||||
public Named(bool? isWrongYear, DateTime minimumDateTime, PersonBirthday? personBirthday) :
|
||||
this(isWrongYear, minimumDateTime, null, personBirthday)
|
||||
{ }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -1,10 +1,9 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using View_by_Distance.Shared.Models.Methods;
|
||||
|
||||
namespace View_by_Distance.Shared.Models;
|
||||
|
||||
public class OutputResolution : Properties.IOutputResolution, IOutputResolution
|
||||
public class OutputResolution : Properties.IOutputResolution
|
||||
{
|
||||
|
||||
protected int _Height;
|
||||
|
13
Shared/Models/Properties/IClosest.cs
Normal file
13
Shared/Models/Properties/IClosest.cs
Normal file
@ -0,0 +1,13 @@
|
||||
namespace View_by_Distance.Shared.Models.Properties;
|
||||
|
||||
public interface IClosest
|
||||
{
|
||||
|
||||
public double? Average { get; }
|
||||
public int? NormalizedPixelPercentage { get; }
|
||||
public bool? IsWrongYear { get; }
|
||||
public double? Minimum { get; }
|
||||
public DateTime MinimumDateTime { get; }
|
||||
public PersonBirthday? PersonBirthday { get; }
|
||||
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
// using View_by_Distance.Shared.Models.Methods;
|
||||
|
||||
// namespace View_by_Distance.Shared.Models.Properties;
|
||||
|
||||
// public interface IConfiguration
|
||||
// {
|
||||
|
||||
// public bool? checkJsonForDistanceResults;
|
||||
// public string[] loadOrCreateThenSaveDistanceResultsForOutputResolutions;
|
||||
// public string[] loadOrCreateThenSaveImageFacesResultsForOutputResolutions;
|
||||
// public bool? loadOrCreateThenSaveIndex;
|
||||
// public bool? overrideForFaceImages;
|
||||
// public bool? overrideForFaceLandmarkImages;
|
||||
// public bool? overrideForResizeImages;
|
||||
// public bool? propertiesChangedForDistance;
|
||||
// public bool? propertiesChangedForFaces;
|
||||
// public bool? propertiesChangedForIndex;
|
||||
// public bool? propertiesChangedForMetadata;
|
||||
// public bool? propertiesChangedForProperty;
|
||||
// public bool? propertiesChangedForResize;
|
||||
// public bool? reverse;
|
||||
// public bool? saveFullYearOfRandomFiles;
|
||||
// public bool? testDistanceResults;
|
||||
// public int? distanceFactor;
|
||||
// public int? locationConfidenceFactor;
|
||||
// public int? mappedMaxIndex;
|
||||
// public int? maxImagesInDirectoryForTopLevelFirstPass;
|
||||
// public int? maxItemsInDistanceCollection;
|
||||
// public int? numberOfJitters;
|
||||
// public int? outputQuality;
|
||||
// public int? paddingLoops;
|
||||
// public string dateGroup;
|
||||
// public string modelDirectory;
|
||||
// public string modelName;
|
||||
// public string outputExtension;
|
||||
// public string predictorModelName;
|
||||
// public string rootDirectory;
|
||||
// public string[] ignoreExtensions;
|
||||
// public string[] ignoreRelativePaths;
|
||||
// public string[] mixedYearRelativePaths;
|
||||
// public string[] outputResolutions;
|
||||
// public string[] saveFaceLandmarkForOutputResolutions;
|
||||
// public string[] validResolutions;
|
||||
|
||||
// }
|
11
Shared/Models/Properties/IContainer.cs
Normal file
11
Shared/Models/Properties/IContainer.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace View_by_Distance.Shared.Models.Properties;
|
||||
|
||||
public interface IContainer
|
||||
{
|
||||
|
||||
public int G { get; }
|
||||
public List<Item> Items { get; }
|
||||
public int R { get; }
|
||||
public string SourceDirectory { get; }
|
||||
|
||||
}
|
@ -3,10 +3,4 @@ namespace View_by_Distance.Shared.Models.Properties;
|
||||
public interface IDirectoryFileSystem
|
||||
{
|
||||
|
||||
// protected new string ClassName { get; }
|
||||
// protected new string DataDisplayFileName { get; }
|
||||
// protected new string DataFullFileName { get; }
|
||||
// protected new string Display { get; }
|
||||
// protected new DateTime LastModified { get; }
|
||||
|
||||
}
|
14
Shared/Models/Properties/IDistanceHolder.cs
Normal file
14
Shared/Models/Properties/IDistanceHolder.cs
Normal file
@ -0,0 +1,14 @@
|
||||
namespace View_by_Distance.Shared.Models.Properties;
|
||||
|
||||
public interface IDistanceHolder
|
||||
{
|
||||
|
||||
public Face Face { init; get; }
|
||||
public FileHolder FileHolder { init; get; }
|
||||
public int Id { init; get; }
|
||||
public string JSONDirectory { init; get; }
|
||||
public Location? Location { init; get; }
|
||||
public string TSVDirectory { init; get; }
|
||||
public double Sort { get; set; }
|
||||
|
||||
}
|
@ -3,16 +3,12 @@ namespace View_by_Distance.Shared.Models.Properties;
|
||||
public interface IFace
|
||||
{
|
||||
|
||||
#pragma warning disable IDE1006
|
||||
public double? α { get; }
|
||||
#pragma warning restore IDE1006
|
||||
public DateTime DateTime { get; }
|
||||
public FaceEncoding FaceEncoding { get; }
|
||||
public Dictionary<string, FacePoint[]> FaceLandmarks { get; }
|
||||
public Location Location { get; }
|
||||
public FaceEncoding? FaceEncoding { get; }
|
||||
public Dictionary<Stateless.FacePart, FacePoint[]>? FaceParts { get; }
|
||||
public Location? Location { get; }
|
||||
public int? LocationIndex { get; }
|
||||
public OutputResolution OutputResolution { get; }
|
||||
public bool Populated { get; }
|
||||
public OutputResolution? OutputResolution { get; }
|
||||
public string RelativePath { get; }
|
||||
|
||||
}
|
16
Shared/Models/Properties/IFileHolder.cs
Normal file
16
Shared/Models/Properties/IFileHolder.cs
Normal file
@ -0,0 +1,16 @@
|
||||
namespace View_by_Distance.Shared.Models.Properties;
|
||||
|
||||
public interface IFileHolder
|
||||
{
|
||||
|
||||
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 long? Length { get; }
|
||||
public string Name { get; }
|
||||
public string NameWithoutExtension { get; }
|
||||
|
||||
}
|
20
Shared/Models/Properties/IItem.cs
Normal file
20
Shared/Models/Properties/IItem.cs
Normal file
@ -0,0 +1,20 @@
|
||||
namespace View_by_Distance.Shared.Models.Properties;
|
||||
|
||||
public interface IItem
|
||||
{
|
||||
|
||||
public bool? Abandoned { get; }
|
||||
public bool? Changed { get; }
|
||||
public List<Closest> Closest { get; }
|
||||
public List<Face> Faces { get; }
|
||||
public FileHolder? ImageFileHolder { get; }
|
||||
public bool? Moved { get; }
|
||||
public bool? NoJson { get; }
|
||||
public List<Named> Named { get; }
|
||||
public Property? Property { get; }
|
||||
public string RelativePath { get; }
|
||||
public FileHolder? ResizedFileHolder { get; }
|
||||
public string SourceDirectoryFile { get; }
|
||||
public bool ValidImageFormatExtension { get; }
|
||||
|
||||
}
|
11
Shared/Models/Properties/INamed.cs
Normal file
11
Shared/Models/Properties/INamed.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace View_by_Distance.Shared.Models.Properties;
|
||||
|
||||
public interface INamed
|
||||
{
|
||||
|
||||
public bool? IsWrongYear { get; }
|
||||
public DateTime MinimumDateTime { get; }
|
||||
public int? NormalizedPixelPercentage { get; }
|
||||
public PersonBirthday? PersonBirthday { get; }
|
||||
|
||||
}
|
6
Shared/Models/Properties/IPath.cs
Normal file
6
Shared/Models/Properties/IPath.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace View_by_Distance.Shared.Models.Properties;
|
||||
|
||||
public interface IPath
|
||||
{
|
||||
|
||||
}
|
@ -6,61 +6,52 @@ namespace View_by_Distance.Shared.Models;
|
||||
public class Property : Properties.IProperty
|
||||
{
|
||||
|
||||
protected bool? _WrongYear;
|
||||
protected DateTime _CreationTime;
|
||||
protected DateTime _LastWriteTime;
|
||||
protected DateTime? _DateTime;
|
||||
protected DateTime? _DateTimeDigitized;
|
||||
protected DateTime? _DateTimeOriginal;
|
||||
protected long _FileSize;
|
||||
protected DateTime? _GPSDateStamp;
|
||||
protected int? _Height;
|
||||
protected int? _Id;
|
||||
protected int[] _Indices;
|
||||
protected int? _Height;
|
||||
protected int? _Width;
|
||||
protected DateTime _LastWriteTime;
|
||||
protected string _Make;
|
||||
protected int? _MetadataGroups;
|
||||
protected string _Model;
|
||||
protected string _Orientation;
|
||||
protected string _UniqueImageId;
|
||||
public bool? WrongYear => _WrongYear;
|
||||
protected int? _Width;
|
||||
public DateTime CreationTime => _CreationTime;
|
||||
public DateTime LastWriteTime => _LastWriteTime;
|
||||
public DateTime? DateTime => _DateTime;
|
||||
public DateTime? DateTimeDigitized => _DateTimeDigitized;
|
||||
public DateTime? DateTimeOriginal => _DateTimeOriginal;
|
||||
public long FileSize => _FileSize;
|
||||
public DateTime? GPSDateStamp => _GPSDateStamp;
|
||||
public int? Height => _Height;
|
||||
public int? Id => _Id;
|
||||
public int[] Indices => _Indices;
|
||||
public int? Height => _Height;
|
||||
public int? Width => _Width;
|
||||
public DateTime LastWriteTime => _LastWriteTime;
|
||||
public string Make => _Make;
|
||||
public int? MetadataGroups => _MetadataGroups;
|
||||
public string Model => _Model;
|
||||
public string Orientation => _Orientation;
|
||||
public string UniqueImageId => _UniqueImageId;
|
||||
public int? Width => _Width;
|
||||
|
||||
[JsonConstructor]
|
||||
public Property(bool? wrongYear, DateTime creationTime, DateTime lastWriteTime, DateTime? dateTime, DateTime? dateTimeDigitized, DateTime? dateTimeOriginal, DateTime? gpsDateStamp, long fileSize, int? id, int[] indices, int? height, int? width, string make, int? metadataGroups, string model, string orientation, string uniqueImageId)
|
||||
public Property(DateTime creationTime, DateTime? dateTime, DateTime? dateTimeDigitized, DateTime? dateTimeOriginal, long fileSize, DateTime? gpsDateStamp, int? height, int? id, int[] indices, DateTime lastWriteTime, string make, string model, string orientation, int? width)
|
||||
{
|
||||
_CreationTime = creationTime;
|
||||
_DateTime = dateTime;
|
||||
_DateTimeDigitized = dateTimeDigitized;
|
||||
_DateTimeOriginal = dateTimeOriginal;
|
||||
_GPSDateStamp = gpsDateStamp;
|
||||
_FileSize = fileSize;
|
||||
_GPSDateStamp = gpsDateStamp;
|
||||
_Height = height;
|
||||
_Id = id;
|
||||
_Indices = indices;
|
||||
_LastWriteTime = lastWriteTime;
|
||||
_Make = make;
|
||||
_MetadataGroups = metadataGroups;
|
||||
_Model = model;
|
||||
_Orientation = orientation;
|
||||
_Width = width;
|
||||
_WrongYear = wrongYear;
|
||||
_UniqueImageId = uniqueImageId;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
@ -69,4 +60,38 @@ public class Property : Properties.IProperty
|
||||
return result;
|
||||
} // ...
|
||||
|
||||
public List<DateTime> GetDateTimes() => Stateless.Methods.Property.GetDateTimes(_CreationTime, _LastWriteTime, _DateTime, _DateTimeDigitized, _DateTimeOriginal, _GPSDateStamp);
|
||||
|
||||
public (bool?, string[]) IsWrongYear(string filteredSourceDirectoryFile, DateTime? minimumDateTime)
|
||||
{
|
||||
string[] results = Array.Empty<string>();
|
||||
bool? result = null;
|
||||
string year;
|
||||
string directoryName;
|
||||
string[] directorySegments;
|
||||
string? check = Path.GetFullPath(filteredSourceDirectoryFile);
|
||||
string? pathRoot = Path.GetPathRoot(filteredSourceDirectoryFile);
|
||||
if (string.IsNullOrEmpty(pathRoot))
|
||||
throw new Exception();
|
||||
if (minimumDateTime.HasValue)
|
||||
year = minimumDateTime.Value.ToString("yyyy");
|
||||
else
|
||||
{
|
||||
List<DateTime> dateTimes = GetDateTimes();
|
||||
year = dateTimes.Min().ToString("yyyy");
|
||||
}
|
||||
for (int i = 0; i < int.MaxValue; i++)
|
||||
{
|
||||
check = Path.GetDirectoryName(check);
|
||||
if (string.IsNullOrEmpty(check) || check == pathRoot)
|
||||
break;
|
||||
directoryName = Path.GetFileName(check);
|
||||
directorySegments = directoryName.Split(' ');
|
||||
(result, results) = Stateless.Methods.Property.IsWrongYear(directorySegments, year);
|
||||
if (result.HasValue)
|
||||
break;
|
||||
}
|
||||
return new(result, results);
|
||||
}
|
||||
|
||||
}
|
@ -1,10 +1,9 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using View_by_Distance.Shared.Models.Methods;
|
||||
|
||||
namespace View_by_Distance.Shared.Models;
|
||||
|
||||
public class RelativePaths : Properties.IRelativePaths, IRelativePaths
|
||||
public class RelativePaths : Properties.IRelativePaths
|
||||
{
|
||||
|
||||
protected string _Value;
|
||||
|
8
Shared/Models/Stateless/Methods/Closest.cs
Normal file
8
Shared/Models/Stateless/Methods/Closest.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class Closest
|
||||
{
|
||||
|
||||
internal static Models.Closest[] Get(List<Models.Closest> collection) => (from l in collection orderby l.Minimum < IClosest.MinimumMinimum, l.Average select l).ToArray();
|
||||
|
||||
}
|
8
Shared/Models/Stateless/Methods/Container.cs
Normal file
8
Shared/Models/Stateless/Methods/Container.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class Container
|
||||
{
|
||||
|
||||
internal static double GetDefaultValue() => throw new Exception();
|
||||
|
||||
}
|
8
Shared/Models/Stateless/Methods/DistanceHolder.cs
Normal file
8
Shared/Models/Stateless/Methods/DistanceHolder.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class DistanceHolder
|
||||
{
|
||||
|
||||
internal static double GetDefaultValue() => throw new Exception();
|
||||
|
||||
}
|
@ -89,11 +89,40 @@ internal abstract class Face
|
||||
a = y2 - y1;
|
||||
double c = Math.Sqrt(Math.Pow(a, 2) + Math.Pow(b, 2));
|
||||
if (y1 < y2)
|
||||
result = (180 / Math.PI) * Math.Asin(a / c);
|
||||
result = 180 / Math.PI * Math.Asin(a / c);
|
||||
else
|
||||
result = (180 / Math.PI) * Math.Asin(a / c) * -1;
|
||||
result = 180 / Math.PI * Math.Asin(a / c) * -1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static double? Getα(Dictionary<FacePart, Models.FacePoint[]> faceParts)
|
||||
{
|
||||
double? result;
|
||||
int? leftEyeX = null;
|
||||
int? leftEyeY = null;
|
||||
int? rightEyeX = null;
|
||||
int? rightEyeY = null;
|
||||
foreach ((FacePart facePart, Models.FacePoint[] facePoints) in faceParts)
|
||||
{
|
||||
if (facePart is not FacePart.LeftEye and not FacePart.RightEye)
|
||||
continue;
|
||||
if (facePart is FacePart.LeftEye)
|
||||
{
|
||||
leftEyeX = (int)(from l in facePoints select l.X).Average();
|
||||
leftEyeY = (int)(from l in facePoints select l.Y).Average();
|
||||
}
|
||||
if (facePart is FacePart.RightEye)
|
||||
{
|
||||
rightEyeX = (int)(from l in facePoints select l.X).Average();
|
||||
rightEyeY = (int)(from l in facePoints select l.Y).Average();
|
||||
}
|
||||
}
|
||||
if (rightEyeX is null || leftEyeX is null || rightEyeY is null || leftEyeY is null)
|
||||
result = null;
|
||||
else
|
||||
result = Getα(rightEyeX.Value, leftEyeX.Value, rightEyeY.Value, leftEyeY.Value);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
8
Shared/Models/Stateless/Methods/FacePoint.cs
Normal file
8
Shared/Models/Stateless/Methods/FacePoint.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class FacePoint
|
||||
{
|
||||
|
||||
internal static double GetDefaultValue() => throw new Exception();
|
||||
|
||||
}
|
8
Shared/Models/Stateless/Methods/FileHolder.cs
Normal file
8
Shared/Models/Stateless/Methods/FileHolder.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class FileHolder
|
||||
{
|
||||
|
||||
internal static double GetDefaultValue() => throw new Exception();
|
||||
|
||||
}
|
@ -3,38 +3,54 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
internal abstract class FileSystem
|
||||
{ // ...
|
||||
|
||||
private static void SetFileSystemCollection(string requestPath, (string RootResultsDirectoryAbsoluteUri, string C_ResizeContentDirectory, string D_FacesContentDirectory, string E_DistanceCollectionDirectory) tuple, bool all, List<Models.FileSystem> results, IEnumerator<string> subDirectoryFiles, List<Models.FaceFileSystem> faceFileSystemCollection)
|
||||
{
|
||||
Models.Face face;
|
||||
Models.FaceFileSystem faceFileSystem;
|
||||
face = Face.GetFace(subDirectoryFiles.Current);
|
||||
faceFileSystem = new Models.FaceFileSystem(requestPath, tuple.RootResultsDirectoryAbsoluteUri.Length, tuple.C_ResizeContentDirectory, tuple.D_FacesContentDirectory, subDirectoryFiles.Current, face);
|
||||
if (!all)
|
||||
results.Add(faceFileSystem);
|
||||
else
|
||||
faceFileSystemCollection.Add(faceFileSystem);
|
||||
}
|
||||
|
||||
private static void LoopFileSystemCollection(string requestPath, (string RootResultsDirectoryAbsoluteUri, string C_ResizeContentDirectory, string D_FacesContentDirectory, string E_DistanceCollectionDirectory) tuple, bool all, List<Models.FileSystem> results, IEnumerator<string> subDirectoryFiles, List<Models.FaceFileSystem> faceFileSystemCollection)
|
||||
{
|
||||
for (int j = 0; j < int.MaxValue; j++)
|
||||
{
|
||||
SetFileSystemCollection(requestPath, tuple, all, results, subDirectoryFiles, faceFileSystemCollection);
|
||||
if (!all || !subDirectoryFiles.MoveNext())
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetFileSystemCollection(string[] directories, List<Models.FileSystem> results, int i)
|
||||
{
|
||||
DirectoryInfo directoryInfo = new(directories[i]);
|
||||
Models.FileSystem fileSystem = new DirectoryFileSystem(directoryInfo);
|
||||
results.Add(fileSystem);
|
||||
}
|
||||
|
||||
private static void LoopFileSystemCollection(string requestPath, (string RootResultsDirectoryAbsoluteUri, string C_ResizeContentDirectory, string D_FacesContentDirectory, string E_DistanceCollectionDirectory) tuple, string[] directories, bool all, List<Models.FileSystem> results, IEnumerator<string> subDirectoryFiles, List<Models.FaceFileSystem> faceFileSystemCollection, int i)
|
||||
{
|
||||
if (subDirectoryFiles.MoveNext())
|
||||
LoopFileSystemCollection(requestPath, tuple, all, results, subDirectoryFiles, faceFileSystemCollection);
|
||||
else
|
||||
SetFileSystemCollection(directories, results, i);
|
||||
}
|
||||
|
||||
internal static List<Models.FileSystem> GetFileSystemCollection(string requestPath, (string RootResultsDirectoryAbsoluteUri, string C_ResizeContentDirectory, string D_FacesContentDirectory, string E_DistanceCollectionDirectory) tuple, string[] directories, string[] files, bool all)
|
||||
{
|
||||
List<Models.FileSystem> results = new();
|
||||
Models.Face face;
|
||||
DirectoryInfo directoryInfo;
|
||||
Models.FileSystem fileSystem;
|
||||
Models.FaceFileSystem faceFileSystem;
|
||||
IEnumerator<string> subDirectoryFiles;
|
||||
List<Models.FaceFileSystem> faceFileSystemCollection = new();
|
||||
for (int i = 0; i < directories.Length; i++)
|
||||
{
|
||||
subDirectoryFiles = Directory.EnumerateFiles(directories[i], "*.json", SearchOption.TopDirectoryOnly).GetEnumerator();
|
||||
if (!subDirectoryFiles.MoveNext())
|
||||
{
|
||||
directoryInfo = new(directories[i]);
|
||||
fileSystem = new DirectoryFileSystem(directoryInfo);
|
||||
results.Add(fileSystem);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int j = 0; j < int.MaxValue; j++)
|
||||
{
|
||||
face = Face.GetFace(subDirectoryFiles.Current);
|
||||
faceFileSystem = new Models.FaceFileSystem(requestPath, tuple.RootResultsDirectoryAbsoluteUri.Length, tuple.C_ResizeContentDirectory, tuple.D_FacesContentDirectory, subDirectoryFiles.Current, face);
|
||||
if (!all)
|
||||
results.Add(faceFileSystem);
|
||||
else
|
||||
faceFileSystemCollection.Add(faceFileSystem);
|
||||
if (!all || !subDirectoryFiles.MoveNext())
|
||||
break;
|
||||
}
|
||||
}
|
||||
LoopFileSystemCollection(requestPath, tuple, directories, all, results, subDirectoryFiles, faceFileSystemCollection, i);
|
||||
}
|
||||
for (int i = 0; i < files.Length; i++)
|
||||
{
|
||||
|
15
Shared/Models/Stateless/Methods/IClosest.cs
Normal file
15
Shared/Models/Stateless/Methods/IClosest.cs
Normal file
@ -0,0 +1,15 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IClosest
|
||||
{ // ...
|
||||
|
||||
const int MaximumPer = 50;
|
||||
const float MaximumMinimum = 0.50f;
|
||||
const bool SkipIsWrongYear = true;
|
||||
const float MinimumMinimum = 0.05f;
|
||||
|
||||
Models.Closest[] TestStatic_Get(List<Models.Closest> collection);
|
||||
|
||||
static Models.Closest[] Get(List<Models.Closest> collection) => Closest.Get(collection);
|
||||
|
||||
}
|
10
Shared/Models/Stateless/Methods/IContainer.cs
Normal file
10
Shared/Models/Stateless/Methods/IContainer.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IContainer
|
||||
{ // ...
|
||||
|
||||
double TestStatic_GetDefaultValue();
|
||||
|
||||
static double GetDefaultValue() => Container.GetDefaultValue();
|
||||
|
||||
}
|
10
Shared/Models/Stateless/Methods/IDistanceHolder.cs
Normal file
10
Shared/Models/Stateless/Methods/IDistanceHolder.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IDistanceHolder
|
||||
{ // ...
|
||||
|
||||
double TestStatic_GetDefaultValue();
|
||||
|
||||
static double GetDefaultValue() => DistanceHolder.GetDefaultValue();
|
||||
|
||||
}
|
@ -3,14 +3,22 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
public interface IFace
|
||||
{ // ...
|
||||
|
||||
double TestStatic_Getα(int x1, int x2, int y1, int y2);
|
||||
string TestStatic_GetJson(string jsonFileFullName);
|
||||
Models.Face TestStatic_GetFace(string jsonFileFullName);
|
||||
Models.Face[] TestStatic_GetFaces(string jsonFileFullName);
|
||||
|
||||
static double Getα(int x1, int x2, int y1, int y2) => Face.Getα(x1, x2, y1, y2);
|
||||
static string GetJson(string jsonFileFullName) => Face.GetJson(jsonFileFullName);
|
||||
|
||||
double TestStatic_Getα(int x1, int x2, int y1, int y2);
|
||||
static double Getα(int x1, int x2, int y1, int y2) => Face.Getα(x1, x2, y1, y2);
|
||||
|
||||
Models.Face TestStatic_GetFace(string jsonFileFullName);
|
||||
static Models.Face GetFace(string jsonFileFullName) => Face.GetFace(jsonFileFullName);
|
||||
|
||||
Models.Face[] TestStatic_GetFaces(string jsonFileFullName);
|
||||
static Models.Face[] GetFaces(string jsonFileFullName) => Face.GetFaces(jsonFileFullName);
|
||||
|
||||
Models.Face[] TestStatic_Getα(Dictionary<FacePart, Models.FacePoint[]> faceParts);
|
||||
static double? Getα(Dictionary<FacePart, Models.FacePoint[]> faceParts) => Face.Getα(faceParts);
|
||||
|
||||
int?[] TestStatic_GetInts(List<Models.Face> faces);
|
||||
static int?[] GetInts(List<Models.Face> faces) => (from l in faces where l.FaceEncoding is not null && l.Location?.NormalizedPixelPercentage is not null select l.Location?.NormalizedPixelPercentage).ToArray();
|
||||
|
||||
}
|
10
Shared/Models/Stateless/Methods/IFacePoint.cs
Normal file
10
Shared/Models/Stateless/Methods/IFacePoint.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IFacePoint
|
||||
{ // ...
|
||||
|
||||
double TestStatic_GetDefaultValue();
|
||||
|
||||
static double GetDefaultValue() => FacePoint.GetDefaultValue();
|
||||
|
||||
}
|
9
Shared/Models/Stateless/Methods/IFileHolder.cs
Normal file
9
Shared/Models/Stateless/Methods/IFileHolder.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IFileHolder
|
||||
{ // ...
|
||||
|
||||
Models.FileHolder TestStatic_Refresh();
|
||||
static Models.FileHolder Refresh(Models.FileHolder fileHolder) => new(fileHolder.FullName);
|
||||
|
||||
}
|
9
Shared/Models/Stateless/Methods/IItem.cs
Normal file
9
Shared/Models/Stateless/Methods/IItem.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IItem
|
||||
{ // ...
|
||||
|
||||
string TestStatic_GetWrongYearFlag(bool? isWrongYear);
|
||||
static string GetWrongYearFlag(bool? isWrongYear) => isWrongYear is null ? "#" : isWrongYear.Value ? "~" : "=";
|
||||
|
||||
}
|
@ -3,6 +3,11 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
public interface ILocation
|
||||
{ // ...
|
||||
|
||||
public const int Factor = 10000;
|
||||
Models.Location? TestStatic_GetLocation(Models.Location? location, int height, int width, int 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);
|
||||
|
||||
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();
|
||||
|
||||
}
|
22
Shared/Models/Stateless/Methods/INamed.cs
Normal file
22
Shared/Models/Stateless/Methods/INamed.cs
Normal file
@ -0,0 +1,22 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface INamed
|
||||
{ // ...
|
||||
|
||||
double? TestStatic_GetReversedDeterministicHashCode(string fileName);
|
||||
static double? GetReversedDeterministicHashCode(string fileName) =>
|
||||
Named.GetReversedDeterministicHashCode(fileName);
|
||||
|
||||
double TestStatic_GetDeterministicHashCodeKey(Models.Item item, Models.Face face);
|
||||
static double GetDeterministicHashCodeKey(Models.Item item, Models.Face face) =>
|
||||
Named.GetDeterministicHashCodeKey(item, face);
|
||||
|
||||
double TestStatic_GetDeterministicHashCodeKey(Models.Item item, Models.Closest closest);
|
||||
static double GetDeterministicHashCodeKey(Models.Item item, Models.Closest closest) =>
|
||||
Named.GetDeterministicHashCodeKey(item, closest);
|
||||
|
||||
(string?, double?) TestStatic_GetReversedDeterministicHashCode(Dictionary<int, List<Models.Face>> keyValuePairs, string file);
|
||||
static (string?, double?) GetReversedDeterministicHashCode(Dictionary<int, List<Models.Face>> keyValuePairs, string file) =>
|
||||
Named.GetReversedDeterministicHashCode(keyValuePairs, file);
|
||||
|
||||
}
|
30
Shared/Models/Stateless/Methods/IPath.cs
Normal file
30
Shared/Models/Stateless/Methods/IPath.cs
Normal file
@ -0,0 +1,30 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IPath
|
||||
{ // ...
|
||||
|
||||
string TestStatic_GetRelativePath(string path, int length);
|
||||
static string GetRelativePath(string path, int length)
|
||||
=> XPath.GetRelativePath(path, length);
|
||||
|
||||
bool TestStatic_DeleteEmptyDirectories(string rootDirectory);
|
||||
static bool DeleteEmptyDirectories(string rootDirectory)
|
||||
=> XPath.DeleteEmptyDirectories(rootDirectory);
|
||||
|
||||
List<string> TestStatic_GetDirectoryNames(string directory);
|
||||
static List<string> GetDirectoryNames(string directory)
|
||||
=> XPath.GetDirectoryNames(directory);
|
||||
|
||||
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);
|
||||
|
||||
(int level, List<string> directories) TestStatic_Get(string rootDirectory, string sourceDirectory);
|
||||
static (int level, List<string> directories) Get(string rootDirectory, string sourceDirectory)
|
||||
=> XPath.Get(rootDirectory, sourceDirectory);
|
||||
|
||||
string TestStatic_GetDirectory(string sourceDirectory, int level, string directoryName);
|
||||
static string GetDirectory(string sourceDirectory, int level, string directoryName)
|
||||
=> XPath.GetDirectory(sourceDirectory, level, directoryName);
|
||||
|
||||
}
|
65
Shared/Models/Stateless/Methods/IProperty.cs
Normal file
65
Shared/Models/Stateless/Methods/IProperty.cs
Normal file
@ -0,0 +1,65 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IProperty
|
||||
{ // ...
|
||||
|
||||
string TestStatic_DateTimeFormat();
|
||||
static string DateTimeFormat() => "yyyy:MM:dd HH:mm:ss";
|
||||
|
||||
int TestStatic_GetDeterministicHashCode(byte[] value);
|
||||
static int GetDeterministicHashCode(byte[] value) =>
|
||||
Property.GetDeterministicHashCode(value);
|
||||
|
||||
int TestStatic_GetDeterministicHashCode(string value);
|
||||
static int GetDeterministicHashCode(string value) =>
|
||||
Property.GetDeterministicHashCode(value);
|
||||
|
||||
DateTime TestStatic_GetDateTime(Models.Property? property);
|
||||
static DateTime GetDateTime(Models.Property? property) =>
|
||||
Property.GetDateTime(property);
|
||||
|
||||
DateTime TestStatic_GetMinimumDateTime(Models.Property? property);
|
||||
static DateTime GetMinimumDateTime(Models.Property? property) =>
|
||||
Property.GetMinimumDateTime(property);
|
||||
|
||||
(int Season, string seasonName) TestStatic_GetSeason(int dayOfYear);
|
||||
static (int Season, string seasonName) GetSeason(int dayOfYear) =>
|
||||
Property.GetSeason(dayOfYear);
|
||||
|
||||
string TestStatic_GetDiffRootDirectory(string diffPropertyDirectory);
|
||||
static string GetDiffRootDirectory(string diffPropertyDirectory) =>
|
||||
Property.GetDiffRootDirectory(diffPropertyDirectory);
|
||||
|
||||
bool TestStatic_Any(List<Models.Container> propertyHolderCollections);
|
||||
static bool Any(List<Models.Container> propertyHolderCollections) =>
|
||||
Property.Any(propertyHolderCollections);
|
||||
|
||||
(bool?, string[]) TestStatic_IsWrongYear(string[] segments, string year);
|
||||
static (bool?, string[]) IsWrongYear(string[] segments, string year) =>
|
||||
Property.IsWrongYear(segments, year);
|
||||
|
||||
(bool?, string[]) TestStatic_IsWrongYear(string fileName, DateTime minimumDateTime);
|
||||
static (bool?, string[]) IsWrongYear(string fileName, DateTime minimumDateTime) =>
|
||||
throw new NotImplementedException(); //Property.IsWrongYear(fileName, minimumDateTime);
|
||||
|
||||
List<DateTime> TestStatic_GetDateTimes(Models.Property property);
|
||||
static List<DateTime> GetDateTimes(Models.Property property) =>
|
||||
Property.GetDateTimes(property.CreationTime, property.LastWriteTime, property.DateTime, property.DateTimeDigitized, property.DateTimeOriginal, property.GPSDateStamp);
|
||||
|
||||
double TestStatic_GetStandardDeviation(IEnumerable<long> values, double average);
|
||||
static double GetStandardDeviation(IEnumerable<long> values, double average) =>
|
||||
Property.GetStandardDeviation(values, average);
|
||||
|
||||
TimeSpan TestStatic_GetThreeStandardDeviationHigh(int minimum, Models.Container container);
|
||||
static TimeSpan GetThreeStandardDeviationHigh(int minimum, Models.Container container) =>
|
||||
Property.GetThreeStandardDeviationHigh(minimum, container);
|
||||
|
||||
(int, List<DateTime>, List<Models.Item>) TestStatic_Get(Models.Container container, TimeSpan threeStandardDeviationHigh, int i);
|
||||
static (int, List<DateTime>, List<Models.Item>) Get(Models.Container container, TimeSpan threeStandardDeviationHigh, int i) =>
|
||||
Property.Get(container, threeStandardDeviationHigh, i);
|
||||
|
||||
List<DateTime> TestStatic_GetDateTimes(DateTime creationTime, DateTime lastWriteTime, DateTime? dateTime, DateTime? dateTimeDigitized, DateTime? dateTimeOriginal, DateTime? gpsDateStamp);
|
||||
static List<DateTime> GetDateTimes(DateTime creationTime, DateTime lastWriteTime, DateTime? dateTime, DateTime? dateTimeDigitized, DateTime? dateTimeOriginal, DateTime? gpsDateStamp) =>
|
||||
Property.GetDateTimes(creationTime, lastWriteTime, dateTime, dateTimeDigitized, dateTimeOriginal, gpsDateStamp);
|
||||
|
||||
}
|
10
Shared/Models/Stateless/Methods/IRelativePaths.cs
Normal file
10
Shared/Models/Stateless/Methods/IRelativePaths.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IRelativePaths
|
||||
{ // ...
|
||||
|
||||
double TestStatic_GetDefaultValue();
|
||||
|
||||
static double GetDefaultValue() => RelativePaths.GetDefaultValue();
|
||||
|
||||
}
|
@ -78,7 +78,7 @@ internal abstract class ImageHelper
|
||||
/// <param name="path">The path of the image to get the dimensions of.</param>
|
||||
/// <returns>The dimensions of the specified image.</returns>
|
||||
/// <exception cref="ArgumentException">The image was of an unrecognized format.</exception>
|
||||
public static Size GetDimensions(BinaryReader binaryReader, int? faceRight, int? faceBottom)
|
||||
internal static Size GetDimensions(BinaryReader binaryReader, int? faceRight, int? faceBottom)
|
||||
{
|
||||
Size? result = null;
|
||||
Dictionary<byte[], Func<BinaryReader, Size>> _ImageFormatDecoders = new()
|
||||
@ -119,7 +119,7 @@ internal abstract class ImageHelper
|
||||
/// <param name="path">The path of the image to get the dimensions of.</param>
|
||||
/// <returns>The dimensions of the specified image.</returns>
|
||||
/// <exception cref="ArgumentException">The image was of an unrecognized format.</exception>
|
||||
public static Size GetDimensions(string path, int? faceRight, int? faceBottom)
|
||||
internal static Size GetDimensions(string path, int? faceRight, int? faceBottom)
|
||||
{
|
||||
Size result;
|
||||
using BinaryReader binaryReader = new(File.OpenRead(path));
|
||||
|
@ -3,6 +3,26 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
internal abstract class Index
|
||||
{
|
||||
|
||||
private static string GetJsonContains(string result, string jsonFileFullName, FileInfo fileInfo, string fileSegmentCollection)
|
||||
{
|
||||
if (fileInfo is null)
|
||||
fileInfo = new FileInfo(jsonFileFullName);
|
||||
result = result.Replace(fileSegmentCollection, nameof(Properties.IIndex.RelativePaths)).Replace("\\\\", "/");
|
||||
File.WriteAllText(fileInfo.FullName, result);
|
||||
File.SetLastWriteTime(fileInfo.FullName, fileInfo.LastWriteTime);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static string GetJsonSpecial(string result, string jsonFileFullName, FileInfo fileInfo)
|
||||
{
|
||||
if (fileInfo is null)
|
||||
fileInfo = new FileInfo(jsonFileFullName);
|
||||
result = result.Replace("/u0", "\\u0");
|
||||
File.WriteAllText(fileInfo.FullName, result);
|
||||
File.SetLastWriteTime(fileInfo.FullName, fileInfo.LastWriteTime);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static string GetJson(string jsonFileFullName, FileInfo fileInfo)
|
||||
{
|
||||
string result;
|
||||
@ -10,21 +30,9 @@ internal abstract class Index
|
||||
string fileSegmentCollection = "FileSegmentCollection";
|
||||
result = File.ReadAllText(jsonFileFullName).Replace("Goolgle", "Google");
|
||||
if (result.Contains(fileSegment) || result.Contains(fileSegmentCollection))
|
||||
{
|
||||
if (fileInfo is null)
|
||||
fileInfo = new FileInfo(jsonFileFullName);
|
||||
result = result.Replace(fileSegmentCollection, nameof(Properties.IIndex.RelativePaths)).Replace("\\\\", "/");
|
||||
File.WriteAllText(fileInfo.FullName, result);
|
||||
File.SetLastWriteTime(fileInfo.FullName, fileInfo.LastWriteTime);
|
||||
}
|
||||
result = GetJsonContains(result, jsonFileFullName, fileInfo, fileSegmentCollection);
|
||||
if (result.Contains("/u0"))
|
||||
{
|
||||
if (fileInfo is null)
|
||||
fileInfo = new FileInfo(jsonFileFullName);
|
||||
result = result.Replace("/u0", "\\u0");
|
||||
File.WriteAllText(fileInfo.FullName, result);
|
||||
File.SetLastWriteTime(fileInfo.FullName, fileInfo.LastWriteTime);
|
||||
}
|
||||
result = GetJsonSpecial(result, jsonFileFullName, fileInfo);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
8
Shared/Models/Stateless/Methods/Item.cs
Normal file
8
Shared/Models/Stateless/Methods/Item.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class Item
|
||||
{
|
||||
|
||||
internal static double GetDefaultValue() => throw new Exception();
|
||||
|
||||
}
|
6
Shared/Models/Stateless/Methods/Location.cs
Normal file
6
Shared/Models/Stateless/Methods/Location.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class Location
|
||||
{
|
||||
|
||||
}
|
146
Shared/Models/Stateless/Methods/Named.cs
Normal file
146
Shared/Models/Stateless/Methods/Named.cs
Normal file
@ -0,0 +1,146 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class Named
|
||||
{
|
||||
|
||||
private static double GetDeterministicHashCodeFileName(int id, int normalizedPixelPercentage)
|
||||
=> double.Parse($"{id}.{normalizedPixelPercentage}");
|
||||
|
||||
internal static double GetDeterministicHashCodeKey(Models.Item item, Models.Closest closest)
|
||||
{
|
||||
double result;
|
||||
if (item.Property?.Id is null || item.ImageFileHolder is null || closest.NormalizedPixelPercentage is null)
|
||||
throw new NullReferenceException();
|
||||
result = GetDeterministicHashCodeFileName(item.Property.Id.Value, closest.NormalizedPixelPercentage.Value);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static double GetDeterministicHashCodeKey(Models.Item item, Models.Face face)
|
||||
{
|
||||
double result;
|
||||
if (item.Property?.Id is null || item.ImageFileHolder is null || face.Location?.NormalizedPixelPercentage is null)
|
||||
throw new NullReferenceException();
|
||||
result = GetDeterministicHashCodeFileName(item.Property.Id.Value, face.Location.NormalizedPixelPercentage.Value);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static double? GetReversedDeterministicHashCodeB(string fileName)
|
||||
{
|
||||
double? result;
|
||||
string[] segments = fileName.Split('.');
|
||||
if (segments.Length < 2)
|
||||
throw new Exception();
|
||||
string id = segments[0];
|
||||
string normalizedPixelPercentage = segments[1];
|
||||
if (!double.TryParse(string.Concat(id, '.', normalizedPixelPercentage), out double resultValue))
|
||||
result = null;
|
||||
else
|
||||
result = resultValue;
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static double? GetReversedDeterministicHashCode(string fileName)
|
||||
{
|
||||
double? result;
|
||||
if (fileName.Length < 2 || fileName[1..].Contains('-'))
|
||||
result = null;
|
||||
else
|
||||
result = GetReversedDeterministicHashCodeB(fileName);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static (string? check, int? normalizedPixelPercentage) GetReversedDeterministicHashCodeFromFace(string file, int idValue, int locationIndexValue, List<Models.Face> faces)
|
||||
{
|
||||
string? check;
|
||||
int? normalizedPixelPercentage;
|
||||
Models.Face face = faces[locationIndexValue];
|
||||
if (face.Location?.NormalizedPixelPercentage is null)
|
||||
{
|
||||
check = null;
|
||||
normalizedPixelPercentage = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
string extensionLowered = Path.GetExtension(file).ToLower();
|
||||
normalizedPixelPercentage = face.Location.NormalizedPixelPercentage.Value;
|
||||
double deterministicHashCodeKey = GetDeterministicHashCodeFileName(idValue, normalizedPixelPercentage.Value);
|
||||
check = Path.Combine(string.Concat(Path.GetDirectoryName(file)), $"{deterministicHashCodeKey}{extensionLowered}");
|
||||
}
|
||||
return (check, normalizedPixelPercentage);
|
||||
}
|
||||
|
||||
private static (string? check, int? normalizedPixelPercentage) GetReversedDeterministicHashCodeAfterParse(Dictionary<int, List<Models.Face>> keyValuePairs, string file, int idValue, int locationIndexValue)
|
||||
{
|
||||
string? check;
|
||||
int? normalizedPixelPercentage;
|
||||
List<Models.Face> faces = keyValuePairs[idValue];
|
||||
if (faces.Count > locationIndexValue)
|
||||
(check, normalizedPixelPercentage) = GetReversedDeterministicHashCodeFromFace(file, idValue, locationIndexValue, faces);
|
||||
else
|
||||
{
|
||||
check = null;
|
||||
normalizedPixelPercentage = null;
|
||||
}
|
||||
return (check, normalizedPixelPercentage);
|
||||
}
|
||||
|
||||
private static (string? check, string id, int? normalizedPixelPercentage) GetReversedDeterministicHashCodeFromCollection(Dictionary<int, List<Models.Face>> keyValuePairs, string file, string fileName)
|
||||
{
|
||||
string id;
|
||||
string? check;
|
||||
int? normalizedPixelPercentage;
|
||||
string[] segments = fileName.Split(' ');
|
||||
if (segments.Length < 3)
|
||||
throw new Exception();
|
||||
id = segments[2].Split('.')[0];
|
||||
string locationIdex = segments[0];
|
||||
if (int.TryParse(id, out int idValue) && int.TryParse(locationIdex, out int locationIndexValue) && keyValuePairs.ContainsKey(idValue))
|
||||
(check, normalizedPixelPercentage) = GetReversedDeterministicHashCodeAfterParse(keyValuePairs, file, idValue, locationIndexValue);
|
||||
else
|
||||
{
|
||||
check = null;
|
||||
id = string.Empty;
|
||||
normalizedPixelPercentage = null;
|
||||
}
|
||||
if (normalizedPixelPercentage is null)
|
||||
id = string.Empty;
|
||||
return new(check, id, normalizedPixelPercentage);
|
||||
}
|
||||
|
||||
private static (string?, double?) GetReversedDeterministicHashCode(Dictionary<int, List<Models.Face>> keyValuePairs, string file, string fileName)
|
||||
{
|
||||
double? result;
|
||||
string? check;
|
||||
string id;
|
||||
int? normalizedPixelPercentage;
|
||||
if (keyValuePairs.Any())
|
||||
(check, id, normalizedPixelPercentage) = GetReversedDeterministicHashCodeFromCollection(keyValuePairs, file, fileName);
|
||||
else
|
||||
{
|
||||
check = null;
|
||||
id = string.Empty;
|
||||
normalizedPixelPercentage = null;
|
||||
}
|
||||
if (normalizedPixelPercentage is null || !double.TryParse(string.Concat(id, '.', normalizedPixelPercentage.Value), out double resultValue))
|
||||
result = null;
|
||||
else
|
||||
result = resultValue;
|
||||
return new(check, result);
|
||||
}
|
||||
|
||||
internal static (string?, double?) GetReversedDeterministicHashCode(Dictionary<int, List<Models.Face>> keyValuePairs, string file)
|
||||
{
|
||||
double? result;
|
||||
string? check;
|
||||
string fileName = Path.GetFileName(file);
|
||||
if (fileName.Contains('-'))
|
||||
(check, result) = GetReversedDeterministicHashCode(keyValuePairs, file, fileName);
|
||||
else
|
||||
{
|
||||
check = null;
|
||||
result = null;
|
||||
}
|
||||
return new(check, result);
|
||||
}
|
||||
|
||||
}
|
@ -48,12 +48,23 @@ internal abstract class Person
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void SetSegments(ref string[] segments, string KeyFormat, ref DateTime incrementDate)
|
||||
{
|
||||
if (segments[0].Length != KeyFormat.Length || !segments[0].Contains('-') || !segments[0].Contains('_'))
|
||||
{
|
||||
List<string> temporarySegments;
|
||||
temporarySegments = segments.ToList();
|
||||
temporarySegments.Insert(0, incrementDate.ToString(KeyFormat));
|
||||
segments = temporarySegments.ToArray();
|
||||
incrementDate = incrementDate.AddDays(1);
|
||||
}
|
||||
}
|
||||
|
||||
internal static Dictionary<DateTime, string[]> Split(string knownPeopleFile)
|
||||
{
|
||||
Dictionary<DateTime, string[]> results = new();
|
||||
string[] segments;
|
||||
DateTime personKey;
|
||||
List<string> temporarySegments;
|
||||
const string KeyFormat = "yyyy-MM-dd_HH";
|
||||
DateTime incrementDate = new(1500, 1, 1);
|
||||
string[] lines = File.ReadAllLines(knownPeopleFile);
|
||||
@ -66,13 +77,7 @@ internal abstract class Person
|
||||
segments = line.Replace(" //", "\t//").Split('\t');
|
||||
if (segments.Length < 1)
|
||||
continue;
|
||||
if (segments[0].Length != KeyFormat.Length || !segments[0].Contains('-') || !segments[0].Contains('_'))
|
||||
{
|
||||
temporarySegments = segments.ToList();
|
||||
temporarySegments.Insert(0, incrementDate.ToString(KeyFormat));
|
||||
segments = temporarySegments.ToArray();
|
||||
incrementDate = incrementDate.AddDays(1);
|
||||
}
|
||||
SetSegments(ref segments, KeyFormat, ref incrementDate);
|
||||
personKey = DateTime.ParseExact(segments[0], KeyFormat, cultureInfo);
|
||||
if (results.ContainsKey(personKey))
|
||||
continue;
|
||||
@ -88,7 +93,29 @@ internal abstract class Person
|
||||
return results.OrderBy(l => l.Key).ToDictionary(l => l.Key, l => l.Value);
|
||||
}
|
||||
|
||||
internal static Dictionary<DateTime, PersonImport> GetPersonCollection(string knownPeopleFile)
|
||||
private static void SetValues(ref string name, ref string comment, ref string mergeName, KeyValuePair<DateTime, string[]> splitLine)
|
||||
{
|
||||
foreach (string segment in splitLine.Value)
|
||||
{
|
||||
if (!segment.Contains('*'))
|
||||
continue;
|
||||
mergeName = segment.Split('*')[1].Split('\t')[0];
|
||||
}
|
||||
if (splitLine.Value[1].StartsWith("//"))
|
||||
comment = splitLine.Value[1];
|
||||
else
|
||||
name = splitLine.Value[1].Split('\t')[0];
|
||||
if (splitLine.Value.Length > 2)
|
||||
comment = splitLine.Value[2];
|
||||
}
|
||||
|
||||
private static void CheckSplitLineAndSetValues(ref string name, ref string comment, ref string mergeName, KeyValuePair<DateTime, string[]> splitLine)
|
||||
{
|
||||
if (splitLine.Value.Length > 1)
|
||||
SetValues(ref name, ref comment, ref mergeName, splitLine);
|
||||
}
|
||||
|
||||
private static Dictionary<DateTime, PersonImport> GetPersonCollection(string knownPeopleFile)
|
||||
{
|
||||
Dictionary<DateTime, PersonImport> results = new();
|
||||
string name;
|
||||
@ -105,21 +132,7 @@ internal abstract class Person
|
||||
comment = string.Empty;
|
||||
oldName = string.Empty;
|
||||
mergeName = string.Empty;
|
||||
if (splitLine.Value.Length > 1)
|
||||
{
|
||||
foreach (string segment in splitLine.Value)
|
||||
{
|
||||
if (!segment.Contains('*'))
|
||||
continue;
|
||||
mergeName = segment.Split('*')[1].Split('\t')[0];
|
||||
}
|
||||
if (splitLine.Value[1].StartsWith("//"))
|
||||
comment = splitLine.Value[1];
|
||||
else
|
||||
name = splitLine.Value[1].Split('\t')[0];
|
||||
if (splitLine.Value.Length > 2)
|
||||
comment = splitLine.Value[2];
|
||||
}
|
||||
CheckSplitLineAndSetValues(ref name, ref comment, ref mergeName, splitLine);
|
||||
person = new(key, name, mergeName, oldName, comment);
|
||||
results.Add(splitLine.Key, person);
|
||||
}
|
||||
@ -133,6 +146,19 @@ internal abstract class Person
|
||||
_ = IStorage.WriteAllText(fileName, json, updateDateWhenMatches: true, compareBeforeWrite: true);
|
||||
}
|
||||
|
||||
private static string GetComment(List<Models.PersonURL> urls, List<Models.PersonComment> comments, KeyValuePair<DateTime, PersonImport> keyValuePair)
|
||||
{
|
||||
string result = keyValuePair.Value.Comment[2..];
|
||||
if (!string.IsNullOrEmpty(result))
|
||||
{
|
||||
if (result.StartsWith("http://") || result.StartsWith("https://"))
|
||||
urls.Add(new(new(result)));
|
||||
else
|
||||
comments.Add(new(new(result)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static List<Models.Person> GetPeopleFromText(Properties.IStorage storage, string localKnownPeopleFile)
|
||||
{
|
||||
List<Models.Person> results = new();
|
||||
@ -156,16 +182,7 @@ internal abstract class Person
|
||||
if (name.First is null || string.IsNullOrEmpty(name.First.Value))
|
||||
continue;
|
||||
if (!string.IsNullOrEmpty(keyValuePair.Value.Comment))
|
||||
{
|
||||
comment = keyValuePair.Value.Comment[2..];
|
||||
if (!string.IsNullOrEmpty(comment))
|
||||
{
|
||||
if (comment.StartsWith("http://") || comment.StartsWith("https://"))
|
||||
urls.Add(new(new(comment)));
|
||||
else
|
||||
comments.Add(new(new(comment)));
|
||||
}
|
||||
}
|
||||
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);
|
||||
|
272
Shared/Models/Stateless/Methods/Property.cs
Normal file
272
Shared/Models/Stateless/Methods/Property.cs
Normal file
@ -0,0 +1,272 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class Property
|
||||
{
|
||||
|
||||
internal static (int Season, string seasonName) GetSeason(int dayOfYear)
|
||||
{
|
||||
(int Season, string seasonName) result = dayOfYear switch
|
||||
{
|
||||
< 78 => new(0, "Winter"),
|
||||
< 171 => new(1, "Spring"),
|
||||
< 264 => new(2, "Summer"),
|
||||
< 354 => new(3, "Fall"),
|
||||
_ => new(4, "Winter")
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static int GetDeterministicHashCode(byte[] value)
|
||||
{
|
||||
int result;
|
||||
unchecked
|
||||
{
|
||||
int hash1 = (5381 << 16) + 5381;
|
||||
int hash2 = hash1;
|
||||
for (int i = 0; i < value.Length; i += 2)
|
||||
{
|
||||
hash1 = ((hash1 << 5) + hash1) ^ value[i];
|
||||
if (i == value.Length - 1)
|
||||
break;
|
||||
hash2 = ((hash2 << 5) + hash2) ^ value[i + 1];
|
||||
}
|
||||
result = hash1 + (hash2 * 1566083941);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static int GetDeterministicHashCode(string value)
|
||||
{
|
||||
int result;
|
||||
unchecked
|
||||
{
|
||||
int hash1 = (5381 << 16) + 5381;
|
||||
int hash2 = hash1;
|
||||
for (int i = 0; i < value.Length; i += 2)
|
||||
{
|
||||
hash1 = ((hash1 << 5) + hash1) ^ value[i];
|
||||
if (i == value.Length - 1)
|
||||
break;
|
||||
hash2 = ((hash2 << 5) + hash2) ^ value[i + 1];
|
||||
}
|
||||
result = hash1 + (hash2 * 1566083941);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static (bool?, string[]) IsWrongYear(string[] segments, string year)
|
||||
{
|
||||
bool? result;
|
||||
string[] results = (
|
||||
from l
|
||||
in segments
|
||||
where l?.Length > 2
|
||||
&& (
|
||||
l[..2] is "19" or "20"
|
||||
|| (l.Length == 5 && l.Substring(1, 2) is "19" or "20" && (l[0] is '~' or '=' or '-' or '^' or '#'))
|
||||
|| (l.Length == 6 && l[..2] is "19" or "20" && l[4] == '.')
|
||||
|| (l.Length == 7 && l.Substring(1, 2) is "19" or "20" && l[5] == '.')
|
||||
)
|
||||
select l
|
||||
).ToArray();
|
||||
string[] matches = (
|
||||
from l
|
||||
in results
|
||||
where l == year
|
||||
|| (l.Length == 5 && l.Substring(1, 4) == year && (l[0] is '~' or '=' or '-' or '^' or '#'))
|
||||
|| (l.Length == 6 && l[..4] == year && l[4] == '.')
|
||||
|| (l.Length == 7 && l.Substring(1, 4) == year && l[5] == '.')
|
||||
select l
|
||||
).ToArray();
|
||||
if (!results.Any())
|
||||
result = null;
|
||||
else
|
||||
result = !matches.Any();
|
||||
return new(result, results);
|
||||
}
|
||||
|
||||
internal static List<DateTime> GetDateTimes(DateTime creationTime, DateTime lastWriteTime, DateTime? dateTime, DateTime? dateTimeDigitized, DateTime? dateTimeOriginal, DateTime? gpsDateStamp)
|
||||
{
|
||||
List<DateTime> results = new()
|
||||
{
|
||||
creationTime,
|
||||
lastWriteTime
|
||||
};
|
||||
if (dateTime.HasValue)
|
||||
results.Add(dateTime.Value);
|
||||
if (dateTimeDigitized.HasValue)
|
||||
results.Add(dateTimeDigitized.Value);
|
||||
if (dateTimeOriginal.HasValue)
|
||||
results.Add(dateTimeOriginal.Value);
|
||||
if (gpsDateStamp.HasValue)
|
||||
results.Add(gpsDateStamp.Value);
|
||||
return results;
|
||||
}
|
||||
|
||||
internal static DateTime GetDateTime(Models.Property? property)
|
||||
{
|
||||
DateTime result;
|
||||
if (property is null)
|
||||
result = DateTime.MinValue;
|
||||
else
|
||||
{
|
||||
List<DateTime> dateTimes = new()
|
||||
{
|
||||
property.CreationTime,
|
||||
property.LastWriteTime
|
||||
};
|
||||
if (property.DateTime.HasValue)
|
||||
dateTimes.Add(property.DateTime.Value);
|
||||
if (property.DateTimeDigitized.HasValue)
|
||||
dateTimes.Add(property.DateTimeDigitized.Value);
|
||||
if (property.DateTimeOriginal.HasValue)
|
||||
dateTimes.Add(property.DateTimeOriginal.Value);
|
||||
if (property.GPSDateStamp.HasValue)
|
||||
dateTimes.Add(property.GPSDateStamp.Value);
|
||||
result = dateTimes.Min();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static DateTime GetMinimumDateTime(Models.Property? property)
|
||||
{
|
||||
DateTime result;
|
||||
List<DateTime> dateTimes;
|
||||
if (property is null)
|
||||
result = DateTime.MinValue;
|
||||
else
|
||||
{
|
||||
dateTimes = IProperty.GetDateTimes(property);
|
||||
result = dateTimes.Min();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static string GetDiffRootDirectory(string diffPropertyDirectory)
|
||||
{
|
||||
string result = string.Empty;
|
||||
string results = " - Results";
|
||||
string? checkDirectory = diffPropertyDirectory;
|
||||
for (int i = 0; i < int.MaxValue; i++)
|
||||
{
|
||||
checkDirectory = Path.GetDirectoryName(checkDirectory);
|
||||
if (string.IsNullOrEmpty(checkDirectory))
|
||||
break;
|
||||
if (checkDirectory.EndsWith(results))
|
||||
{
|
||||
result = checkDirectory[..^results.Length];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static double GetStandardDeviation(IEnumerable<long> values, double average)
|
||||
{
|
||||
double result = 0;
|
||||
if (!values.Any())
|
||||
throw new Exception("Collection must have at least one value!");
|
||||
double sum = values.Sum(l => (l - average) * (l - average));
|
||||
result = Math.Sqrt(sum / values.Count());
|
||||
return result;
|
||||
}
|
||||
|
||||
private static long GetThreeStandardDeviationHigh(ref List<long> ticksCollection, long min)
|
||||
{
|
||||
long result;
|
||||
ticksCollection = (from l in ticksCollection select l - min).ToList();
|
||||
double sum = ticksCollection.Sum();
|
||||
double average = sum / ticksCollection.Count;
|
||||
double standardDeviation = GetStandardDeviation(ticksCollection, average);
|
||||
result = (long)Math.Ceiling(average + min + (standardDeviation * 3));
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static TimeSpan GetThreeStandardDeviationHigh(int minimum, Models.Container container)
|
||||
{
|
||||
TimeSpan result;
|
||||
DateTime? minimumDateTime;
|
||||
List<long> ticksCollection = new();
|
||||
foreach (Models.Item item in container.Items)
|
||||
{
|
||||
if (item.Property is null)
|
||||
continue;
|
||||
minimumDateTime = GetMinimumDateTime(item.Property);
|
||||
if (minimumDateTime is null)
|
||||
continue;
|
||||
ticksCollection.Add(minimumDateTime.Value.Ticks);
|
||||
}
|
||||
long threeStandardDeviationHigh;
|
||||
long min;
|
||||
if (!ticksCollection.Any())
|
||||
min = 0;
|
||||
else
|
||||
min = ticksCollection.Min();
|
||||
if (ticksCollection.Count < minimum)
|
||||
threeStandardDeviationHigh = long.MaxValue;
|
||||
else
|
||||
threeStandardDeviationHigh = GetThreeStandardDeviationHigh(ref ticksCollection, min);
|
||||
result = new TimeSpan(threeStandardDeviationHigh - min);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static (int, List<DateTime>, List<Models.Item>) Get(Models.Container container, TimeSpan threeStandardDeviationHigh, int i)
|
||||
{
|
||||
List<Models.Item> results = new();
|
||||
int j = i;
|
||||
long? ticks;
|
||||
Models.Item item;
|
||||
TimeSpan timeSpan;
|
||||
Models.Item nextItem;
|
||||
DateTime? minimumDateTime;
|
||||
DateTime? nextMinimumDateTime;
|
||||
List<DateTime> dateTimes = new();
|
||||
for (; j < container.Items.Count; j++)
|
||||
{
|
||||
ticks = null;
|
||||
item = container.Items[j];
|
||||
if (item.Property is null)
|
||||
continue;
|
||||
minimumDateTime = GetMinimumDateTime(item.Property);
|
||||
if (minimumDateTime is null)
|
||||
continue;
|
||||
for (int k = j + 1; k < container.Items.Count; k++)
|
||||
{
|
||||
nextItem = container.Items[k];
|
||||
if (nextItem.Property is null)
|
||||
continue;
|
||||
nextMinimumDateTime = GetMinimumDateTime(nextItem.Property);
|
||||
if (nextMinimumDateTime is null)
|
||||
continue;
|
||||
ticks = nextMinimumDateTime.Value.Ticks;
|
||||
break;
|
||||
}
|
||||
results.Add(item);
|
||||
dateTimes.Add(minimumDateTime.Value);
|
||||
if (ticks.HasValue)
|
||||
{
|
||||
timeSpan = new(ticks.Value - minimumDateTime.Value.Ticks);
|
||||
if (timeSpan > threeStandardDeviationHigh)
|
||||
break;
|
||||
}
|
||||
}
|
||||
return new(j, dateTimes, results);
|
||||
}
|
||||
|
||||
internal static bool Any(List<Models.Container> propertyHolderCollections)
|
||||
{
|
||||
bool result = false;
|
||||
foreach (Models.Container container in propertyHolderCollections)
|
||||
{
|
||||
if (!container.Items.Any())
|
||||
continue;
|
||||
if ((from l in container.Items where l.Any() select true).Any())
|
||||
{
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
8
Shared/Models/Stateless/Methods/RelativePaths.cs
Normal file
8
Shared/Models/Stateless/Methods/RelativePaths.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class RelativePaths
|
||||
{
|
||||
|
||||
internal static double GetDefaultValue() => throw new Exception();
|
||||
|
||||
}
|
@ -12,11 +12,11 @@ internal abstract class WorkingDirectory
|
||||
List<string> directories = new();
|
||||
Environment.SpecialFolder[] specialFolders = new Environment.SpecialFolder[]
|
||||
{
|
||||
Environment.SpecialFolder.LocalApplicationData,
|
||||
Environment.SpecialFolder.ApplicationData,
|
||||
Environment.SpecialFolder.History,
|
||||
Environment.SpecialFolder.CommonApplicationData,
|
||||
Environment.SpecialFolder.InternetCache
|
||||
Environment.SpecialFolder.LocalApplicationData,
|
||||
Environment.SpecialFolder.ApplicationData,
|
||||
Environment.SpecialFolder.History,
|
||||
Environment.SpecialFolder.CommonApplicationData,
|
||||
Environment.SpecialFolder.InternetCache
|
||||
};
|
||||
foreach (Environment.SpecialFolder specialFolder in specialFolders)
|
||||
directories.Add(Path.Combine(Environment.GetFolderPath(specialFolder), subDirectoryName, executingAssemblyName));
|
||||
|
150
Shared/Models/Stateless/Methods/XPath.cs
Normal file
150
Shared/Models/Stateless/Methods/XPath.cs
Normal file
@ -0,0 +1,150 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class XPath
|
||||
{
|
||||
|
||||
internal static string GetRelativePath(string path, int length)
|
||||
{
|
||||
string result = path[length..].Replace(@"\", "/");
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static bool DeleteEmptyDirectories(string rootDirectory)
|
||||
{
|
||||
bool result;
|
||||
if (!Directory.Exists(rootDirectory))
|
||||
result = false;
|
||||
else
|
||||
{
|
||||
string[] files;
|
||||
string[] directories = Directory.GetDirectories(rootDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
if (directories.Length > 0)
|
||||
files = Array.Empty<string>();
|
||||
else
|
||||
files = Directory.GetFiles(rootDirectory, "*", SearchOption.AllDirectories);
|
||||
if (directories.Length == 0 && files.Length == 0)
|
||||
{
|
||||
result = true;
|
||||
Directory.Delete(rootDirectory);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
foreach (string directory in directories)
|
||||
{
|
||||
result = DeleteEmptyDirectories(directory);
|
||||
if (result)
|
||||
result = DeleteEmptyDirectories(directory);
|
||||
}
|
||||
if (files is null)
|
||||
{
|
||||
directories = Directory.GetDirectories(rootDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
result = directories.Length == 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static bool WriteAllText(string path, string contents, bool updateDateWhenMatches, bool compareBeforeWrite, DateTime? updateToWhenMatches)
|
||||
{
|
||||
bool result;
|
||||
string text;
|
||||
if (!compareBeforeWrite)
|
||||
result = true;
|
||||
else
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
text = string.Empty;
|
||||
else
|
||||
text = File.ReadAllText(path);
|
||||
result = text != contents;
|
||||
if (!result && updateDateWhenMatches)
|
||||
{
|
||||
if (updateToWhenMatches is null)
|
||||
File.SetLastWriteTime(path, DateTime.Now);
|
||||
else
|
||||
File.SetLastWriteTime(path, updateToWhenMatches.Value);
|
||||
}
|
||||
}
|
||||
if (result)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
internal static List<string> GetDirectoryNames(string directory)
|
||||
{
|
||||
List<string> results = new();
|
||||
string? checkDirectory = directory;
|
||||
string? pathRoot = Path.GetPathRoot(directory);
|
||||
string extension = Path.GetExtension(directory);
|
||||
if (string.IsNullOrEmpty(pathRoot))
|
||||
throw new NullReferenceException(nameof(pathRoot));
|
||||
if (Directory.Exists(directory))
|
||||
results.Add(Path.GetFileName(directory));
|
||||
else if ((string.IsNullOrEmpty(extension) || extension.Length > 3) && !File.Exists(directory))
|
||||
results.Add(Path.GetFileName(directory));
|
||||
for (int i = 0; i < int.MaxValue; i++)
|
||||
{
|
||||
checkDirectory = Path.GetDirectoryName(checkDirectory);
|
||||
if (string.IsNullOrEmpty(checkDirectory) || checkDirectory == pathRoot)
|
||||
break;
|
||||
results.Add(Path.GetFileName(checkDirectory));
|
||||
}
|
||||
results.Add(pathRoot);
|
||||
results.Reverse();
|
||||
return results;
|
||||
}
|
||||
|
||||
internal static (int level, List<string> directories) Get(string rootDirectory, string sourceDirectory)
|
||||
{
|
||||
int result = 0;
|
||||
string? directory;
|
||||
string? checkDirectory;
|
||||
List<string> results = new();
|
||||
checkDirectory = sourceDirectory;
|
||||
for (int i = 0; i < int.MaxValue; i++)
|
||||
{
|
||||
result += 1;
|
||||
directory = Path.GetFileName(checkDirectory);
|
||||
if (string.IsNullOrEmpty(directory))
|
||||
break;
|
||||
results.Add(directory);
|
||||
checkDirectory = Path.GetDirectoryName(checkDirectory);
|
||||
if (checkDirectory == rootDirectory)
|
||||
break;
|
||||
}
|
||||
results.Reverse();
|
||||
return new(result, results);
|
||||
}
|
||||
|
||||
internal static string GetDirectory(string sourceDirectory, int level, string directoryName)
|
||||
{
|
||||
string result;
|
||||
string? checkDirectory;
|
||||
checkDirectory = Path.GetDirectoryName(sourceDirectory);
|
||||
for (int i = 0; i < level; i++)
|
||||
checkDirectory = Path.GetDirectoryName(checkDirectory);
|
||||
if (string.IsNullOrEmpty(checkDirectory))
|
||||
throw new Exception();
|
||||
checkDirectory = Path.Combine(checkDirectory, directoryName);
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
result = checkDirectory;
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
14
Shared/Models/XPath.cs
Normal file
14
Shared/Models/XPath.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace View_by_Distance.Shared.Models;
|
||||
|
||||
public class XPath : Properties.IPath
|
||||
{
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -35,9 +35,9 @@ public class IsEnvironment
|
||||
if (testCategory.EndsWith(".json"))
|
||||
{
|
||||
Production = testCategory == "appsettings.json";
|
||||
Staging = testCategory.EndsWith(nameof(Staging));
|
||||
Staging = testCategory.Contains(nameof(Staging));
|
||||
OSX = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
|
||||
Development = testCategory.EndsWith(nameof(Development));
|
||||
Development = testCategory.Contains(nameof(Development));
|
||||
Linux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
|
||||
DebuggerWasAttachedDuringConstructor = Debugger.IsAttached;
|
||||
Windows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
||||
|
@ -9,7 +9,7 @@
|
||||
<PropertyGroup>
|
||||
<PackageId>Phares.View.by.Distance.Shared</PackageId>
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<Version>5.0.402.104</Version>
|
||||
<Version>6.0.100.1</Version>
|
||||
<Authors>Mike Phares</Authors>
|
||||
<Company>Phares</Company>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
|
Reference in New Issue
Block a user