Distance bug fix

This commit is contained in:
2022-09-29 13:13:41 -07:00
parent 152612bacb
commit 4568d3fbc6
21 changed files with 933 additions and 879 deletions

View File

@ -8,7 +8,7 @@ public interface IPerson
string TestStatic_GetFileFullName(Properties.IStorage storage, string personBirthdayFormat, Models.Person person) =>
GetFileFullName(storage, personBirthdayFormat, person);
static string GetFileFullName(Properties.IStorage storage, string personBirthdayFormat, Models.Person person) =>
PersonBirthday.GetFileFullName(storage, personBirthdayFormat, person.Birthday);
IPersonBirthday.GetFileFullName(storage, personBirthdayFormat, person.Birthday);
Models.Person TestStatic_GetPerson(string personDisplayDirectoryName, long personKey, Models.PersonBirthday personBirthday) =>
GetPerson(personDisplayDirectoryName, personKey, personBirthday);

View File

@ -1,35 +1,37 @@
using System.Globalization;
namespace View_by_Distance.Shared.Models.Stateless.Methods;
public interface IPersonBirthday
{
DateTime TestStatic_GetDefaultValue() =>
PersonBirthday.GetDefaultValue(); // {{1}}SingletonValue
GetDefaultValue();
static DateTime GetDefaultValue() =>
PersonBirthday.GetDefaultValue(); // {{1}}SingletonValue
DateTime.MinValue; // {{1}}SingletonValue
// ...
string TestStatic_GetDateTime(string personKey) =>
GetDateTime(personKey);
static string GetDateTime(string personKey) =>
personKey.Length < 5 || !personKey.Contains('#') ? personKey : personKey[..2] == "19" ? $"1600{personKey[4..]}" : $"1700{personKey[4..]}";
double? TestStatic_GetAge(Models.PersonBirthday birthday) =>
GetAge(birthday);
static double? GetAge(Models.PersonBirthday birthday) =>
PersonBirthday.GetAge(birthday);
DateTime? TestStatic_GetDateTime(string personBirthdayFormat, string personKey) =>
PersonBirthday.GetDateTime(personBirthdayFormat, personKey);
static DateTime? GetDateTime(string personBirthdayFormat, string personKey) =>
PersonBirthday.GetDateTime(personBirthdayFormat, personKey);
Models.PersonBirthday TestStatic_GetPersonBirthday(long ticks) =>
new(new(ticks));
static Models.PersonBirthday GetPersonBirthday(long ticks) =>
new(new(ticks));
string TestStatic_GetFileName(string personBirthdayFormat, Models.PersonBirthday personBirthday) =>
PersonBirthday.GetFileName(personBirthdayFormat, personBirthday);
GetFileName(personBirthdayFormat, personBirthday);
static string GetFileName(string personBirthdayFormat, Models.PersonBirthday personBirthday) =>
PersonBirthday.GetFileName(personBirthdayFormat, personBirthday);
$"{personBirthday.Value.ToString(personBirthdayFormat)}.json";
(int, TimeSpan) TestStatic_GetAge(DateTime dateTime, Models.PersonBirthday birthday) =>
GetAge(dateTime, birthday);
@ -41,20 +43,15 @@ public interface IPersonBirthday
static (int, TimeSpan) GetAge(long dateTimeTicks, Models.PersonBirthday birthday) =>
PersonBirthday.GetAge(dateTimeTicks, birthday);
string TestStatic_GetFormatted(string personBirthdayFormat, long personKey) =>
GetFormatted(personBirthdayFormat, personKey);
static string GetFormatted(string personBirthdayFormat, long personKey) =>
PersonBirthday.GetFormatted(personBirthdayFormat, GetPersonBirthday(personKey));
string TestStatic_GetFormatted(string personBirthdayFormat, Models.PersonBirthday personBirthday) =>
GetFormatted(personBirthdayFormat, personBirthday);
static string GetFormatted(string personBirthdayFormat, Models.PersonBirthday personBirthday) =>
PersonBirthday.GetFormatted(personBirthdayFormat, personBirthday);
personBirthday.Value.ToString(personBirthdayFormat);
Models.PersonBirthday? TestStatic_GetPersonBirthday(string personBirthdayFormat, string personKey) =>
GetPersonBirthday(personBirthdayFormat, personKey);
static Models.PersonBirthday? GetPersonBirthday(string personBirthdayFormat, string personKey) =>
PersonBirthday.GetPersonBirthday(personBirthdayFormat, personKey);
string TestStatic_GetFormatted(string personBirthdayFormat, long personKey) =>
GetFormatted(personBirthdayFormat, personKey);
static string GetFormatted(string personBirthdayFormat, long personKey) =>
GetFormatted(personBirthdayFormat, GetPersonBirthday(personKey));
bool TestStatic_IsCounterPersonBirthday(Models.PersonBirthday personBirthday) =>
IsCounterPersonBirthday(personBirthday);
@ -64,28 +61,28 @@ public interface IPersonBirthday
Models.PersonBirthday TestStatic_GetNextBirthDate(Properties.IStorage storage) =>
GetNextBirthDate(storage);
static Models.PersonBirthday GetNextBirthDate(Properties.IStorage storage) =>
PersonBirthday.GetNextBirthDate(storage);
throw new Exception(storage.ToString()); // Person.GetNextBirthDate(storage);
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);
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);
string TestStatic_GetFileFullName(Properties.IStorage storage, string personBirthdayFormat, Models.PersonBirthday personBirthday) =>
GetFileFullName(storage, personBirthdayFormat, personBirthday);
static string GetFileFullName(Properties.IStorage storage, string personBirthdayFormat, Models.PersonBirthday personBirthday) =>
PersonBirthday.GetFileFullName(storage, personBirthdayFormat, personBirthday);
Models.PersonBirthday? TestStatic_GetPersonBirthday(string personBirthdayFormat, string personKey) =>
GetPersonBirthday(personBirthdayFormat, personKey);
static Models.PersonBirthday? GetPersonBirthday(string personBirthdayFormat, string personKey) =>
PersonBirthday.GetPersonBirthday(personBirthdayFormat, personKey);
bool TestStatic_DoesBirthDateExits(Properties.IStorage storage, Models.PersonBirthday personBirthday) =>
DoesBirthDateExits(storage, personBirthday);
static bool DoesBirthDateExits(Properties.IStorage storage, Models.PersonBirthday personBirthday) =>
DoesBirthDateExits(storage, personBirthday);
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) =>
@ -96,4 +93,19 @@ public interface IPersonBirthday
static bool IsWrongYearFilterOrCounterPersonBirthday(bool? isWrongYear, Models.PersonBirthday personBirthday) =>
PersonBirthday.IsWrongYearFilterOrCounterPersonBirthday(isWrongYear, personBirthday);
string TestStatic_GetFileFullName(Properties.IStorage storage, string personBirthdayFormat, Models.PersonBirthday personBirthday) =>
GetFileFullName(storage, personBirthdayFormat, personBirthday);
static string GetFileFullName(Properties.IStorage storage, string personBirthdayFormat, Models.PersonBirthday personBirthday) =>
Path.Combine(storage.PeopleRootDirectory, "{}", GetFileName(personBirthdayFormat, personBirthday));
bool TestStatic_DoesBirthDateExits(Properties.IStorage storage, string personBirthdayFormat, Models.PersonBirthday personBirthday) =>
DoesBirthDateExits(storage, personBirthdayFormat, personBirthday);
internal static bool DoesBirthDateExits(Properties.IStorage storage, string personBirthdayFormat, Models.PersonBirthday personBirthday) =>
File.Exists(GetFileFullName(storage, personBirthdayFormat, personBirthday));
DateTime? TestStatic_GetDateTime(string personBirthdayFormat, string personKey) =>
GetDateTime(personBirthdayFormat, personKey);
static DateTime? GetDateTime(string personBirthdayFormat, string personKey) =>
DateTime.TryParseExact(GetDateTime(personKey), personBirthdayFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dateTime) ? dateTime : null;
}

View File

@ -5,20 +5,12 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
internal abstract class PersonBirthday
{
internal static DateTime GetDefaultValue() => DateTime.MinValue; // {{1}}SingletonValue
// ...
internal static string GetFormatted(string personBirthdayFormat, Models.PersonBirthday personBirthday) => personBirthday.Value.ToString(personBirthdayFormat);
internal static string GetFileName(string personBirthdayFormat, Models.PersonBirthday personBirthday) => $"{personBirthday.Value.ToString(personBirthdayFormat)}.json";
internal static bool DoesBirthDateExits(Properties.IStorage storage, string personBirthdayFormat, Models.PersonBirthday personBirthday) => File.Exists(GetFileFullName(storage, personBirthdayFormat, personBirthday));
internal static Models.PersonBirthday GetNextBirthDate(Properties.IStorage storage) => throw new Exception(storage.ToString()); // Person.GetNextBirthDate(storage);
internal static string GetFileFullName(Properties.IStorage storage, string personBirthdayFormat, Models.PersonBirthday personBirthday) => Path.Combine(storage.PeopleRootDirectory, "{}", GetFileName(personBirthdayFormat, personBirthday));
internal static DateTime? GetDateTime(string personBirthdayFormat, string personKey) => DateTime.TryParseExact(personKey.Replace('#', '0'), personBirthdayFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dateTime) ? dateTime : null;
internal static Models.PersonBirthday? GetPersonBirthday(string personBirthdayFormat, string personKey)
{
Models.PersonBirthday? result;
DateTime? dateTime = GetDateTime(personBirthdayFormat, personKey);
DateTime? dateTime = IPersonBirthday.GetDateTime(personBirthdayFormat, personKey);
if (dateTime is null)
result = null;
else
@ -29,7 +21,7 @@ internal abstract class PersonBirthday
internal static bool IsCounterPersonBirthday(Models.PersonBirthday personBirthday)
{
bool result;
if (personBirthday.Value.Year < 1900)
if (personBirthday.Value.Year < 1826)
result = true;
else
result = false;
@ -109,7 +101,7 @@ internal abstract class PersonBirthday
return result;
}
internal static Models.PersonBirthday[] GetDescendingOrderedPersonBirthdays(string personBirthdayFormat, string[] personKeyDirectories, string personDisplayDirectory)
internal static List<Models.PersonBirthday> GetPersonBirthdays(string personBirthdayFormat, string[] personKeyDirectories, string personDisplayDirectory, string personDisplayDirectoryName)
{
List<Models.PersonBirthday> results = new();
string[] files;
@ -124,13 +116,15 @@ internal abstract class PersonBirthday
(personBirthday, personKeyFormatted) = Person.Get(personBirthdayFormat, personDisplayDirectory, personKeyDirectory, birthday);
if (personBirthday is null || personKeyFormatted.Contains('#'))
continue;
if (!IPersonBirthday.IsCounterPersonBirthday(personBirthday) && ((!personKeyDirectory.Contains('#') && (personDisplayDirectoryName.Contains('~') || personDisplayDirectoryName.Contains('#'))) || (personKeyDirectory.Contains('#') && !personDisplayDirectoryName.Contains('#'))))
throw new NotSupportedException();
results.Add(personBirthday);
files = Directory.GetFiles(personKeyDirectory, "*", SearchOption.TopDirectoryOnly);
if (files.Any())
continue;
File.WriteAllText(Path.Combine(personKeyDirectory, $"{personKeyFormatted}.txt"), string.Empty);
}
return results.OrderByDescending(l => l.Value.Ticks).ToArray();
return results;
}
}

View File

@ -33,31 +33,23 @@ internal abstract class PersonContainer
return results;
}
private static List<(long?, Models.PersonContainer)> GetPersonContainersCollections(string personBirthdayFormat, string facesFileNameExtension, char[] chars, string personDisplayDirectory, string personDisplayDirectoryName, string[] personKeyDirectories, int? approximateYears, Models.PersonBirthday[] personBirthdays)
private static List<(long?, Models.PersonContainer)> GetPersonContainersCollections(string facesFileNameExtension, char[] chars, string personDisplayDirectory, string personDisplayDirectoryName, int? approximateYears, List<Models.PersonBirthday> personBirthdays)
{
List<(long?, Models.PersonContainer)> results = new();
long personKey;
string[] segments;
const int zero = 0;
Models.Person person;
string personKeyFormatted;
Models.PersonBirthday? personBirthday;
Models.PersonContainer personContainer;
Models.PersonBirthday[] orderedPersonBirthdays;
string[] personDisplayDirectoryAllFiles = GetFiles(facesFileNameExtension, personDisplayDirectory);
foreach (string personKeyDirectory in personKeyDirectories)
foreach (Models.PersonBirthday personBirthday in personBirthdays)
{
personKeyFormatted = Path.GetFileName(personKeyDirectory);
personBirthday = IPersonBirthday.GetPersonBirthday(personBirthdayFormat, personKeyFormatted);
if (personBirthday is null)
continue;
if (!IPersonBirthday.IsCounterPersonBirthday(personBirthday) && ((!personKeyDirectory.Contains('#') && (personDisplayDirectoryName.Contains('~') || personDisplayDirectoryName.Contains('#'))) || (personKeyDirectory.Contains('#') && !personDisplayDirectoryName.Contains('#'))))
throw new NotSupportedException();
personKey = personBirthdays[zero].Value.Ticks;
if (personKey != personBirthdays.OrderByDescending(l => l.Value.Ticks).ToArray()[0].Value.Ticks)
throw new NotSupportedException();
segments = personDisplayDirectoryName.Split(chars);
orderedPersonBirthdays = personBirthdays.OrderByDescending(l => l.Value.Ticks).ToArray();
personKey = orderedPersonBirthdays[zero].Value.Ticks;
person = IPerson.GetPerson(personKey, segments);
personContainer = new(approximateYears, person, personBirthdays, personDisplayDirectoryAllFiles, personDisplayDirectoryName, personKey);
personContainer = new(approximateYears, person, orderedPersonBirthdays, personDisplayDirectoryAllFiles, personDisplayDirectoryName, personKey);
results.Add(new(personKey, personContainer));
}
return results;
@ -71,7 +63,7 @@ internal abstract class PersonContainer
return result;
}
private static string? VerifyAge(string personDisplayDirectory, string minusOne, string personDisplayDirectoryName, int? approximateYears, Models.PersonBirthday[] personBirthdays)
private static string? VerifyAge(string personDisplayDirectory, string minusOne, string personDisplayDirectoryName, int? approximateYears, List<Models.PersonBirthday> personBirthdays)
{
string? result;
if (approximateYears is null)
@ -81,7 +73,8 @@ internal abstract class PersonContainer
const int zero = 0;
int? updateApproximateYears;
DateTime dateTime = DateTime.Now;
TimeSpan timeSpan = new(personBirthdays[zero].Value.Ticks - dateTime.AddYears(-approximateYears.Value).Ticks);
Models.PersonBirthday[] orderedPersonBirthdays = personBirthdays.OrderByDescending(l => l.Value.Ticks).ToArray();
TimeSpan timeSpan = new(orderedPersonBirthdays[zero].Value.Ticks - dateTime.AddYears(-approximateYears.Value).Ticks);
if (timeSpan.TotalDays < -356)
updateApproximateYears = approximateYears.Value + 1;
else if (timeSpan.TotalDays > 356)
@ -110,7 +103,7 @@ internal abstract class PersonContainer
string[] personKeyDirectories;
string? personDisplayDirectoryName;
Models.PersonContainer personContainer;
Models.PersonBirthday[] personBirthdays;
List<Models.PersonBirthday> personBirthdays;
foreach (string personDisplayDirectory in personDisplayDirectories)
{
personDisplayDirectoryName = Path.GetFileName(personDisplayDirectory);
@ -118,7 +111,7 @@ internal abstract class PersonContainer
continue;
approximateYears = Age.GetApproximateYears(personDisplayDirectoryName, chars);
personKeyDirectories = Directory.GetDirectories(personDisplayDirectory, "*", SearchOption.TopDirectoryOnly);
personBirthdays = PersonBirthday.GetDescendingOrderedPersonBirthdays(personBirthdayFormat, personKeyDirectories, personDisplayDirectory);
personBirthdays = PersonBirthday.GetPersonBirthdays(personBirthdayFormat, personKeyDirectories, personDisplayDirectory, personDisplayDirectoryName);
if (personDisplayDirectoryName.Contains('^'))
{
minusOne = Path.GetDirectoryName(personDisplayDirectory);
@ -129,7 +122,7 @@ internal abstract class PersonContainer
if (changes.Any(l => l is not null))
continue;
if (personBirthdays.Any())
results.AddRange(GetPersonContainersCollections(personBirthdayFormat, facesFileNameExtension, chars, personDisplayDirectory, personDisplayDirectoryName, personKeyDirectories, approximateYears, personBirthdays));
results.AddRange(GetPersonContainersCollections(facesFileNameExtension, chars, personDisplayDirectory, personDisplayDirectoryName, approximateYears, personBirthdays));
else
{
personContainer = GetPersonContainer(facesFileNameExtension, personDisplayDirectory, personDisplayDirectoryName, approximateYears);