Spreading Resistance Profile with ChartJS,
Copy-On-Get and nuget bump (Serilog)
This commit is contained in:
101
Server/Services/csv/ProfileHeader.cs
Normal file
101
Server/Services/csv/ProfileHeader.cs
Normal file
@ -0,0 +1,101 @@
|
||||
using System.Text;
|
||||
|
||||
namespace Adaptation.FileHandlers.csv;
|
||||
|
||||
public class ProfileHeader
|
||||
{
|
||||
|
||||
#nullable disable
|
||||
|
||||
public string NumberOfProfiles { get; set; }
|
||||
public List<Profile> Profiles { get; set; }
|
||||
public List<ProfilePoint> ProfilePoints { get; set; }
|
||||
|
||||
#nullable enable
|
||||
#pragma warning disable CA1834
|
||||
|
||||
internal static ProfileHeader? GetProfileHeader(string[] lines, int start, int stop)
|
||||
{
|
||||
ProfileHeader? result;
|
||||
string first;
|
||||
string[] segments;
|
||||
Profile profileInfo;
|
||||
ProfilePoint profile;
|
||||
int? thirdStart = null;
|
||||
int? secondStart = null;
|
||||
List<string> values = new();
|
||||
List<Profile> profiles = new();
|
||||
StringBuilder stringBuilder = new();
|
||||
List<ProfilePoint> profilePoints = new();
|
||||
for (int i = start; i < stop; i++)
|
||||
{
|
||||
segments = lines[i].Split(new string[] { "," }, StringSplitOptions.None);
|
||||
first = segments.First();
|
||||
if (first == "ID")
|
||||
{
|
||||
secondStart = i + 1;
|
||||
break;
|
||||
}
|
||||
_ = stringBuilder.Append(first).Append(",");
|
||||
if (segments.Length > 1)
|
||||
values.Add(segments[1]);
|
||||
else
|
||||
values.Add(string.Empty);
|
||||
}
|
||||
string header = "Number of Profiles,";
|
||||
if (secondStart is null || stringBuilder.Length != header.Length || stringBuilder.ToString() != header)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
result = new()
|
||||
{
|
||||
NumberOfProfiles = values[0],
|
||||
Profiles = profiles,
|
||||
ProfilePoints = profilePoints,
|
||||
};
|
||||
for (int i = secondStart.Value; i < stop; i++)
|
||||
{
|
||||
segments = lines[i].Split(new string[] { "," }, StringSplitOptions.None);
|
||||
first = segments.First();
|
||||
if (first == "Point")
|
||||
{
|
||||
thirdStart = i + 1;
|
||||
break;
|
||||
}
|
||||
if (segments.Length < 6)
|
||||
continue;
|
||||
profileInfo = new()
|
||||
{
|
||||
Id = segments[0],
|
||||
Name = segments[1],
|
||||
Label = segments[2],
|
||||
Allocated = segments[3],
|
||||
Used = segments[4],
|
||||
List = segments[5],
|
||||
};
|
||||
profiles.Add(profileInfo);
|
||||
}
|
||||
if (thirdStart is not null)
|
||||
{
|
||||
for (int i = thirdStart.Value; i < stop; i++)
|
||||
{
|
||||
segments = lines[i].Split(new string[] { "," }, StringSplitOptions.None);
|
||||
if (segments.Length < 6)
|
||||
continue;
|
||||
profile = new()
|
||||
{
|
||||
Number = segments[0],
|
||||
Depth = segments[1],
|
||||
Raw = segments[2],
|
||||
Edited = segments[3],
|
||||
Resistivity = segments[4],
|
||||
CD = segments[5],
|
||||
};
|
||||
profilePoints.Add(profile);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user