AA.Compare Project to Match not runToDoCollectionFirst
Removed Layered AppSettings with Nested Objects at First Level
This commit is contained in:
46
Shared/Models/Stateless/Methods/Age.cs
Normal file
46
Shared/Models/Stateless/Methods/Age.cs
Normal file
@ -0,0 +1,46 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class Age
|
||||
{
|
||||
|
||||
internal static (int, TimeSpan) GetAge(long minuendTicks, long subtrahendTicks)
|
||||
{
|
||||
TimeSpan result;
|
||||
int years = 0;
|
||||
DateTime check = new(subtrahendTicks);
|
||||
for (int i = 0; i < int.MaxValue; i++)
|
||||
{
|
||||
check = check.AddYears(1);
|
||||
if (check.Ticks > minuendTicks)
|
||||
break;
|
||||
years += 1;
|
||||
}
|
||||
result = new(minuendTicks - check.AddYears(-1).Ticks);
|
||||
return (years, result);
|
||||
}
|
||||
|
||||
internal static (int, TimeSpan) GetAge(long minuendTicks, DateTime subtrahend)
|
||||
{
|
||||
(int years, TimeSpan result) = GetAge(minuendTicks, subtrahend.Ticks);
|
||||
return (years, result);
|
||||
}
|
||||
|
||||
internal static (int, TimeSpan) GetAge(DateTime minuend, DateTime subtrahend)
|
||||
{
|
||||
(int years, TimeSpan result) = GetAge(minuend.Ticks, subtrahend.Ticks);
|
||||
return (years, result);
|
||||
}
|
||||
|
||||
internal static int? GetApproximateYears(char[] personCharacters, string personDisplayDirectoryName)
|
||||
{
|
||||
int? result;
|
||||
const int zero = 0;
|
||||
string[] segments = personDisplayDirectoryName.Split(personCharacters);
|
||||
if (segments.Length == 1 || !int.TryParse(segments[1].Split('-')[zero], out int years))
|
||||
result = null;
|
||||
else
|
||||
result = years;
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
26
Shared/Models/Stateless/Methods/IAge.cs
Normal file
26
Shared/Models/Stateless/Methods/IAge.cs
Normal file
@ -0,0 +1,26 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IAge
|
||||
{ // ...
|
||||
|
||||
(int, TimeSpan) TestStatic_GetAge(long minuendTicks, long subtrahendTicks) =>
|
||||
GetAge(minuendTicks, subtrahendTicks);
|
||||
static (int, TimeSpan) GetAge(long minuendTicks, long subtrahendTicks) =>
|
||||
Age.GetAge(minuendTicks, subtrahendTicks);
|
||||
|
||||
(int, TimeSpan) TestStatic_GetAge(long minuendTicks, DateTime subtrahend) =>
|
||||
GetAge(minuendTicks, subtrahend);
|
||||
static (int, TimeSpan) GetAge(long minuendTicks, DateTime subtrahend) =>
|
||||
Age.GetAge(minuendTicks, subtrahend);
|
||||
|
||||
(int, TimeSpan) TestStatic_GetAge(DateTime minuend, DateTime subtrahend) =>
|
||||
GetAge(minuend, subtrahend);
|
||||
static (int, TimeSpan) GetAge(DateTime minuend, DateTime subtrahend) =>
|
||||
Age.GetAge(minuend, subtrahend);
|
||||
|
||||
int? TestStatic_GetApproximateYears(char[] personCharacters, string personDisplayDirectoryName) =>
|
||||
GetApproximateYears(personCharacters, personDisplayDirectoryName);
|
||||
static int? GetApproximateYears(char[] personCharacters, string personDisplayDirectoryName) =>
|
||||
Age.GetApproximateYears(personCharacters, personDisplayDirectoryName);
|
||||
|
||||
}
|
9
Shared/Models/Stateless/Methods/ICompare.cs
Normal file
9
Shared/Models/Stateless/Methods/ICompare.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface ICompare
|
||||
{
|
||||
|
||||
void Tick();
|
||||
void ConstructProgressBar(int maxTicks, string message);
|
||||
|
||||
}
|
@ -5,23 +5,23 @@ public interface IId
|
||||
|
||||
const int DeterministicHashCode = 9876543;
|
||||
|
||||
static bool IsOffsetDeterministicHashCode(MetadataConfiguration metadataConfiguration) =>
|
||||
metadataConfiguration.Offset == DeterministicHashCode;
|
||||
static bool IsOffsetDeterministicHashCode(MetadataSettings metadataSettings) =>
|
||||
metadataSettings.Offset == DeterministicHashCode;
|
||||
|
||||
string TestStatic_GetIntelligentId(MetadataConfiguration metadataConfiguration, long id, bool? hasIgnoreKeyword, bool? hasDateTimeOriginal) =>
|
||||
GetIntelligentId(metadataConfiguration, id, hasIgnoreKeyword, hasDateTimeOriginal);
|
||||
static string GetIntelligentId(MetadataConfiguration metadataConfiguration, long id, bool? hasIgnoreKeyword, bool? hasDateTimeOriginal) =>
|
||||
Id.GetIntelligentId(metadataConfiguration, id, hasIgnoreKeyword, hasDateTimeOriginal);
|
||||
string TestStatic_GetIntelligentId(ResultSettings resultSettings, MetadataSettings metadataSettings, long id, bool? hasIgnoreKeyword, bool? hasDateTimeOriginal) =>
|
||||
GetIntelligentId(resultSettings, metadataSettings, id, hasIgnoreKeyword, hasDateTimeOriginal);
|
||||
static string GetIntelligentId(ResultSettings resultSettings, MetadataSettings metadataSettings, long id, bool? hasIgnoreKeyword, bool? hasDateTimeOriginal) =>
|
||||
Id.GetIntelligentId(resultSettings, metadataSettings, id, hasIgnoreKeyword, hasDateTimeOriginal);
|
||||
|
||||
int TestStatic_GetId(MetadataConfiguration metadataConfiguration, string intelligentId) =>
|
||||
GetId(metadataConfiguration, intelligentId);
|
||||
static int GetId(MetadataConfiguration metadataConfiguration, string intelligentId) =>
|
||||
Id.GetId(metadataConfiguration, intelligentId);
|
||||
int TestStatic_GetId(ResultSettings resultSettings, MetadataSettings metadataSettings, string intelligentId) =>
|
||||
GetId(resultSettings, metadataSettings, intelligentId);
|
||||
static int GetId(ResultSettings resultSettings, MetadataSettings metadataSettings, string intelligentId) =>
|
||||
Id.GetId(resultSettings, metadataSettings, intelligentId);
|
||||
|
||||
string TestStatic_GetPaddedId(MetadataConfiguration metadataConfiguration, int id, bool? hasIgnoreKeyword, bool? hasDateTimeOriginal, int? index) =>
|
||||
GetPaddedId(metadataConfiguration, id, hasIgnoreKeyword, hasDateTimeOriginal, index);
|
||||
static string GetPaddedId(MetadataConfiguration metadataConfiguration, int id, bool? hasIgnoreKeyword, bool? hasDateTimeOriginal, int? index) =>
|
||||
Id.GetPaddedId(metadataConfiguration, id, hasIgnoreKeyword, hasDateTimeOriginal, index);
|
||||
string TestStatic_GetPaddedId(ResultSettings resultSettings, MetadataSettings metadataSettings, int id, bool? hasIgnoreKeyword, bool? hasDateTimeOriginal, int? index) =>
|
||||
GetPaddedId(resultSettings, metadataSettings, id, hasIgnoreKeyword, hasDateTimeOriginal, index);
|
||||
static string GetPaddedId(ResultSettings resultSettings, MetadataSettings metadataSettings, int id, bool? hasIgnoreKeyword, bool? hasDateTimeOriginal, int? index) =>
|
||||
Id.GetPaddedId(resultSettings, metadataSettings, id, hasIgnoreKeyword, hasDateTimeOriginal, index);
|
||||
|
||||
string TestStatic_GetIgnoreFullPath(FilePath filePath, FileHolder fileHolder) =>
|
||||
GetIgnoreFullPath(filePath, fileHolder);
|
||||
@ -36,22 +36,22 @@ public interface IId
|
||||
Path.Combine(fileHolder.DirectoryFullPath, $"{fileHolder.NameWithoutExtension[..^1]}2{fileHolder.ExtensionLowered}") :
|
||||
throw new NotSupportedException("Low");
|
||||
|
||||
bool TestStatic_NameWithoutExtensionIsIntelligentIdFormat(MetadataConfiguration metadataConfiguration, string fileNameFirstSegment) =>
|
||||
NameWithoutExtensionIsIntelligentIdFormat(metadataConfiguration, fileNameFirstSegment);
|
||||
static bool NameWithoutExtensionIsIntelligentIdFormat(MetadataConfiguration metadataConfiguration, string fileNameFirstSegment) =>
|
||||
fileNameFirstSegment.Length - 1 == metadataConfiguration.IntMinValueLength && fileNameFirstSegment[^1] is '1' or '2' or '8' or '9' && fileNameFirstSegment.All(char.IsNumber);
|
||||
bool TestStatic_NameWithoutExtensionIsIntelligentIdFormat(MetadataSettings metadataSettings, string fileNameFirstSegment) =>
|
||||
NameWithoutExtensionIsIntelligentIdFormat(metadataSettings, fileNameFirstSegment);
|
||||
static bool NameWithoutExtensionIsIntelligentIdFormat(MetadataSettings metadataSettings, string fileNameFirstSegment) =>
|
||||
fileNameFirstSegment.Length - 1 == metadataSettings.IntMinValueLength && fileNameFirstSegment[^1] is '1' or '2' or '8' or '9' && fileNameFirstSegment.All(char.IsNumber);
|
||||
|
||||
bool TestStatic_NameWithoutExtensionIsPaddedIntelligentIdFormat(MetadataConfiguration metadataConfiguration, int sortOrderOnlyLengthIndex, string fileNameFirstSegment) =>
|
||||
NameWithoutExtensionIsPaddedIntelligentIdFormat(metadataConfiguration, sortOrderOnlyLengthIndex, fileNameFirstSegment);
|
||||
static bool NameWithoutExtensionIsPaddedIntelligentIdFormat(MetadataConfiguration metadataConfiguration, int sortOrderOnlyLengthIndex, string fileNameFirstSegment) =>
|
||||
fileNameFirstSegment.Length == metadataConfiguration.IntMinValueLength + sortOrderOnlyLengthIndex + 1
|
||||
bool TestStatic_NameWithoutExtensionIsPaddedIntelligentIdFormat(MetadataSettings metadataSettings, int sortOrderOnlyLengthIndex, string fileNameFirstSegment) =>
|
||||
NameWithoutExtensionIsPaddedIntelligentIdFormat(metadataSettings, sortOrderOnlyLengthIndex, fileNameFirstSegment);
|
||||
static bool NameWithoutExtensionIsPaddedIntelligentIdFormat(MetadataSettings metadataSettings, int sortOrderOnlyLengthIndex, string fileNameFirstSegment) =>
|
||||
fileNameFirstSegment.Length == metadataSettings.IntMinValueLength + sortOrderOnlyLengthIndex + 1
|
||||
&& fileNameFirstSegment[^1] is '1' or '2' or '8' or '9'
|
||||
&& fileNameFirstSegment.All(char.IsNumber);
|
||||
|
||||
bool TestStatic_NameWithoutExtensionIsIdFormat(MetadataConfiguration metadataConfiguration, FileHolder fileHolder) =>
|
||||
NameWithoutExtensionIsIdFormat(metadataConfiguration, fileHolder);
|
||||
static bool NameWithoutExtensionIsIdFormat(MetadataConfiguration metadataConfiguration, FileHolder fileHolder) =>
|
||||
Id.NameWithoutExtensionIsIdFormat(metadataConfiguration, fileHolder.NameWithoutExtension.Split('.')[0]);
|
||||
bool TestStatic_NameWithoutExtensionIsIdFormat(MetadataSettings metadataSettings, FileHolder fileHolder) =>
|
||||
NameWithoutExtensionIsIdFormat(metadataSettings, fileHolder);
|
||||
static bool NameWithoutExtensionIsIdFormat(MetadataSettings metadataSettings, FileHolder fileHolder) =>
|
||||
Id.NameWithoutExtensionIsIdFormat(metadataSettings, fileHolder.NameWithoutExtension.Split('.')[0]);
|
||||
|
||||
int TestStatic_GetDeterministicHashCode(byte[] value) =>
|
||||
GetDeterministicHashCode(value);
|
||||
|
25
Shared/Models/Stateless/Methods/ILocation.cs
Normal file
25
Shared/Models/Stateless/Methods/ILocation.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using System.Drawing;
|
||||
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface ILocation
|
||||
{
|
||||
|
||||
RectangleF? TestStatic_GetPercentagesRectangle(DistanceSettings distanceSettings, int wholePercentages) =>
|
||||
GetPercentagesRectangle(distanceSettings, wholePercentages);
|
||||
static RectangleF? GetPercentagesRectangle(DistanceSettings distanceSettings, int wholePercentages) =>
|
||||
Location.GetPercentagesRectangle(distanceSettings, wholePercentages);
|
||||
|
||||
Models.Location TestStatic_GetTrimBound(double detectionConfidence, Rectangle rectangle, int width, int height, int facesCount) =>
|
||||
TrimBound(detectionConfidence, rectangle, width, height, facesCount);
|
||||
static Models.Location TrimBound(double detectionConfidence, Rectangle rectangle, int width, int height, int facesCount) =>
|
||||
Models.Location.Get(Math.Min(rectangle.Bottom, height),
|
||||
detectionConfidence,
|
||||
height,
|
||||
Math.Max(rectangle.Left, 0),
|
||||
Math.Min(rectangle.Right, width),
|
||||
Math.Max(rectangle.Top, 0),
|
||||
width,
|
||||
facesCount);
|
||||
|
||||
}
|
28
Shared/Models/Stateless/Methods/IMapping.cs
Normal file
28
Shared/Models/Stateless/Methods/IMapping.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using View_by_Distance.Shared.Models.Properties;
|
||||
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IMapping
|
||||
{ // ...
|
||||
|
||||
int TestStatic_GetAreaPermyriad(int faceAreaPermyriad, int height, Models.Location location, int width)
|
||||
=> GetAreaPermyriad(faceAreaPermyriad, height, location, width);
|
||||
static int GetAreaPermyriad(int faceAreaPermyriad, int height, Models.Location location, int width)
|
||||
=> Mapping.GetAreaPermyriad(faceAreaPermyriad, location.Bottom, height, location.Left, location.Right, location.Top, width);
|
||||
|
||||
int TestStatic_GetAreaPermyriad(int faceAreaPermyriad, int bottom, int height, int left, int right, int top, int width)
|
||||
=> GetAreaPermyriad(faceAreaPermyriad, bottom, height, left, right, top, width);
|
||||
static int GetAreaPermyriad(int faceAreaPermyriad, int bottom, int height, int left, int right, int top, int width)
|
||||
=> Mapping.GetAreaPermyriad(faceAreaPermyriad, bottom, height, left, right, top, width);
|
||||
|
||||
int TestStatic_GetAreaPermyriad(int faceAreaPermyriad, Models.Location location, OutputResolution outputResolution)
|
||||
=> GetAreaPermyriad(faceAreaPermyriad, location, outputResolution);
|
||||
static int GetAreaPermyriad(int faceAreaPermyriad, Models.Location location, OutputResolution outputResolution)
|
||||
=> Mapping.GetAreaPermyriad(faceAreaPermyriad, location.Bottom, outputResolution.Height, location.Left, location.Right, location.Top, outputResolution.Width);
|
||||
|
||||
int? TestStatic_GetWholePercentages(ICompareSettings compareSettings, FilePath filePath) =>
|
||||
GetWholePercentages(compareSettings, filePath);
|
||||
static int? GetWholePercentages(ICompareSettings compareSettings, FilePath filePath) =>
|
||||
Mapping.GetWholePercentages(compareSettings, filePath);
|
||||
|
||||
}
|
@ -61,24 +61,24 @@ public interface IPath
|
||||
static string GetDirectory(string sourceDirectory, int level, string directoryName) =>
|
||||
XPath.GetDirectory(sourceDirectory, level, directoryName);
|
||||
|
||||
(string, int) TestStatic_GetDirectoryNameAndIndex(ResultConfiguration resultConfiguration, FileHolder fileHolder) =>
|
||||
GetDirectoryNameAndIndex(resultConfiguration, fileHolder);
|
||||
static (string, int) GetDirectoryNameAndIndex(ResultConfiguration resultConfiguration, FileHolder fileHolder) =>
|
||||
XPath.GetDirectoryNameAndIndex(resultConfiguration, fileHolder);
|
||||
(string, int) TestStatic_GetDirectoryNameAndIndex(ResultSettings resultSettings, FileHolder fileHolder) =>
|
||||
GetDirectoryNameAndIndex(resultSettings, fileHolder);
|
||||
static (string, int) GetDirectoryNameAndIndex(ResultSettings resultSettings, FileHolder fileHolder) =>
|
||||
XPath.GetDirectoryNameAndIndex(resultSettings, fileHolder);
|
||||
|
||||
(string, int) TestStatic_GetDirectoryNameAndIndex(ResultConfiguration resultConfiguration, FilePath filePath) =>
|
||||
GetDirectoryNameAndIndex(resultConfiguration, filePath);
|
||||
static (string, int) GetDirectoryNameAndIndex(ResultConfiguration resultConfiguration, FilePath filePath) =>
|
||||
XPath.GetDirectoryNameAndIndex(resultConfiguration, filePath);
|
||||
(string, int) TestStatic_GetDirectoryNameAndIndex(ResultSettings resultSettings, FilePath filePath) =>
|
||||
GetDirectoryNameAndIndex(resultSettings, filePath);
|
||||
static (string, int) GetDirectoryNameAndIndex(ResultSettings resultSettings, FilePath filePath) =>
|
||||
XPath.GetDirectoryNameAndIndex(resultSettings, filePath);
|
||||
|
||||
(string, int) TestStatic_GetDirectoryNameAndIndex(ResultConfiguration resultConfiguration, int id) =>
|
||||
GetDirectoryNameAndIndex(resultConfiguration, id);
|
||||
static (string, int) GetDirectoryNameAndIndex(ResultConfiguration resultConfiguration, int id) =>
|
||||
XPath.GetDirectoryNameAndIndex(resultConfiguration, id);
|
||||
(string, int) TestStatic_GetDirectoryNameAndIndex(ResultSettings resultSettings, int id) =>
|
||||
GetDirectoryNameAndIndex(resultSettings, id);
|
||||
static (string, int) GetDirectoryNameAndIndex(ResultSettings resultSettings, int id) =>
|
||||
XPath.GetDirectoryNameAndIndex(resultSettings, id);
|
||||
|
||||
ReadOnlyDictionary<int, ReadOnlyDictionary<string, string[]>> TestStatic_GetKeyValuePairs(ResultConfiguration resultConfiguration, string? resultsFullGroupDirectory, string[]? jsonGroups) =>
|
||||
GetKeyValuePairs(resultConfiguration, resultsFullGroupDirectory, jsonGroups);
|
||||
static ReadOnlyDictionary<int, ReadOnlyDictionary<string, string[]>> GetKeyValuePairs(ResultConfiguration resultConfiguration, string? resultsFullGroupDirectory, string[]? jsonGroups) =>
|
||||
XPath.GetKeyValuePairs(resultConfiguration, resultsFullGroupDirectory, jsonGroups);
|
||||
ReadOnlyDictionary<int, ReadOnlyDictionary<string, string[]>> TestStatic_GetKeyValuePairs(ResultSettings resultSettings, string? resultsFullGroupDirectory, string[]? jsonGroups) =>
|
||||
GetKeyValuePairs(resultSettings, resultsFullGroupDirectory, jsonGroups);
|
||||
static ReadOnlyDictionary<int, ReadOnlyDictionary<string, string[]>> GetKeyValuePairs(ResultSettings resultSettings, string? resultsFullGroupDirectory, string[]? jsonGroups) =>
|
||||
XPath.GetKeyValuePairs(resultSettings, resultsFullGroupDirectory, jsonGroups);
|
||||
|
||||
}
|
55
Shared/Models/Stateless/Methods/IPerson.cs
Normal file
55
Shared/Models/Stateless/Methods/IPerson.cs
Normal file
@ -0,0 +1,55 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IPerson
|
||||
{
|
||||
|
||||
// ...
|
||||
|
||||
static (char, char, char) GetPersonHour(string? personDisplayDirectoryName, int hour) =>
|
||||
hour == 0 ? new('U', 'U', 'U') :
|
||||
hour == 1 ? new('U', 'U', 'U') :
|
||||
hour == 2 ? new('U', 'U', 'U') :
|
||||
hour == 3 ? new('A', 'U', 'Y') :
|
||||
hour == 4 ? new('A', 'F', 'Y') :
|
||||
hour == 5 ? new('A', 'M', 'Y') :
|
||||
hour == 6 ? new('A', 'F', 'N') :
|
||||
hour == 7 ? new('A', 'M', 'N') :
|
||||
hour == 13 ? new('D', 'U', 'Y') :
|
||||
hour == 14 ? new('D', 'F', 'Y') :
|
||||
hour == 15 ? new('D', 'M', 'Y') :
|
||||
hour == 16 ? new('D', 'F', 'N') :
|
||||
hour == 17 ? new('D', 'M', 'N') :
|
||||
throw new NotImplementedException(personDisplayDirectoryName);
|
||||
|
||||
static string GetHourGroup(string? personDisplayDirectoryName, int hour) =>
|
||||
hour == 0 ? "Unknown-Unknown-Unknown" :
|
||||
hour == 1 ? "Unknown-Unknown-Unknown" :
|
||||
hour == 2 ? "Unknown-Unknown-Unknown" :
|
||||
hour == 3 ? "Alive-Unknown-Yes" :
|
||||
hour == 4 ? "Alive-Female-Yes" :
|
||||
hour == 5 ? "Alive-Male-Yes" :
|
||||
hour == 6 ? "Alive-Female-No" :
|
||||
hour == 7 ? "Alive-Male-No" :
|
||||
hour == 13 ? "Dead-Unknown-Yes" :
|
||||
hour == 14 ? "Dead-Female-Yes" :
|
||||
hour == 15 ? "Dead-Male-Yes" :
|
||||
hour == 16 ? "Dead-Female-No" :
|
||||
hour == 17 ? "Dead-Male-No" :
|
||||
throw new NotImplementedException(personDisplayDirectoryName);
|
||||
|
||||
bool TestStatic_IsDefaultName(string personDisplayDirectoryName) =>
|
||||
IsDefaultName(personDisplayDirectoryName);
|
||||
static bool IsDefaultName(string personDisplayDirectoryName) =>
|
||||
personDisplayDirectoryName.Length > 1 && personDisplayDirectoryName[0] == 'X' && personDisplayDirectoryName[1] == '+';
|
||||
|
||||
bool TestStatic_IsDefaultName(Models.PersonContainer personContainer) =>
|
||||
IsDefaultName(personContainer);
|
||||
static bool IsDefaultName(Models.PersonContainer personContainer) =>
|
||||
personContainer.ApproximateYears is null || IsDefaultName(personContainer.DisplayDirectoryName);
|
||||
|
||||
bool TestStatic_IsDefaultName(MappingFromPerson mappingFromPerson) =>
|
||||
IsDefaultName(mappingFromPerson);
|
||||
static bool IsDefaultName(MappingFromPerson mappingFromPerson) =>
|
||||
mappingFromPerson.ApproximateYears is null || IsDefaultName(mappingFromPerson.DisplayDirectoryName);
|
||||
|
||||
}
|
116
Shared/Models/Stateless/Methods/IPersonBirthday.cs
Normal file
116
Shared/Models/Stateless/Methods/IPersonBirthday.cs
Normal file
@ -0,0 +1,116 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
public interface IPersonBirthday
|
||||
{
|
||||
|
||||
DateTime TestStatic_GetDefaultValue() =>
|
||||
GetDefaultValue();
|
||||
|
||||
static DateTime GetDefaultValue() =>
|
||||
DateTime.MinValue; // {{1}}SingletonValue
|
||||
|
||||
// ...
|
||||
|
||||
static bool IsCounterPersonBirthday(Models.PersonBirthday personBirthday) =>
|
||||
personBirthday.Value.Year < 1809;
|
||||
|
||||
static bool IsCounterPersonYear(long personKey) =>
|
||||
new DateTime(personKey).Year < 1809;
|
||||
|
||||
static bool IsCounterPersonYear(int year) =>
|
||||
year < 1809;
|
||||
|
||||
static bool IsCounterPersonYear(string year) =>
|
||||
new string[] { year, "1809" }.Min() == year;
|
||||
|
||||
static bool IsWrongYearFilterOrCounterPersonBirthday(bool? isWrongYear, Models.PersonBirthday personBirthday) =>
|
||||
isWrongYear is null || isWrongYear.Value || IsCounterPersonBirthday(personBirthday);
|
||||
|
||||
string TestStatic_GetDateTime(string personKeyFormatted) =>
|
||||
GetDateTime(personKeyFormatted);
|
||||
static string GetDateTime(string personKeyFormatted) =>
|
||||
personKeyFormatted.Length < 5 || !personKeyFormatted.Contains('#') ? personKeyFormatted : personKeyFormatted[..2] == "19" ? $"1600{personKeyFormatted[4..]}" : $"1700{personKeyFormatted[4..]}";
|
||||
|
||||
double? TestStatic_GetAge(Models.PersonBirthday birthday) =>
|
||||
GetAge(birthday);
|
||||
static double? GetAge(Models.PersonBirthday birthday) =>
|
||||
PersonBirthday.GetAge(birthday);
|
||||
|
||||
int TestStatic_GetHour(bool alive, char sex) =>
|
||||
GetHour(alive, sex);
|
||||
static int GetHour(bool alive, char sex) =>
|
||||
alive ? sex is 'M' ? 5 : sex is 'F' ? 4 : sex is 'U' ? 2 : throw new NotImplementedException() : sex is 'M' ? 15 : sex is 'F' ? 14 : sex is 'U' ? 3 : throw new NotImplementedException();
|
||||
|
||||
int TestStatic_GetHour(bool alive, ConsoleKey consoleKey) =>
|
||||
GetHour(alive, consoleKey);
|
||||
static int GetHour(bool alive, ConsoleKey consoleKey) =>
|
||||
GetHour(alive, consoleKey.ToString()[0]);
|
||||
|
||||
Models.PersonBirthday TestStatic_GetPersonBirthday(long ticks) =>
|
||||
new(new DateTime(ticks));
|
||||
static Models.PersonBirthday GetPersonBirthday(long ticks) =>
|
||||
new(new DateTime(ticks));
|
||||
|
||||
DateTime? TestStatic_GetDate(string month, string day, string year) =>
|
||||
GetDate(month, day, year);
|
||||
static DateTime? GetDate(string month, string day, string year) =>
|
||||
PersonBirthday.GetDate(month, day, year);
|
||||
|
||||
string TestStatic_GetFileName(string personBirthdayFormat, Models.PersonBirthday personBirthday) =>
|
||||
GetFileName(personBirthdayFormat, personBirthday);
|
||||
static string GetFileName(string personBirthdayFormat, Models.PersonBirthday personBirthday) =>
|
||||
$"{personBirthday.Value.ToString(personBirthdayFormat)}.json";
|
||||
|
||||
(int, TimeSpan) TestStatic_GetAge(DateTime dateTime, Models.PersonBirthday birthday) =>
|
||||
GetAge(dateTime, birthday);
|
||||
static (int, TimeSpan) GetAge(DateTime dateTime, Models.PersonBirthday birthday) =>
|
||||
PersonBirthday.GetAge(dateTime, birthday);
|
||||
|
||||
(int, TimeSpan) TestStatic_GetAge(long dateTimeTicks, Models.PersonBirthday birthday) =>
|
||||
GetAge(dateTimeTicks, birthday);
|
||||
static (int, TimeSpan) GetAge(long dateTimeTicks, Models.PersonBirthday birthday) =>
|
||||
PersonBirthday.GetAge(dateTimeTicks, birthday);
|
||||
|
||||
string TestStatic_GetFormatted(string personBirthdayFormat, Models.PersonBirthday personBirthday) =>
|
||||
GetFormatted(personBirthdayFormat, personBirthday);
|
||||
static string GetFormatted(string personBirthdayFormat, Models.PersonBirthday personBirthday) =>
|
||||
personBirthday.Value.ToString(personBirthdayFormat);
|
||||
|
||||
string TestStatic_GetFormatted(string personBirthdayFormat, long personKey) =>
|
||||
GetFormatted(personBirthdayFormat, personKey);
|
||||
static string GetFormatted(string personBirthdayFormat, long personKey) =>
|
||||
GetFormatted(personBirthdayFormat, GetPersonBirthday(personKey));
|
||||
|
||||
TimeSpan? TestStatic_Get(DateTime minimumDateTime, Models.PersonBirthday personBirthday) =>
|
||||
GetTimeSpan(minimumDateTime, isWrongYear: false, personBirthday);
|
||||
static TimeSpan? GetTimeSpan(DateTime minimumDateTime, Models.PersonBirthday personBirthday) =>
|
||||
PersonBirthday.GetTimeSpan(minimumDateTime, isWrongYear: false, personBirthday);
|
||||
|
||||
Models.PersonBirthday? TestStatic_GetPersonBirthday(string personBirthdayFormat, string personKeyFormatted) =>
|
||||
GetPersonBirthday(personBirthdayFormat, personKeyFormatted);
|
||||
static Models.PersonBirthday? GetPersonBirthday(string personBirthdayFormat, string personKeyFormatted) =>
|
||||
PersonBirthday.GetPersonBirthday(personBirthdayFormat, personKeyFormatted);
|
||||
|
||||
TimeSpan? TestStatic_Get(long minimumDateTimeTicks, bool? isWrongYear, Models.PersonBirthday personBirthday) =>
|
||||
GetTimeSpan(minimumDateTimeTicks, isWrongYear, personBirthday);
|
||||
static TimeSpan? GetTimeSpan(long minimumDateTimeTicks, bool? isWrongYear, Models.PersonBirthday personBirthday) =>
|
||||
PersonBirthday.GetTimeSpan(minimumDateTimeTicks, isWrongYear, personBirthday);
|
||||
|
||||
TimeSpan? TestStatic_Get(DateTime minimumDateTime, bool? isWrongYear, Models.PersonBirthday personBirthday) =>
|
||||
GetTimeSpan(minimumDateTime, isWrongYear, personBirthday);
|
||||
static TimeSpan? GetTimeSpan(DateTime minimumDateTime, bool? isWrongYear, Models.PersonBirthday personBirthday) =>
|
||||
PersonBirthday.GetTimeSpan(minimumDateTime, isWrongYear, personBirthday);
|
||||
|
||||
DateTime? TestStatic_GetDateTime(string personBirthdayFormat, string personKeyFormatted) =>
|
||||
GetDateTime(personBirthdayFormat, personKeyFormatted);
|
||||
static DateTime? GetDateTime(string personBirthdayFormat, string personKeyFormatted) =>
|
||||
DateTime.TryParseExact(GetDateTime(personKeyFormatted), personBirthdayFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dateTime) ? dateTime : null;
|
||||
|
||||
List<PersonKeyFormattedAndPersonBirthday> TestStatic_GetPersonBirthdays(string personBirthdayFormat, string[] personKeyDirectories, string personDisplayDirectoryName) =>
|
||||
GetPersonBirthdays(personBirthdayFormat, personKeyDirectories, personDisplayDirectoryName);
|
||||
static List<PersonKeyFormattedAndPersonBirthday> GetPersonBirthdays(string personBirthdayFormat, string[] personKeyDirectories, string personDisplayDirectoryName) =>
|
||||
PersonBirthday.GetPersonBirthdays(personBirthdayFormat, personKeyDirectories, personDisplayDirectoryName);
|
||||
|
||||
}
|
@ -6,7 +6,7 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
public interface IRename
|
||||
{
|
||||
|
||||
ReadOnlyCollection<string> ConvertAndGetFastForwardMovingPictureExpertsGroupFiles(IRenameConfiguration renameConfiguration, FilePath filePath);
|
||||
ReadOnlyCollection<string> ConvertAndGetFastForwardMovingPictureExpertsGroupFiles(IRenameSettings renameSettings, FilePath filePath);
|
||||
DeterministicHashCode GetDeterministicHashCode(FilePath filePath);
|
||||
void Tick();
|
||||
|
||||
|
@ -3,44 +3,44 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
public interface IResult
|
||||
{
|
||||
|
||||
string TestStatic_GetRelativePath(ResultConfiguration resultConfiguration, string path) =>
|
||||
GetRelativePath(resultConfiguration, path);
|
||||
static string GetRelativePath(ResultConfiguration resultConfiguration, string path) =>
|
||||
XResult.GetRelativePath(resultConfiguration, path);
|
||||
string TestStatic_GetRelativePath(ResultSettings resultSettings, string path) =>
|
||||
GetRelativePath(resultSettings, path);
|
||||
static string GetRelativePath(ResultSettings resultSettings, string path) =>
|
||||
XResult.GetRelativePath(resultSettings, path);
|
||||
|
||||
string TestStatic_GetResultsGroupDirectory(ResultConfiguration resultConfiguration, string description, bool create) =>
|
||||
GetResultsGroupDirectory(resultConfiguration, description, create);
|
||||
static string GetResultsGroupDirectory(ResultConfiguration resultConfiguration, string description, bool create) =>
|
||||
XResult.GetResultsGroupDirectory(resultConfiguration, description, create);
|
||||
string TestStatic_GetResultsGroupDirectory(ResultSettings resultSettings, string description, bool create) =>
|
||||
GetResultsGroupDirectory(resultSettings, description, create);
|
||||
static string GetResultsGroupDirectory(ResultSettings resultSettings, string description, bool create) =>
|
||||
XResult.GetResultsGroupDirectory(resultSettings, description, create);
|
||||
|
||||
string TestStatic_GetResultsGroupDirectory(ResultConfiguration resultConfiguration, string description) =>
|
||||
GetResultsGroupDirectory(resultConfiguration, description);
|
||||
static string GetResultsGroupDirectory(ResultConfiguration resultConfiguration, string description) =>
|
||||
XResult.GetResultsGroupDirectory(resultConfiguration, description, create: true);
|
||||
string TestStatic_GetResultsGroupDirectory(ResultSettings resultSettings, string description) =>
|
||||
GetResultsGroupDirectory(resultSettings, description);
|
||||
static string GetResultsGroupDirectory(ResultSettings resultSettings, string description) =>
|
||||
XResult.GetResultsGroupDirectory(resultSettings, description, create: true);
|
||||
|
||||
string TestStatic_GetResultsDateGroupDirectory(ResultConfiguration resultConfiguration, string description) =>
|
||||
GetResultsDateGroupDirectory(resultConfiguration, description);
|
||||
static string GetResultsDateGroupDirectory(ResultConfiguration resultConfiguration, string description) =>
|
||||
XResult.GetResultsDateGroupDirectory(resultConfiguration, description);
|
||||
string TestStatic_GetResultsDateGroupDirectory(ResultSettings resultSettings, string description) =>
|
||||
GetResultsDateGroupDirectory(resultSettings, description);
|
||||
static string GetResultsDateGroupDirectory(ResultSettings resultSettings, string description) =>
|
||||
XResult.GetResultsDateGroupDirectory(resultSettings, description);
|
||||
|
||||
string TestStatic_GetResultsDateGroupDirectory(ResultConfiguration resultConfiguration, string description, string jsonGroup) =>
|
||||
GetResultsDateGroupDirectory(resultConfiguration, description, jsonGroup);
|
||||
static string GetResultsDateGroupDirectory(ResultConfiguration resultConfiguration, string description, string jsonGroup) =>
|
||||
XResult.GetResultsDateGroupDirectory(resultConfiguration, description, jsonGroup);
|
||||
string TestStatic_GetResultsDateGroupDirectory(ResultSettings resultSettings, string description, string jsonGroup) =>
|
||||
GetResultsDateGroupDirectory(resultSettings, description, jsonGroup);
|
||||
static string GetResultsDateGroupDirectory(ResultSettings resultSettings, string description, string jsonGroup) =>
|
||||
XResult.GetResultsDateGroupDirectory(resultSettings, description, jsonGroup);
|
||||
|
||||
List<string> TestStatic_GetDirectoryInfoCollection(ResultConfiguration resultConfiguration, string sourceDirectory, string dateGroupDirectory, string contentDescription, string singletonDescription, string collectionDescription, bool converted) =>
|
||||
GetDirectoryInfoCollection(resultConfiguration, sourceDirectory, dateGroupDirectory, contentDescription, singletonDescription, collectionDescription, converted);
|
||||
static List<string> GetDirectoryInfoCollection(ResultConfiguration resultConfiguration, string sourceDirectory, string dateGroupDirectory, string contentDescription, string singletonDescription, string collectionDescription, bool converted) =>
|
||||
XResult.GetDirectoryInfoCollection(resultConfiguration, sourceDirectory, dateGroupDirectory, contentDescription, singletonDescription, collectionDescription, converted);
|
||||
List<string> TestStatic_GetDirectoryInfoCollection(ResultSettings resultSettings, string sourceDirectory, string dateGroupDirectory, string contentDescription, string singletonDescription, string collectionDescription, bool converted) =>
|
||||
GetDirectoryInfoCollection(resultSettings, sourceDirectory, dateGroupDirectory, contentDescription, singletonDescription, collectionDescription, converted);
|
||||
static List<string> GetDirectoryInfoCollection(ResultSettings resultSettings, string sourceDirectory, string dateGroupDirectory, string contentDescription, string singletonDescription, string collectionDescription, bool converted) =>
|
||||
XResult.GetDirectoryInfoCollection(resultSettings, sourceDirectory, dateGroupDirectory, contentDescription, singletonDescription, collectionDescription, converted);
|
||||
|
||||
string TestStatic_GetResultsFullGroupDirectory(ResultConfiguration resultConfiguration, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel) =>
|
||||
GetResultsFullGroupDirectory(resultConfiguration, description, outputResolution, includeResizeGroup, includeModel, includePredictorModel);
|
||||
static string GetResultsFullGroupDirectory(ResultConfiguration resultConfiguration, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel) =>
|
||||
XResult.GetResultsFullGroupDirectory(resultConfiguration, description, outputResolution, includeResizeGroup, includeModel, includePredictorModel);
|
||||
string TestStatic_GetResultsFullGroupDirectory(ResultSettings resultSettings, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel) =>
|
||||
GetResultsFullGroupDirectory(resultSettings, description, outputResolution, includeResizeGroup, includeModel, includePredictorModel);
|
||||
static string GetResultsFullGroupDirectory(ResultSettings resultSettings, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel) =>
|
||||
XResult.GetResultsFullGroupDirectory(resultSettings, description, outputResolution, includeResizeGroup, includeModel, includePredictorModel);
|
||||
|
||||
List<string> TestStatic_GetDirectoryInfoCollection(ResultConfiguration resultConfiguration, string sourceDirectory, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel, string contentDescription, string singletonDescription, string collectionDescription) =>
|
||||
GetDirectoryInfoCollection(resultConfiguration, sourceDirectory, description, outputResolution, includeResizeGroup, includeModel, includePredictorModel, contentDescription, singletonDescription, collectionDescription);
|
||||
static List<string> GetDirectoryInfoCollection(ResultConfiguration resultConfiguration, string sourceDirectory, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel, string contentDescription, string singletonDescription, string collectionDescription) =>
|
||||
XResult.GetDirectoryInfoCollection(resultConfiguration, sourceDirectory, description, outputResolution, includeResizeGroup, includeModel, includePredictorModel, contentDescription, singletonDescription, collectionDescription);
|
||||
List<string> TestStatic_GetDirectoryInfoCollection(ResultSettings resultSettings, string sourceDirectory, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel, string contentDescription, string singletonDescription, string collectionDescription) =>
|
||||
GetDirectoryInfoCollection(resultSettings, sourceDirectory, description, outputResolution, includeResizeGroup, includeModel, includePredictorModel, contentDescription, singletonDescription, collectionDescription);
|
||||
static List<string> GetDirectoryInfoCollection(ResultSettings resultSettings, string sourceDirectory, string description, string outputResolution, bool includeResizeGroup, bool includeModel, bool includePredictorModel, string contentDescription, string singletonDescription, string collectionDescription) =>
|
||||
XResult.GetDirectoryInfoCollection(resultSettings, sourceDirectory, description, outputResolution, includeResizeGroup, includeModel, includePredictorModel, contentDescription, singletonDescription, collectionDescription);
|
||||
|
||||
}
|
78
Shared/Models/Stateless/Methods/Location.cs
Normal file
78
Shared/Models/Stateless/Methods/Location.cs
Normal file
@ -0,0 +1,78 @@
|
||||
using System.Drawing;
|
||||
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class Location
|
||||
{
|
||||
|
||||
internal static bool Check(int bottom, int left, int right, int top, int zCount, bool throwException)
|
||||
{
|
||||
bool result = true;
|
||||
if (left < 0)
|
||||
result = false;
|
||||
if (right < 0)
|
||||
result = false;
|
||||
if (right < left)
|
||||
result = false;
|
||||
if (top < 0)
|
||||
result = false;
|
||||
if (bottom < 0)
|
||||
result = false;
|
||||
if (bottom < top)
|
||||
result = false;
|
||||
if (zCount < 0)
|
||||
result = false;
|
||||
if (throwException && !result)
|
||||
throw new Exception();
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static bool Check(int bottom, int height, int left, int right, int top, int width, int zCount, bool throwException)
|
||||
{
|
||||
bool result = true;
|
||||
if (bottom > height)
|
||||
result = false;
|
||||
if (left > width)
|
||||
result = false;
|
||||
if (right > width)
|
||||
result = false;
|
||||
if (top > height)
|
||||
result = false;
|
||||
if (zCount < 0)
|
||||
result = false;
|
||||
if (result)
|
||||
result = Check(bottom, left, right, top, zCount, throwException);
|
||||
if (throwException && !result)
|
||||
throw new Exception();
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static RectangleF? GetPercentagesRectangle(DistanceSettings distanceSettings, int wholePercentages)
|
||||
{
|
||||
RectangleF? result;
|
||||
string wp = wholePercentages.ToString();
|
||||
int length = (distanceSettings.LocationDigits - 1) / 4;
|
||||
string[] segments =
|
||||
[
|
||||
wp[..1],
|
||||
wp.Substring(1, length),
|
||||
wp.Substring(3, length),
|
||||
wp.Substring(5, length),
|
||||
wp.Substring(7, length)
|
||||
];
|
||||
if (string.Join(string.Empty, segments) != wp)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
if (!int.TryParse(segments[1], out int xWholePercent) || !int.TryParse(segments[2], out int yWholePercent) || !int.TryParse(segments[3], out int wWholePercent) || !int.TryParse(segments[4], out int hWholePercent))
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
float factor = 100;
|
||||
result = new(xWholePercent / factor, yWholePercent / factor, wWholePercent / factor, hWholePercent / factor);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
61
Shared/Models/Stateless/Methods/Mapping.cs
Normal file
61
Shared/Models/Stateless/Methods/Mapping.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using View_by_Distance.Shared.Models.Properties;
|
||||
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class Mapping
|
||||
{
|
||||
|
||||
internal static (string?, string?, bool?) GetSegments(string facesFileNameExtension, FilePath filePath)
|
||||
{
|
||||
string? extensionLowered;
|
||||
string? wholePercentages;
|
||||
bool? needsFacesFileNameExtension;
|
||||
string[] segments = filePath.Name.Split('.');
|
||||
if (segments.Length < 4 || $".{segments[3]}" != facesFileNameExtension)
|
||||
{
|
||||
extensionLowered = null;
|
||||
wholePercentages = null;
|
||||
needsFacesFileNameExtension = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
extensionLowered = $".{segments[2]}";
|
||||
wholePercentages = segments[1];
|
||||
needsFacesFileNameExtension = segments.Length == 3;
|
||||
}
|
||||
return new(wholePercentages, extensionLowered, needsFacesFileNameExtension);
|
||||
}
|
||||
|
||||
private static int? GetConvertedFromSegments(ICompareSettings compareSettings, FilePath filePath)
|
||||
{
|
||||
int? result;
|
||||
(string? WholePercentages, string? ExtensionLowered, bool? Check) segments = GetSegments(compareSettings.FacesFileNameExtension, filePath);
|
||||
if (string.IsNullOrEmpty(segments.WholePercentages) || string.IsNullOrEmpty(segments.ExtensionLowered) || segments.Check is null)
|
||||
result = null;
|
||||
else if (!int.TryParse(segments.WholePercentages, out int wholePercentages))
|
||||
result = null;
|
||||
else
|
||||
result = wholePercentages;
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static int? GetWholePercentages(ICompareSettings compareSettings, FilePath filePath)
|
||||
{
|
||||
int? wholePercentages;
|
||||
if (filePath.Name.Length < 2 || filePath.Name[1..].Contains('-'))
|
||||
wholePercentages = null;
|
||||
else
|
||||
wholePercentages = GetConvertedFromSegments(compareSettings, filePath);
|
||||
return wholePercentages;
|
||||
}
|
||||
|
||||
internal static int GetAreaPermyriad(int faceAreaPermyriad, int bottom, int height, int left, int right, int top, int width)
|
||||
{
|
||||
int result;
|
||||
double area = width * height;
|
||||
double locationArea = (right - left) * (bottom - top);
|
||||
result = (int)Math.Round(locationArea / area * faceAreaPermyriad, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
187
Shared/Models/Stateless/Methods/PersonBirthday.cs
Normal file
187
Shared/Models/Stateless/Methods/PersonBirthday.cs
Normal file
@ -0,0 +1,187 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class PersonBirthday
|
||||
{
|
||||
|
||||
// ...
|
||||
|
||||
internal static Models.PersonBirthday? GetPersonBirthday(string personBirthdayFormat, string personKeyFormatted)
|
||||
{
|
||||
Models.PersonBirthday? result;
|
||||
DateTime? dateTime;
|
||||
if (personKeyFormatted.Length != personBirthdayFormat.Length)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
dateTime = IPersonBirthday.GetDateTime(personBirthdayFormat, personKeyFormatted);
|
||||
if (dateTime is null)
|
||||
result = null;
|
||||
else
|
||||
result = new(dateTime.Value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static TimeSpan? GetTimeSpan(long minimumDateTimeTicks, bool? isWrongYear, Models.PersonBirthday personBirthday)
|
||||
{
|
||||
TimeSpan? timeSpan;
|
||||
bool isWrongYearFilterOrCounterPersonBirthday = IPersonBirthday.IsWrongYearFilterOrCounterPersonBirthday(isWrongYear, personBirthday);
|
||||
if (isWrongYearFilterOrCounterPersonBirthday)
|
||||
timeSpan = null;
|
||||
else
|
||||
timeSpan = new(minimumDateTimeTicks - personBirthday.Value.Ticks);
|
||||
return timeSpan;
|
||||
}
|
||||
|
||||
internal static TimeSpan? GetTimeSpan(DateTime minimumDateTime, bool? isWrongYear, Models.PersonBirthday personBirthday)
|
||||
{
|
||||
TimeSpan? timeSpan = GetTimeSpan(minimumDateTime.Ticks, isWrongYear, personBirthday);
|
||||
return timeSpan;
|
||||
}
|
||||
|
||||
internal static (int, TimeSpan) GetAge(long dateTimeTicks, Models.PersonBirthday birthday)
|
||||
{
|
||||
TimeSpan result;
|
||||
int years;
|
||||
if (birthday?.Value is null)
|
||||
throw new NullReferenceException(nameof(birthday.Value));
|
||||
(years, result) = Age.GetAge(dateTimeTicks, birthday.Value);
|
||||
return (years, result);
|
||||
}
|
||||
|
||||
internal static (int, TimeSpan) GetAge(DateTime dateTime, Models.PersonBirthday birthday)
|
||||
{
|
||||
TimeSpan result;
|
||||
int years;
|
||||
if (birthday?.Value is null)
|
||||
throw new NullReferenceException(nameof(birthday.Value));
|
||||
(years, result) = Age.GetAge(dateTime, birthday.Value);
|
||||
return (years, result);
|
||||
}
|
||||
|
||||
internal static (int, double) GetAge(DateTime dateTime, DateTime dayBeforeLeapDate, Models.PersonBirthday birthday)
|
||||
{
|
||||
double result;
|
||||
(int years, TimeSpan timeSpan) = GetAge(dateTime, birthday);
|
||||
if (!DateTime.IsLeapYear(dateTime.Year) || dateTime < dayBeforeLeapDate.AddDays(1))
|
||||
result = timeSpan.TotalDays / 365;
|
||||
else
|
||||
result = timeSpan.TotalDays / 366;
|
||||
return (years, result);
|
||||
}
|
||||
|
||||
internal static double? GetAge(Models.PersonBirthday birthday)
|
||||
{
|
||||
double? result;
|
||||
if (birthday is null)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
DateTime dateTime = DateTime.Now;
|
||||
DateTime dayBeforeLeapDate = new(dateTime.Year, 2, 28);
|
||||
(int years, double r) = GetAge(dateTime, dayBeforeLeapDate, birthday);
|
||||
result = years + r;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static List<PersonKeyFormattedAndPersonBirthday> GetPersonBirthdays(string personBirthdayFormat, string[] personKeyDirectories, string personDisplayDirectoryName)
|
||||
{
|
||||
List<PersonKeyFormattedAndPersonBirthday> results = [];
|
||||
string personKeyFormatted;
|
||||
Models.PersonBirthday? personBirthday;
|
||||
PersonKeyFormattedAndPersonBirthday personKeyFormattedAndPersonBirthday;
|
||||
foreach (string personKeyDirectory in personKeyDirectories)
|
||||
{
|
||||
personKeyFormatted = Path.GetFileName(personKeyDirectory);
|
||||
if (!DateTime.TryParseExact(personKeyFormatted, "MM.dd.yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime birthday))
|
||||
personBirthday = IPersonBirthday.GetPersonBirthday(personBirthdayFormat, personKeyFormatted);
|
||||
else
|
||||
// (personBirthday, personKeyFormatted) = Person.Get(personBirthdayFormat, personDisplayDirectory, personKeyDirectory, birthday);
|
||||
continue;
|
||||
if (personBirthday is null)
|
||||
continue;
|
||||
if (!IPersonBirthday.IsCounterPersonBirthday(personBirthday) && ((!personKeyDirectory.Contains('#') && (personDisplayDirectoryName.Contains('~') || personDisplayDirectoryName.Contains('#'))) || (personKeyDirectory.Contains('#') && !personDisplayDirectoryName.Contains('#'))))
|
||||
throw new NotSupportedException();
|
||||
personKeyFormattedAndPersonBirthday = new(personKeyFormatted, personBirthday);
|
||||
results.Add(personKeyFormattedAndPersonBirthday);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private static string? GetMonthShortForm(string month)
|
||||
{
|
||||
string? result = month.ToLower()[0] switch
|
||||
{
|
||||
// 'j' => "jan",
|
||||
'f' => "feb",
|
||||
// 'm' => "mar",
|
||||
// 'a' => "apr",
|
||||
// 'm' => "may",
|
||||
// 'j' => "jun",
|
||||
// 'j' => "jul",
|
||||
// 'a' => "aug",
|
||||
's' => "sep",
|
||||
'o' => "oct",
|
||||
'n' => "nov",
|
||||
'd' => "dec",
|
||||
_ => null
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static DateTime? GetDate(string month, string day, string year)
|
||||
{
|
||||
DateTime? result;
|
||||
DateTime dayDateTime;
|
||||
DateTime yearDateTime;
|
||||
DateTime monthDateTime;
|
||||
string? monthShortHand = string.IsNullOrEmpty(month) ? "x" : GetMonthShortForm(month);
|
||||
if (month.Length > 3)
|
||||
{
|
||||
if (!DateTime.TryParseExact($"{month},1,1500", "MMMM,d,yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out monthDateTime))
|
||||
monthDateTime = DateTime.MinValue;
|
||||
}
|
||||
else if (month.Length == 3)
|
||||
{
|
||||
if (!DateTime.TryParseExact($"{month},1,1500", "MMM,d,yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out monthDateTime))
|
||||
monthDateTime = DateTime.MinValue;
|
||||
}
|
||||
else if (month.Length == 1 && monthShortHand is not null)
|
||||
{
|
||||
if (!DateTime.TryParseExact($"{monthShortHand},1,1500", "MMM,d,yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out monthDateTime))
|
||||
monthDateTime = DateTime.MinValue;
|
||||
}
|
||||
else if (int.TryParse(month, out int _))
|
||||
{
|
||||
if (!DateTime.TryParseExact($"{month.PadLeft(2, '0')[..2]},1,1500", "MM,d,yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out monthDateTime))
|
||||
monthDateTime = DateTime.MinValue;
|
||||
}
|
||||
else
|
||||
monthDateTime = DateTime.MinValue;
|
||||
if (!int.TryParse(day, out int _))
|
||||
dayDateTime = DateTime.MinValue;
|
||||
else
|
||||
{
|
||||
if (!DateTime.TryParseExact($"01,{day.PadLeft(2, '0')[..2]},1500", "MM,d,yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dayDateTime))
|
||||
dayDateTime = DateTime.MinValue;
|
||||
}
|
||||
if (year.Length == 2 && int.TryParse(year, out int _))
|
||||
{
|
||||
if (!DateTime.TryParseExact($"01,01,{year.PadLeft(4, '0')[..4]}", "MM,dd,yy", CultureInfo.InvariantCulture, DateTimeStyles.None, out yearDateTime))
|
||||
yearDateTime = DateTime.MinValue;
|
||||
}
|
||||
else if (year.Length == 4 && int.TryParse(year, out int _))
|
||||
{
|
||||
if (!DateTime.TryParseExact($"01,01,{year.PadLeft(4, '0')[..4]}", "MM,dd,yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out yearDateTime))
|
||||
yearDateTime = DateTime.MinValue;
|
||||
}
|
||||
else
|
||||
yearDateTime = DateTime.MinValue;
|
||||
result = monthDateTime == DateTime.MinValue ? null : dayDateTime == DateTime.MinValue ? null : yearDateTime == DateTime.MinValue ? null : new(yearDateTime.Year, monthDateTime.Month, dayDateTime.Day);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user