Person Sex
This commit is contained in:
		| @ -115,6 +115,7 @@ public partial class DlibDotNet | |||||||
|             if (rootResultsDirectory is null) |             if (rootResultsDirectory is null) | ||||||
|                 throw new Exception(); |                 throw new Exception(); | ||||||
|             Storage storage = new(rootDirectory, rootResultsDirectory, peopleRootDirectory); |             Storage storage = new(rootDirectory, rootResultsDirectory, peopleRootDirectory); | ||||||
|  |             _ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(Path.Combine(peopleRootDirectory, "{}")); | ||||||
|             _PersonContainers = Shared.Models.Stateless.Methods.IPersonContainer.GetPersonContainers(storage, configuration.PersonBirthdayFormat, configuration.PersonCharacters.ToArray(), _Faces.FileNameExtension); |             _PersonContainers = Shared.Models.Stateless.Methods.IPersonContainer.GetPersonContainers(storage, configuration.PersonBirthdayFormat, configuration.PersonCharacters.ToArray(), _Faces.FileNameExtension); | ||||||
|         } |         } | ||||||
|         { |         { | ||||||
| @ -1046,11 +1047,10 @@ public partial class DlibDotNet | |||||||
|     private void CreateTree(PersonContainer[] personContainers, long ticks, string a2PeopleContentDirectory, Dictionary<long, List<int>> personKeyToIds) |     private void CreateTree(PersonContainer[] personContainers, long ticks, string a2PeopleContentDirectory, Dictionary<long, List<int>> personKeyToIds) | ||||||
|     { |     { | ||||||
|         string by; |         string by; | ||||||
|         string directory; |  | ||||||
|         string[] matches; |         string[] matches; | ||||||
|         string[] segments; |  | ||||||
|         const int zero = 0; |         const int zero = 0; | ||||||
|         string[] pGedFiles; |         string[] pGedFiles; | ||||||
|  |         string[] pGedLines; | ||||||
|         string personKeyFormatted; |         string personKeyFormatted; | ||||||
|         List<long> distinct = new(); |         List<long> distinct = new(); | ||||||
|         PersonBirthday personBirthday; |         PersonBirthday personBirthday; | ||||||
| @ -1089,15 +1089,16 @@ public partial class DlibDotNet | |||||||
|             pGedFiles = (from l in matches where l.EndsWith(".pged") select l).ToArray(); |             pGedFiles = (from l in matches where l.EndsWith(".pged") select l).ToArray(); | ||||||
|             if (!pGedFiles.Any()) |             if (!pGedFiles.Any()) | ||||||
|                 continue; |                 continue; | ||||||
|             lines.AddRange(File.ReadAllLines(pGedFiles[0])); |             pGedLines = File.ReadAllLines(pGedFiles[0]); | ||||||
|             segments = personContainer.DisplayDirectoryName.Split(_Configuration.PersonCharacters.ToArray()); |             lines.AddRange(pGedLines); | ||||||
|             if (segments.Length < 2) |             // segments = personContainer.DisplayDirectoryName.Split(_Configuration.PersonCharacters.ToArray()); | ||||||
|                 directory = Path.Combine(rootDirectory, $"000 {personKeyFormatted} {personContainer.DisplayDirectoryName}"); |             // if (segments.Length < 2) | ||||||
|             else |             //     directory = Path.Combine(rootDirectory, $"000 {personKeyFormatted} {personContainer.DisplayDirectoryName}"); | ||||||
|                 directory = Path.Combine(rootDirectory, $"{segments[1].PadLeft(3, '0')} {personKeyFormatted} {personContainer.DisplayDirectoryName}"); |             // else | ||||||
|             if (Directory.Exists(directory)) |             //     directory = Path.Combine(rootDirectory, $"{segments[1].PadLeft(3, '0')} {personKeyFormatted} {personContainer.DisplayDirectoryName}"); | ||||||
|                 continue; |             // if (Directory.Exists(directory)) | ||||||
|             _ = Directory.CreateDirectory(directory); |             //     continue; | ||||||
|  |             // _ = Directory.CreateDirectory(directory); | ||||||
|         } |         } | ||||||
|         lines.Add("0 TRLR"); |         lines.Add("0 TRLR"); | ||||||
|         File.WriteAllLines(Path.Combine(a2PeopleContentDirectory, $"{ticks}.ged"), lines); |         File.WriteAllLines(Path.Combine(a2PeopleContentDirectory, $"{ticks}.ged"), lines); | ||||||
|  | |||||||
| @ -1,5 +1,3 @@ | |||||||
| using System.Text; |  | ||||||
|  |  | ||||||
| namespace View_by_Distance.Shared.Models.Stateless.Methods; | namespace View_by_Distance.Shared.Models.Stateless.Methods; | ||||||
|  |  | ||||||
| internal abstract class Person | internal abstract class Person | ||||||
| @ -17,38 +15,86 @@ internal abstract class Person | |||||||
|         return new(personBirthday, personKeyFormatted); |         return new(personBirthday, personKeyFormatted); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private static void WriteGedFile(string? personKeyFormatted, Models.PersonBirthday personBirthday, Models.PersonName name, string[] matches) |     private static void WriteGedFile(string personKeyFormatted, Models.PersonBirthday personBirthday, Models.PersonName name, string[] matches) | ||||||
|     { |     { | ||||||
|         string[] pGedFiles = (from l in matches where l.EndsWith(".pged") select l).ToArray(); |         string[] pGedFiles = (from l in matches where l.EndsWith(".pged") select l).ToArray(); | ||||||
|         if (!pGedFiles.Any()) |         if (!pGedFiles.Any()) | ||||||
|         { |         { | ||||||
|             StringBuilder stringBuilder = new(); |  | ||||||
|             _ = stringBuilder.Append("0 @I").Append(personKeyFormatted).AppendLine("@ INDI"); |  | ||||||
|             _ = stringBuilder.Append("1 NAME ").Append(name.First.Value).Append(" /").Append(name.Last.Value).AppendLine("/"); |  | ||||||
|             if (!string.IsNullOrEmpty(name.First.Value)) |  | ||||||
|                 _ = stringBuilder.Append("2 GIVN ").AppendLine(name.First.Value); |  | ||||||
|             if (!string.IsNullOrEmpty(name.Last.Value)) |  | ||||||
|                 _ = stringBuilder.Append("2 SURN ").AppendLine(name.Last.Value); |  | ||||||
|             if (!string.IsNullOrEmpty(name.Alias.Value)) |  | ||||||
|             { |  | ||||||
|                 _ = stringBuilder.Append("2 NICK ").AppendLine(name.Alias.Value); |  | ||||||
|                 if (name.Alias.Value.Contains(" Jr")) |  | ||||||
|                     _ = stringBuilder.Append("2 NSFX ").AppendLine("Jr"); |  | ||||||
|                 else if (name.Alias.Value.Contains(" Sr")) |  | ||||||
|                     _ = stringBuilder.Append("2 NSFX ").AppendLine("Sr"); |  | ||||||
|             } |  | ||||||
|             _ = stringBuilder.AppendLine("1 SEX U"); |  | ||||||
|             if (!IPersonBirthday.IsCounterPersonBirthday(personBirthday)) |  | ||||||
|             { |  | ||||||
|                 _ = stringBuilder.AppendLine("1 BIRT"); |  | ||||||
|                 _ = stringBuilder.Append("2 DATE ").AppendLine(personBirthday.Value.ToString("dd MMM yyyy")); |  | ||||||
|             } |  | ||||||
|             string? directory = Path.GetDirectoryName(matches[0]); |             string? directory = Path.GetDirectoryName(matches[0]); | ||||||
|             if (directory is null) |             if (directory is null) | ||||||
|                 throw new Exception(); |                 throw new Exception(); | ||||||
|  |             List<string> pGedLines = new(); | ||||||
|  |             string nameLine = $"1 NAME {name.First.Value} /{name.Last.Value}/"; | ||||||
|  |             pGedLines.Add($"0 @I{personKeyFormatted}@ INDI"); | ||||||
|  |             pGedLines.Add(nameLine); | ||||||
|  |             if (!string.IsNullOrEmpty(name.First.Value)) | ||||||
|  |                 pGedLines.Add($"2 GIVN {name.First.Value}"); | ||||||
|  |             if (!string.IsNullOrEmpty(name.Last.Value)) | ||||||
|  |                 pGedLines.Add($"2 SURN {name.Last.Value}"); | ||||||
|  |             if (!string.IsNullOrEmpty(name.Alias.Value)) | ||||||
|  |             { | ||||||
|  |                 pGedLines.Add($"2 NICK {name.Alias.Value}"); | ||||||
|  |                 if (name.Alias.Value.Contains(" Jr")) | ||||||
|  |                     pGedLines.Add("2 NSFX Jr"); | ||||||
|  |                 else if (name.Alias.Value.Contains(" Sr")) | ||||||
|  |                     pGedLines.Add("2 NSFX Sr"); | ||||||
|  |             } | ||||||
|  |             if (personKeyFormatted[^2..] == "06") | ||||||
|  |                 pGedLines.Add("1 SEX F"); | ||||||
|  |             else if (personKeyFormatted[^2..] == "13") | ||||||
|  |                 pGedLines.Add("1 SEX M"); | ||||||
|  |             else | ||||||
|  |             { | ||||||
|  |                 string? sexLine = null; | ||||||
|  |                 string[] sourceLines = File.ReadAllLines("D:/1) Images A/Images-9b89679-Results/A2) People/9b89679/([])/FamilyEcho/638157228251558818-RootsMagic-Export.ged"); | ||||||
|  |                 for (int i = 0; i < sourceLines.Length; i++) | ||||||
|  |                 { | ||||||
|  |                     if (sourceLines[i] != nameLine) | ||||||
|  |                         continue; | ||||||
|  |                     for (int j = i + 1; j < sourceLines.Length; j++) | ||||||
|  |                     { | ||||||
|  |                         i = j; | ||||||
|  |                         if (sourceLines[j].StartsWith("0 @I")) | ||||||
|  |                             break; | ||||||
|  |                         if (sourceLines[j].StartsWith("1 SEX ")) | ||||||
|  |                         { | ||||||
|  |                             sexLine = sourceLines[j]; | ||||||
|  |                             break; | ||||||
|  |                         } | ||||||
|  |                     } | ||||||
|  |                     if (sexLine is not null) | ||||||
|  |                         break; | ||||||
|  |                 } | ||||||
|  |                 if (sexLine is null) | ||||||
|  |                     pGedLines.Add("1 SEX U"); | ||||||
|  |                 else | ||||||
|  |                 { | ||||||
|  |                     pGedLines.Add($"1 SEX {sexLine[6]}"); | ||||||
|  |                     string sex = sexLine[6] is 'F' ? "06" : sexLine[6] is 'M' ? "13" : sexLine[6] is 'U' ? "21" : throw new NotImplementedException(); | ||||||
|  |                     if (directory.EndsWith("00")) | ||||||
|  |                         directory = string.Concat(directory[..^2], sex); | ||||||
|  |                     else if (directory.EndsWith("01")) | ||||||
|  |                         directory = string.Concat(directory[..^2], sex); | ||||||
|  |                     else if (directory.EndsWith("05")) // Daisy  | ||||||
|  |                         directory = string.Concat(directory[..^2], sex); | ||||||
|  |                     else if (directory.EndsWith("18")) // Meghan | ||||||
|  |                         directory = string.Concat(directory[..^2], sex); | ||||||
|  |                     else if (directory.EndsWith("20")) // Joey | ||||||
|  |                         directory = string.Concat(directory[..^2], sex); | ||||||
|  |                     else | ||||||
|  |                         throw new NotImplementedException(); | ||||||
|  |                     personKeyFormatted = $"{personKeyFormatted[..^2]}{sex}"; | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |             if (!IPersonBirthday.IsCounterPersonBirthday(personBirthday)) | ||||||
|  |             { | ||||||
|  |                 pGedLines.Add("1 BIRT"); | ||||||
|  |                 pGedLines.Add($"2 DATE {personBirthday.Value:dd MMM yyyy}"); | ||||||
|  |             } | ||||||
|             if (!Directory.Exists(directory)) |             if (!Directory.Exists(directory)) | ||||||
|                 _ = Directory.CreateDirectory(directory); |                 _ = Directory.CreateDirectory(directory); | ||||||
|             File.WriteAllText(Path.Combine(directory, $"{personKeyFormatted}.pged"), stringBuilder.ToString()); |             string text = string.Join(Environment.NewLine, pGedLines); | ||||||
|  |             _ = IPath.WriteAllText(Path.Combine(directory, $"{personKeyFormatted}.pged"), text, updateDateWhenMatches: false, compareBeforeWrite: true); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @ -64,7 +110,7 @@ internal abstract class Person | |||||||
|         List<Models.PersonAddress> addresses = new(); |         List<Models.PersonAddress> addresses = new(); | ||||||
|         Models.PersonName name = PersonName.Create(segments[zero]); |         Models.PersonName name = PersonName.Create(segments[zero]); | ||||||
|         string[] matches = (from l in personDisplayDirectoryAllFiles where !string.IsNullOrEmpty(personKeyFormatted) && l.Contains(personKeyFormatted) select l).ToArray(); |         string[] matches = (from l in personDisplayDirectoryAllFiles where !string.IsNullOrEmpty(personKeyFormatted) && l.Contains(personKeyFormatted) select l).ToArray(); | ||||||
|         if (matches.Any()) |         if (!string.IsNullOrEmpty(personKeyFormatted) && matches.Any()) | ||||||
|             WriteGedFile(personKeyFormatted, personBirthday, name, matches); |             WriteGedFile(personKeyFormatted, personBirthday, name, matches); | ||||||
|         result = new(id, personBirthday, name, comments, urls, numbers, emails, addresses); |         result = new(id, personBirthday, name, comments, urls, numbers, emails, addresses); | ||||||
|         return result; |         return result; | ||||||
|  | |||||||
| @ -124,11 +124,10 @@ internal abstract class PersonBirthday | |||||||
|                 continue; |                 continue; | ||||||
|             if (!IPersonBirthday.IsCounterPersonBirthday(personBirthday) && ((!personKeyDirectory.Contains('#') && (personDisplayDirectoryName.Contains('~') || personDisplayDirectoryName.Contains('#'))) || (personKeyDirectory.Contains('#') && !personDisplayDirectoryName.Contains('#')))) |             if (!IPersonBirthday.IsCounterPersonBirthday(personBirthday) && ((!personKeyDirectory.Contains('#') && (personDisplayDirectoryName.Contains('~') || personDisplayDirectoryName.Contains('#'))) || (personKeyDirectory.Contains('#') && !personDisplayDirectoryName.Contains('#')))) | ||||||
|                 throw new NotSupportedException(); |                 throw new NotSupportedException(); | ||||||
|             results.Add(new(personKeyFormatted, personBirthday)); |  | ||||||
|             files = Directory.GetFiles(personKeyDirectory, "*", SearchOption.TopDirectoryOnly); |             files = Directory.GetFiles(personKeyDirectory, "*", SearchOption.TopDirectoryOnly); | ||||||
|             if (files.Any()) |             if (!files.Any()) | ||||||
|                 continue; |                 continue; | ||||||
|             File.WriteAllText(Path.Combine(personKeyDirectory, $"{personKeyFormatted}.txt"), string.Empty); |             results.Add(new(personKeyFormatted, personBirthday)); | ||||||
|         } |         } | ||||||
|         return results; |         return results; | ||||||
|     } |     } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user