Complete Class bug fix

This commit is contained in:
Mike Phares 2024-11-01 17:04:20 -07:00
parent 2b16357d44
commit dcaaba3614
7 changed files with 44 additions and 29 deletions

View File

@ -49,6 +49,16 @@
],
"problemMatcher": "$msCompile"
},
{
"label": "Format-Whitespaces",
"command": "dotnet",
"type": "process",
"args": [
"format",
"whitespace"
],
"problemMatcher": "$msCompile"
},
{
"label": "Nuget Clear",
"command": "dotnet",

View File

@ -20,28 +20,28 @@ internal class Complete
public Summary Summary { get; }
public ReadOnlyCollection<Point> Points { get; }
public static Complete? Get(int take, string site, string multiple, string summaryLine, string lastUnits, string[] lines)
public static Complete? Get(int take, string site, string multiple, string summaryLine, string lastUnits, string lastUnitsB, ReadOnlyCollection<string> lines)
{
Complete? result;
Header? header = Header.Get(lines, site, summaryLine);
if (header is null)
result = null;
else
{
Complete? result;
Header? header = Header.Get(lines, site, summaryLine);
if (header is null)
Summary? summary = SummarySegment.Get(lines, site, summaryLine, lastUnits);
if (summary is null)
result = null;
else
{
Summary? summary = SummarySegment.Get(lines, site, summaryLine);
if (summary is null)
ReadOnlyCollection<Point> points = Point.GetCollection(lines, take, site, multiple, summaryLine, lastUnitsB) ?? throw new NullReferenceException(nameof(summary));
if (points.Count == 0)
result = null;
else
{
ReadOnlyCollection<Point> points = Point.GetCollection(lines, take, site, multiple, summaryLine, lastUnits) ?? throw new NullReferenceException(nameof(summary));
if (points.Count == 0)
result = null;
else
result = new(header, summary, points);
}
result = new(header, summary, points);
}
return result;
}
return result;
}
}
@ -49,4 +49,4 @@ internal class Complete
[JsonSerializable(typeof(Complete))]
internal partial class CompleteSourceGenerationContext : JsonSerializerContext
{
}
}

View File

@ -128,7 +128,7 @@ internal class Header
return new(results);
}
public static Header? Get(string[] lines, string site, string summaryLine)
public static Header? Get(ReadOnlyCollection<string> lines, string site, string summaryLine)
{
Header? result;
string json;
@ -185,4 +185,4 @@ internal class Header
[JsonSerializable(typeof(Header))]
internal partial class HeaderSourceGenerationContext : JsonSerializerContext
{
}
}

View File

@ -77,7 +77,7 @@ internal class Point
string.Empty,
string.Empty);
public static ReadOnlyCollection<Point> GetCollection(string[] lines, int take, string site, string multiple, string summaryLine, string lastUnits)
public static ReadOnlyCollection<Point> GetCollection(ReadOnlyCollection<string> lines, int take, string site, string multiple, string summaryLine, string lastUnitsB)
{
List<Point> results = new();
string s;
@ -89,7 +89,7 @@ internal class Point
bool foundB = false;
string[] segmentsC;
List<string> sites = new();
for (int i = 0; i < lines.Length; i++)
for (int i = 0; i < lines.Count; i++)
{
line = lines[i];
segmentsC = line.Split(new string[] { site }, StringSplitOptions.RemoveEmptyEntries);
@ -107,7 +107,7 @@ internal class Point
continue;
if (!foundB && line.Contains(multiple))
foundB = true;
if (line != lastUnits)
if (line != lastUnitsB)
continue;
if (foundB)
{
@ -117,7 +117,7 @@ internal class Point
for (int j = 0; j < sites.Count; j++)
{
s = sites[j];
if (i + take > lines.Length)
if (i + take > lines.Count)
break;
segments = s.Split(new string[] { "(", ",", ")" }, StringSplitOptions.None);
if (segments.Length < 2)
@ -154,4 +154,4 @@ internal class Point
[JsonSerializable(typeof(Point))]
internal partial class PointSourceGenerationContext : JsonSerializerContext
{
}
}

View File

@ -3,6 +3,7 @@ using Adaptation.Shared.Methods;
using log4net;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Diagnostics;
using System.IO;
@ -540,13 +541,15 @@ public class ProcessData : IProcessData
const string multiple = "MULTIPLE";
const string summaryLine = "SUMMARY A A";
const string lastUnits = "Flat Z: Grade : % Flat Z: Grade : % Flat Z: Grade : %";
const string lastUnitsB = "Flat Z: Grade : % Flat Z: Grade : % Flat Z: Grade : %";
string[] lines = File.ReadAllLines(altHeaderFileName);
if (lines.Length > take)
result = Complete.Get(take, site, multiple, summaryLine, lastUnits, lines);
ReadOnlyCollection<string> collection = new(lines);
if (collection.Count > take)
result = Complete.Get(take, site, multiple, summaryLine, lastUnits, lastUnitsB, collection);
else
{
result = null;
_Log.Warn($"File {altHeaderFileName} has less than 5 lines");
_Log.Warn($"File {altHeaderFileName} has less than {take} collection");
}
return result;
}

View File

@ -16,4 +16,4 @@ internal class Summary
public SummarySegment? StandardDeviationPercentage { get; }
public SummarySegment? RadialGradient { get; }
}
}

View File

@ -66,7 +66,7 @@ internal class SummarySegment
return new(results);
}
public static Summary? Get(string[] lines, string site, string summaryLine)
public static Summary? Get(ReadOnlyCollection<string> lines, string site, string summaryLine, string lastUnits)
{
Summary? result;
string json;
@ -85,10 +85,12 @@ internal class SummarySegment
continue;
if (line.Contains(site))
break;
if (line.Contains(lastUnits))
break;
foreach (JsonProperty jsonProperty in jsonProperties)
{
segments = line.Split(new string[] { $"{jsonProperty.Name}:", $"{jsonProperty.Name} :" }, StringSplitOptions.None);
if (segments.Length < 2 || !line.StartsWith(jsonProperty.Name))
if (segments.Length < 2 || (!line.StartsWith(jsonProperty.Name) && !line.StartsWith($"@ {jsonProperty.Name}")))
continue;
segmentsB = segments[1].Trim().Split(' ');
if (segmentsB.Length < 3)
@ -119,4 +121,4 @@ internal class SummarySegment
[JsonSerializable(typeof(SummarySegment))]
internal partial class SummarySegmentSourceGenerationContext : JsonSerializerContext
{
}
}