SaveParents
Removed GetFilteredOutMapped Removed GetNonSpecificPeopleCollection
This commit is contained in:
@ -1,7 +1,4 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
@ -95,19 +92,17 @@ internal abstract class PersonContainer
|
||||
return results;
|
||||
}
|
||||
|
||||
private static List<Models.PersonContainer> GetPersonContainersCollections(string mappingDefaultName, string facesFileNameExtension, char[] personCharacters, ReadOnlyDictionary<string, string[]> individuals, PersonDirectory personDirectory, char numberSign, string personDisplayDirectory, string personDisplayDirectoryName, bool isDefaultName, int? approximateYears, List<(string PersonKeyFormatted, Models.PersonBirthday PersonBirthday)> collection)
|
||||
private static List<Models.PersonContainer> GetPersonContainersCollections(string mappingDefaultName, string facesFileNameExtension, char[] personCharacters, PersonDirectory personDirectory, char numberSign, string personDisplayDirectory, string personDisplayDirectoryName, bool isDefaultName, int? approximateYears, List<(string PersonKeyFormatted, Models.PersonBirthday PersonBirthday)> collection)
|
||||
{
|
||||
List<Models.PersonContainer> results = new();
|
||||
long personKey;
|
||||
const int zero = 0;
|
||||
Models.Person person;
|
||||
string[]? individualsLines;
|
||||
Models.PersonContainer personContainer;
|
||||
Models.PersonBirthday[] orderedPersonBirthdays;
|
||||
string[] personDisplayDirectoryAllFiles = GetFiles(facesFileNameExtension, personDisplayDirectory, isDefaultName);
|
||||
foreach ((string personKeyFormatted, Models.PersonBirthday personBirthday) in collection)
|
||||
{
|
||||
_ = individuals.TryGetValue(personKeyFormatted, out individualsLines);
|
||||
orderedPersonBirthdays = (from l in collection where !l.PersonKeyFormatted.Contains(numberSign) orderby l.PersonBirthday.Value.Ticks descending select l.PersonBirthday).ToArray();
|
||||
if (!orderedPersonBirthdays.Any())
|
||||
personKey = collection[zero].PersonBirthday.Value.Ticks;
|
||||
@ -118,7 +113,7 @@ internal abstract class PersonContainer
|
||||
personKey = orderedPersonBirthdays[zero].Value.Ticks;
|
||||
}
|
||||
person = IPerson.GetPerson(mappingDefaultName, personCharacters, personDisplayDirectoryName, personDisplayDirectoryAllFiles, personKey);
|
||||
personContainer = new(approximateYears, orderedPersonBirthdays, personDisplayDirectoryAllFiles, personDisplayDirectoryName, individualsLines, personKey, person, personDirectory);
|
||||
personContainer = new(approximateYears, orderedPersonBirthdays, personDisplayDirectoryAllFiles, personDisplayDirectoryName, personKey, person, personDirectory);
|
||||
results.Add(personContainer);
|
||||
}
|
||||
return results;
|
||||
@ -155,7 +150,7 @@ internal abstract class PersonContainer
|
||||
return result;
|
||||
}
|
||||
|
||||
private static (List<string?>, List<Models.PersonContainer>) GetPersonContainersGroup(string mappingDefaultName, string personBirthdayFormat, string facesFileNameExtension, char[] personCharacters, ReadOnlyDictionary<string, string[]> individuals, PersonDirectory personDirectory, string[] personDisplayDirectories)
|
||||
private static (List<string?>, List<Models.PersonContainer>) GetPersonContainersGroup(string mappingDefaultName, string personBirthdayFormat, string facesFileNameExtension, char[] personCharacters, PersonDirectory personDirectory, string[] personDisplayDirectories)
|
||||
{
|
||||
List<Models.PersonContainer> results = new();
|
||||
string? minusOne;
|
||||
@ -189,7 +184,7 @@ internal abstract class PersonContainer
|
||||
continue;
|
||||
if (collection.Any())
|
||||
{
|
||||
personContainers = GetPersonContainersCollections(mappingDefaultName, facesFileNameExtension, personCharacters, individuals, personDirectory, numberSign, personDisplayDirectory, personDisplayDirectoryName, isDefaultName, approximateYears, collection);
|
||||
personContainers = GetPersonContainersCollections(mappingDefaultName, facesFileNameExtension, personCharacters, personDirectory, numberSign, personDisplayDirectory, personDisplayDirectoryName, isDefaultName, approximateYears, collection);
|
||||
results.AddRange(personContainers);
|
||||
}
|
||||
else
|
||||
@ -202,7 +197,7 @@ internal abstract class PersonContainer
|
||||
return new(changes, results);
|
||||
}
|
||||
|
||||
private static (List<string?>, List<Models.PersonContainer>) GetPersonContainersInnerGroups(string mappingDefaultName, string personBirthdayFormat, string facesFileNameExtension, char[] personCharacters, ReadOnlyDictionary<string, string[]> individuals, string groupDirectory, string groupDirectoryName)
|
||||
private static (List<string?>, List<Models.PersonContainer>) GetPersonContainersInnerGroups(string mappingDefaultName, string personBirthdayFormat, string facesFileNameExtension, char[] personCharacters, string groupDirectory, string groupDirectoryName)
|
||||
{
|
||||
List<Models.PersonContainer> results = new();
|
||||
string[] segments;
|
||||
@ -219,7 +214,7 @@ internal abstract class PersonContainer
|
||||
if (@char == exclamationPoint)
|
||||
{
|
||||
personDirectory = new(@char, "Ignore", 'U', 'U', 'U');
|
||||
(changes, collection) = GetPersonContainersGroup(mappingDefaultName, personBirthdayFormat, facesFileNameExtension, personCharacters, individuals, personDirectory, innerGroupDirectories);
|
||||
(changes, collection) = GetPersonContainersGroup(mappingDefaultName, personBirthdayFormat, facesFileNameExtension, personCharacters, personDirectory, innerGroupDirectories);
|
||||
allChanges.AddRange(changes);
|
||||
results.AddRange(collection);
|
||||
}
|
||||
@ -241,7 +236,7 @@ internal abstract class PersonContainer
|
||||
continue;
|
||||
personDirectory = new(@char, innerGroupDirectoryName, segments[zero][zero], segments[1][zero], segments[2][zero]);
|
||||
personDisplayDirectories = Directory.GetDirectories(innerGroupDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
(changes, collection) = GetPersonContainersGroup(mappingDefaultName, personBirthdayFormat, facesFileNameExtension, personCharacters, individuals, personDirectory, personDisplayDirectories);
|
||||
(changes, collection) = GetPersonContainersGroup(mappingDefaultName, personBirthdayFormat, facesFileNameExtension, personCharacters, personDirectory, personDisplayDirectories);
|
||||
allChanges.AddRange(changes);
|
||||
results.AddRange(collection);
|
||||
}
|
||||
@ -249,7 +244,7 @@ internal abstract class PersonContainer
|
||||
return new(allChanges, results);
|
||||
}
|
||||
|
||||
private static List<Models.PersonContainer> GetPersonContainersGroups(string mappingDefaultName, string personBirthdayFormat, string facesFileNameExtension, char[] personCharacters, ReadOnlyDictionary<string, string[]> individuals, string[] groupDirectories)
|
||||
private static List<Models.PersonContainer> GetPersonContainersGroups(string mappingDefaultName, string personBirthdayFormat, string facesFileNameExtension, char[] personCharacters, string[] groupDirectories)
|
||||
{
|
||||
List<Models.PersonContainer> results;
|
||||
const int zero = 0;
|
||||
@ -263,7 +258,7 @@ internal abstract class PersonContainer
|
||||
groupDirectoryName = Path.GetFileName(groupDirectory);
|
||||
if (!personCharacters.Contains(groupDirectoryName[zero]))
|
||||
continue;
|
||||
(changes, collection) = GetPersonContainersInnerGroups(mappingDefaultName, personBirthdayFormat, facesFileNameExtension, personCharacters, individuals, groupDirectory, groupDirectoryName);
|
||||
(changes, collection) = GetPersonContainersInnerGroups(mappingDefaultName, personBirthdayFormat, facesFileNameExtension, personCharacters, groupDirectory, groupDirectoryName);
|
||||
allChanges.AddRange(changes);
|
||||
personContainers.AddRange(collection);
|
||||
}
|
||||
@ -273,7 +268,7 @@ internal abstract class PersonContainer
|
||||
return results;
|
||||
}
|
||||
|
||||
internal static List<Models.PersonContainer> GetPersonContainers(Properties.IStorage storage, string mappingDefaultName, string personBirthdayFormat, char[] personCharacters, string facesFileNameExtension, ReadOnlyDictionary<string, string[]> individuals)
|
||||
internal static List<Models.PersonContainer> GetPersonContainers(Properties.IStorage storage, string mappingDefaultName, string personBirthdayFormat, char[] personCharacters, string facesFileNameExtension)
|
||||
{
|
||||
List<Models.PersonContainer> results;
|
||||
string a2PeopleSingletonDirectory = Path.Combine(storage.PeopleRootDirectory, "{}");
|
||||
@ -290,7 +285,7 @@ internal abstract class PersonContainer
|
||||
if (!groupDirectories.Any())
|
||||
results = new();
|
||||
else
|
||||
results = GetPersonContainersGroups(mappingDefaultName, personBirthdayFormat, facesFileNameExtension, personCharacters, individuals, groupDirectories);
|
||||
results = GetPersonContainersGroups(mappingDefaultName, personBirthdayFormat, facesFileNameExtension, personCharacters, groupDirectories);
|
||||
return results;
|
||||
}
|
||||
|
||||
@ -329,34 +324,7 @@ internal abstract class PersonContainer
|
||||
return results;
|
||||
}
|
||||
|
||||
internal static List<Models.PersonContainer> GetNonSpecificPeopleCollection(string mappingDefaultName, int personBirthdayFirstYear, char[] personCharacters, List<Models.PersonContainer> personContainers, long ticks)
|
||||
{
|
||||
List<Models.PersonContainer> results = new();
|
||||
long personKey;
|
||||
Models.Person person;
|
||||
int? approximateYears = null;
|
||||
Models.PersonBirthday personBirthday;
|
||||
Models.PersonContainer personContainer;
|
||||
List<long> personKeys = GetPersonKeys(personContainers);
|
||||
string[] personDisplayDirectoryAllFiles = Array.Empty<string>();
|
||||
DateTime incrementDate = new(personBirthdayFirstYear, 1, 1);
|
||||
for (int i = 0; i < int.MaxValue; i++)
|
||||
{
|
||||
personKey = incrementDate.Ticks;
|
||||
incrementDate = incrementDate.AddDays(1);
|
||||
if (incrementDate.Ticks > ticks)
|
||||
break;
|
||||
if (personKeys.Contains(personKey))
|
||||
continue;
|
||||
personBirthday = IPersonBirthday.GetPersonBirthday(personKey);
|
||||
person = IPerson.GetPerson(mappingDefaultName, personCharacters, mappingDefaultName, personKey, personBirthday);
|
||||
personContainer = new(approximateYears, new Models.PersonBirthday[] { personBirthday }, personDisplayDirectoryAllFiles, mappingDefaultName, personKey, person);
|
||||
results.Add(personContainer);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private static ReadOnlyDictionary<string, string> GetPersonKeyFormattedToPersonFullName(string personBirthdayFormat, List<Models.PersonContainer> personContainers)
|
||||
internal static ReadOnlyDictionary<string, string> GetPersonKeyFormattedToPersonFullName(string personBirthdayFormat, ReadOnlyCollection<Models.PersonContainer> personContainers)
|
||||
{
|
||||
Dictionary<string, string> results = new();
|
||||
string? value;
|
||||
@ -376,118 +344,4 @@ internal abstract class PersonContainer
|
||||
return new(results);
|
||||
}
|
||||
|
||||
private static ReadOnlyDictionary<int, List<GenealogicalDataCommunicationRelation>> GetFamilyIndexToCollection(List<GenealogicalDataCommunicationRelation> genealogicalDataCommunicationRelations)
|
||||
{
|
||||
Dictionary<int, List<GenealogicalDataCommunicationRelation>> results = new();
|
||||
List<GenealogicalDataCommunicationRelation>? relations;
|
||||
foreach (GenealogicalDataCommunicationRelation genealogicalDataCommunicationRelation in genealogicalDataCommunicationRelations)
|
||||
{
|
||||
if (!results.TryGetValue(genealogicalDataCommunicationRelation.FamilyIndex, out relations))
|
||||
{
|
||||
results.Add(genealogicalDataCommunicationRelation.FamilyIndex, new());
|
||||
if (!results.TryGetValue(genealogicalDataCommunicationRelation.FamilyIndex, out relations))
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
relations.Add(genealogicalDataCommunicationRelation);
|
||||
}
|
||||
return new(results);
|
||||
}
|
||||
|
||||
private static void WriteAll(long ticks, string a2PeopleContentDirectory, List<string[]> frontMatterLinesCollections, string weekOfYear)
|
||||
{
|
||||
string json;
|
||||
string[] segments;
|
||||
string? directory;
|
||||
string frontMatterLastLine;
|
||||
DateTime dateTime = new(ticks);
|
||||
List<string> allFrontMatterLines = new();
|
||||
foreach (string[] frontMatterLines in frontMatterLinesCollections)
|
||||
{
|
||||
allFrontMatterLines.Add("{");
|
||||
frontMatterLastLine = frontMatterLines.Last();
|
||||
foreach (string frontMatterLine in frontMatterLines)
|
||||
{
|
||||
segments = frontMatterLine.Split(": ");
|
||||
if (segments.Length != 2)
|
||||
continue;
|
||||
if (frontMatterLine == frontMatterLastLine)
|
||||
allFrontMatterLines.Add($"\"{string.Join("\": ", segments)}");
|
||||
else
|
||||
allFrontMatterLines.Add($"\"{string.Join("\": ", segments)},");
|
||||
}
|
||||
allFrontMatterLines.Add("},");
|
||||
}
|
||||
directory = Path.Combine(a2PeopleContentDirectory, $"{dateTime.Year}-Markdown", $"{dateTime.Year}-Week-{weekOfYear}", ticks.ToString());
|
||||
if (!Directory.Exists(directory))
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
json = $"[{string.Join(Environment.NewLine, allFrontMatterLines.ToArray(), 0, allFrontMatterLines.Count - 1)}{allFrontMatterLines.Last()[..^1]}]";
|
||||
Models.GenealogicalDataCommunication[]? genealogicalDataCommunications = JsonSerializer.Deserialize(json, GenealogicalDataCommunicationSourceCollectionGenerationContext.Default.GenealogicalDataCommunicationArray);
|
||||
if (genealogicalDataCommunications is null)
|
||||
throw new NullReferenceException(nameof(genealogicalDataCommunications));
|
||||
json = JsonSerializer.Serialize(genealogicalDataCommunications, GenealogicalDataCommunicationSourceCollectionGenerationContext.Default.GenealogicalDataCommunicationArray);
|
||||
_ = IPath.WriteAllText(Path.Combine(directory, $"{ticks}.json"), json, updateDateWhenMatches: false, compareBeforeWrite: true);
|
||||
}
|
||||
|
||||
internal static void MaybeWriteMarkDownFiles(string mappingDefaultName, string personBirthdayFormat, long ticks, List<GenealogicalDataCommunicationRelation> genealogicalDataCommunicationRelations, List<Models.PersonContainer> personContainers, string a2PeopleContentDirectory)
|
||||
{
|
||||
bool? male;
|
||||
bool? first;
|
||||
string fullName;
|
||||
string[] matches;
|
||||
string? directory;
|
||||
bool isDefaultName;
|
||||
const int zero = 0;
|
||||
string personKeyFormatted;
|
||||
string lowerHyphenFullName;
|
||||
List<string> frontMatterLines;
|
||||
string pattern = "[^a-z0-9-]";
|
||||
DateTime dateTime = new(ticks);
|
||||
Calendar calendar = new CultureInfo("en-US").Calendar;
|
||||
List<(string? Id, string[] FrontMatterLines)> collection = new();
|
||||
Models.GenealogicalDataCommunication genealogicalDataCommunication;
|
||||
GenealogicalDataCommunicationLines? genealogicalDataCommunicationLines;
|
||||
string weekOfYear = calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
|
||||
ReadOnlyDictionary<string, string> personKeyFormattedToPersonFullName = GetPersonKeyFormattedToPersonFullName(personBirthdayFormat, personContainers);
|
||||
ReadOnlyDictionary<int, List<GenealogicalDataCommunicationRelation>> familyIndexToCollection = GetFamilyIndexToCollection(genealogicalDataCommunicationRelations);
|
||||
foreach (Models.PersonContainer personContainer in personContainers.OrderByDescending(l => l.Key))
|
||||
{
|
||||
if (personContainer.Key is null || personContainer.Birthdays is null || personContainer.Person is null || personContainer.PersonDirectory is null || !personContainer.Birthdays.Any())
|
||||
continue;
|
||||
male = personContainer.PersonDirectory.Sex == 'U' ? null : personContainer.PersonDirectory.Sex == 'M' || (personContainer.PersonDirectory.Sex == 'F' ? false : throw new Exception());
|
||||
first = personContainer.PersonDirectory.First == 'U' ? null : personContainer.PersonDirectory.First == 'Y' || (personContainer.PersonDirectory.First == 'N' ? false : throw new Exception());
|
||||
if (first is null)
|
||||
continue;
|
||||
isDefaultName = IPerson.IsDefaultName(mappingDefaultName, personContainer.DisplayDirectoryName);
|
||||
personKeyFormatted = IPersonBirthday.GetFormatted(personBirthdayFormat, personContainer.Key.Value);
|
||||
matches = (from l in personContainer.DisplayDirectoryAllFiles where l.Contains(personKeyFormatted) select l).ToArray();
|
||||
if (!matches.Any())
|
||||
continue;
|
||||
directory = Path.GetDirectoryName(matches[zero]);
|
||||
if (directory is null)
|
||||
continue;
|
||||
genealogicalDataCommunicationLines = personContainer.GenealogicalDataCommunicationRelationIndividualsLines is null ? null : GenealogicalDataCommunication.GetGenealogicalDataCommunicationLines(personContainer.Birthdays[zero], personContainer.GenealogicalDataCommunicationRelationIndividualsLines);
|
||||
if (genealogicalDataCommunicationLines is null)
|
||||
continue;
|
||||
genealogicalDataCommunication = GenealogicalDataCommunication.GetGenealogicalDataCommunication(first.Value, genealogicalDataCommunicationLines);
|
||||
if (genealogicalDataCommunication.Sex != personContainer.PersonDirectory.Sex)
|
||||
continue;
|
||||
if (genealogicalDataCommunication.Birth is not null && !directory.EndsWith(genealogicalDataCommunication.Birth.Value.Hour.ToString()))
|
||||
continue;
|
||||
if (genealogicalDataCommunication.Death is null && personContainer.PersonDirectory.Status == 'D' || genealogicalDataCommunication.Death is not null && personContainer.PersonDirectory.Status == 'A')
|
||||
continue;
|
||||
fullName = PersonName.GetFullName(personContainer.Person.Name);
|
||||
lowerHyphenFullName = $"{Regex.Replace(fullName.ToLower(), pattern, "-")}";
|
||||
frontMatterLines = MarkDown.GetFrontMatterLines(ticks, fullName, lowerHyphenFullName, genealogicalDataCommunication);
|
||||
if (!frontMatterLines.Any())
|
||||
continue;
|
||||
collection.Add((genealogicalDataCommunication.Id, frontMatterLines.ToArray()));
|
||||
MarkDown.WriteFile(personKeyFormatted, ticks, genealogicalDataCommunicationRelations, a2PeopleContentDirectory, calendar, pattern, personKeyFormattedToPersonFullName, familyIndexToCollection, genealogicalDataCommunication, fullName, lowerHyphenFullName, frontMatterLines);
|
||||
}
|
||||
if (collection.Any())
|
||||
{
|
||||
List<string[]> frontMatterLinesCollections = (from l in collection orderby l.Id.Length, l.Id where l.Id is not null select l.FrontMatterLines).ToList();
|
||||
WriteAll(ticks, a2PeopleContentDirectory, frontMatterLinesCollections, weekOfYear);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user