diff --git a/Adaptation/FileHandlers/pcl/Complete.cs b/Adaptation/FileHandlers/pcl/Complete.cs index ce3a8db..17adda1 100644 --- a/Adaptation/FileHandlers/pcl/Complete.cs +++ b/Adaptation/FileHandlers/pcl/Complete.cs @@ -23,26 +23,41 @@ internal class Complete public Summary Summary { get; } public ReadOnlyCollection Points { get; } - public static Complete? Get(Shared.Logistics logistics, List fileInfoCollection, ReadOnlyCollection lines) + private static ReadOnlyCollection FilterLines(ReadOnlyCollection collection) + { + List results = new(); + foreach (string line in collection) + { + if (string.IsNullOrEmpty(line) || line is "*" or "@") + continue; + if (line.Length < 3 || line[0] is not '*' and not '@' || line[1] != ' ') + results.Add(line); + else + results.Add(line.Substring(2)); + } + return new(results); + } + + public static Complete? Get(Shared.Logistics logistics, List fileInfoCollection, ReadOnlyCollection collection) { Complete? result; Constant constant = new(); - ReadOnlyCollection collection = new(lines); + ReadOnlyCollection lines = FilterLines(collection); if (collection.Count <= constant.Take) result = null; else { - Header? header = Header.Get(constant, collection); + Header? header = Header.Get(constant, lines); if (header is null) result = null; else { - Summary? summary = SummarySegment.Get(constant, collection); + Summary? summary = SummarySegment.Get(constant, lines); if (summary is null) result = null; else { - ReadOnlyCollection points = Point.GetCollection(constant, collection) ?? throw new NullReferenceException(nameof(summary)); + ReadOnlyCollection points = Point.GetCollection(constant, lines) ?? throw new NullReferenceException(nameof(summary)); if (points.Count == 0) result = null; else diff --git a/Adaptation/FileHandlers/pcl/Constant.cs b/Adaptation/FileHandlers/pcl/Constant.cs index d3e5613..129bd11 100644 --- a/Adaptation/FileHandlers/pcl/Constant.cs +++ b/Adaptation/FileHandlers/pcl/Constant.cs @@ -3,7 +3,7 @@ namespace Adaptation.FileHandlers.pcl; internal class Constant { - public int Take { get; } = 12; + public int Take { get; } = 11; public string Site { get; } = "Site: "; public string Multiple { get; } = "MULTIPLE"; public string SummaryLine { get; } = "SUMMARY A A"; diff --git a/Adaptation/FileHandlers/pcl/Point.cs b/Adaptation/FileHandlers/pcl/Point.cs index 1e02a4b..83767b8 100644 --- a/Adaptation/FileHandlers/pcl/Point.cs +++ b/Adaptation/FileHandlers/pcl/Point.cs @@ -71,8 +71,9 @@ internal class Point string[] segments; string[] segmentsB; bool found = false; - bool foundB = false; string[] segmentsC; + bool foundB = false; + int x = constant.Take - 2; List sites = new(); for (int i = 0; i < lines.Count; i++) { @@ -107,24 +108,24 @@ internal class Point segments = s.Split(new string[] { "(", ",", ")" }, StringSplitOptions.None); if (segments.Length < 2) break; - segmentsB = lines[i + 10].Split(' '); + segmentsB = lines[i + x].Split(' '); if (segmentsB.Length < 2) break; - point = new(segments[0].Trim(), - segments[1].Trim(), - segments[2].Trim(), - nAvg: lines[i + 2].Trim(), - nsl: lines[i + 3].Trim(), - vd: lines[i + 4].Trim(), - flatZ: lines[i + 5].Trim(), - rhoAvg: lines[i + 6].Trim(), - rhosl: lines[i + 7].Trim(), - phase: lines[i + 8].Trim(), - grade: lines[i + 9].Trim(), + point = new(site: segments[0].Trim(), + x: segments[1].Trim(), + y: segments[2].Trim(), + nAvg: lines[i + 1].Trim(), + nsl: lines[i + 2].Trim(), + vd: lines[i + 3].Trim(), + flatZ: lines[i + 4].Trim(), + rhoAvg: lines[i + 5].Trim(), + rhosl: lines[i + 6].Trim(), + phase: lines[i + 7].Trim(), + grade: lines[i + 8].Trim(), xLeft: segmentsB[0], xRight: segmentsB[1], - bottomY: lines[i + 11].Trim(), - topY: lines[i + 12].Trim()); + bottomY: lines[i + 10].Trim(), + topY: lines[i + 11].Trim()); results.Add(point); i += constant.Take; } diff --git a/Adaptation/FileHandlers/pcl/SummarySegment.cs b/Adaptation/FileHandlers/pcl/SummarySegment.cs index ba624ce..525cccc 100644 --- a/Adaptation/FileHandlers/pcl/SummarySegment.cs +++ b/Adaptation/FileHandlers/pcl/SummarySegment.cs @@ -28,12 +28,12 @@ internal class SummarySegment [JsonPropertyName("Navg")] public string NAvg { get; } [JsonPropertyName("Nsl")] public string Nsl { get; } [JsonPropertyName("Vd")] public string Vd { get; } - [JsonPropertyName("@ Flat Z")] public string FlatZ { get; } + [JsonPropertyName("Flat Z")] public string FlatZ { get; } [JsonPropertyName("Rhoavg")] public string RhoAvg { get; } [JsonPropertyName("Rhosl")] public string Rhosl { get; } [JsonPropertyName("Phase")] public string Phase { get; } [JsonPropertyName("Grade")] public string Grade { get; } - [JsonPropertyName("@ Rs")] public string Rs { get; } + [JsonPropertyName("Rs")] public string Rs { get; } public static SummarySegment Get() => new(string.Empty, @@ -64,6 +64,7 @@ internal class SummarySegment string[] segments; bool found = false; string[] segmentsB; + List names = new(); Dictionary keyValuePairs = new(); Dictionary keyValuePairsB = new(); Dictionary keyValuePairsC = new(); @@ -81,11 +82,14 @@ internal class SummarySegment foreach (JsonProperty jsonProperty in jsonProperties) { segments = line.Split(new string[] { $"{jsonProperty.Name}:", $"{jsonProperty.Name} :" }, StringSplitOptions.None); - if (segments.Length < 2 || (!line.StartsWith(jsonProperty.Name) && !line.StartsWith($"@ {jsonProperty.Name}"))) + if (segments.Length < 2 || !line.StartsWith(jsonProperty.Name)) continue; segmentsB = segments[1].Trim().Split(' '); if (segmentsB.Length < 3) continue; + if (names.Contains(jsonProperty.Name)) + continue; + names.Add(jsonProperty.Name); keyValuePairs.Add(jsonProperty.Name, segmentsB[0]); keyValuePairsB.Add(jsonProperty.Name, segmentsB[1]); keyValuePairsC.Add(jsonProperty.Name, segmentsB[2]);