This commit is contained in:
2022-08-22 09:10:19 -07:00
parent f72fcee1db
commit bc2174b17a
150 changed files with 4323 additions and 6259 deletions

View 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();
}

View File

@ -0,0 +1,8 @@
namespace View_by_Distance.Shared.Models.Stateless.Methods;
internal abstract class Container
{
internal static double GetDefaultValue() => throw new Exception();
}

View File

@ -0,0 +1,8 @@
namespace View_by_Distance.Shared.Models.Stateless.Methods;
internal abstract class DistanceHolder
{
internal static double GetDefaultValue() => throw new Exception();
}

View File

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

View File

@ -0,0 +1,8 @@
namespace View_by_Distance.Shared.Models.Stateless.Methods;
internal abstract class FacePoint
{
internal static double GetDefaultValue() => throw new Exception();
}

View File

@ -0,0 +1,8 @@
namespace View_by_Distance.Shared.Models.Stateless.Methods;
internal abstract class FileHolder
{
internal static double GetDefaultValue() => throw new Exception();
}

View File

@ -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++)
{

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

View File

@ -0,0 +1,10 @@
namespace View_by_Distance.Shared.Models.Stateless.Methods;
public interface IContainer
{ // ...
double TestStatic_GetDefaultValue();
static double GetDefaultValue() => Container.GetDefaultValue();
}

View File

@ -0,0 +1,10 @@
namespace View_by_Distance.Shared.Models.Stateless.Methods;
public interface IDistanceHolder
{ // ...
double TestStatic_GetDefaultValue();
static double GetDefaultValue() => DistanceHolder.GetDefaultValue();
}

View File

@ -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();
}

View File

@ -0,0 +1,10 @@
namespace View_by_Distance.Shared.Models.Stateless.Methods;
public interface IFacePoint
{ // ...
double TestStatic_GetDefaultValue();
static double GetDefaultValue() => FacePoint.GetDefaultValue();
}

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

View 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 ? "~" : "=";
}

View File

@ -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();
}

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

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

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

View File

@ -0,0 +1,10 @@
namespace View_by_Distance.Shared.Models.Stateless.Methods;
public interface IRelativePaths
{ // ...
double TestStatic_GetDefaultValue();
static double GetDefaultValue() => RelativePaths.GetDefaultValue();
}

View File

@ -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));

View File

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

View File

@ -0,0 +1,8 @@
namespace View_by_Distance.Shared.Models.Stateless.Methods;
internal abstract class Item
{
internal static double GetDefaultValue() => throw new Exception();
}

View File

@ -0,0 +1,6 @@
namespace View_by_Distance.Shared.Models.Stateless.Methods;
internal abstract class Location
{
}

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

View File

@ -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);

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

View File

@ -0,0 +1,8 @@
namespace View_by_Distance.Shared.Models.Stateless.Methods;
internal abstract class RelativePaths
{
internal static double GetDefaultValue() => throw new Exception();
}

View File

@ -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));

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