mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-18 22:45:59 +01:00
fix(tapes): the alerter of a physics log is read where its header puts it
The simulator's log has had a column of the vehicle's speed at its end since 2026-11 (master), and the alerter, counted six columns from the end past the free-text command, was read from the wheel slip instead. Its place from the end is taken from the "Security" heading of the file's header, and only a log with no header falls back to the old 25 columns.
This commit is contained in:
@@ -68,6 +68,24 @@ public class HaslerTapeTests
|
||||
Assert.Equal(5, tape.DistanceM, 6);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_security_flag_is_found_where_the_header_puts_it_with_the_vehicle_speed_at_the_end()
|
||||
{
|
||||
// the simulator's log since 2026-10: a column of the vehicle's speed after the temperatures
|
||||
string header = Header.Replace("WaterAuxTemp[Deg]\r\n", "WaterAuxTemp[Deg] VehicleVelocity[km/h]\r\n");
|
||||
static string WithSpeed(string line, double kmh) =>
|
||||
line.Replace("\r\n", string.Create(CultureInfo.InvariantCulture, $" {kmh:0.0000}\r\n"));
|
||||
// the wheels slipping, the alerter quiet: the column before the speed used to be read as the alerter
|
||||
string slipping = Line(0, 36, 0, 0, security: 0).Replace(" 0 0 0.0000 0.0000 0.0000 0.0000\r\n",
|
||||
" 0 1 0.0000 0.0000 0.0000 0.0000\r\n");
|
||||
|
||||
var tape = HaslerTape.Parse(header + WithSpeed(slipping, 36) + WithSpeed(Line(1, 36, 0, 0, security: 1), 36));
|
||||
|
||||
Assert.Equal(2, tape.Samples.Count);
|
||||
Assert.False(tape.Samples[0].SecurityAlarm);
|
||||
Assert.True(tape.Samples[1].SecurityAlarm);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_sample_under_a_point_of_the_tape_is_found_by_time_and_by_distance()
|
||||
{
|
||||
|
||||
@@ -29,13 +29,16 @@ public readonly record struct TapeSample(
|
||||
public sealed class HaslerTape
|
||||
{
|
||||
// Columns counted from the start; the security flag is counted from the end, past
|
||||
// the command, which is free text. The header says m/s and MPa, the values are km/h and bar.
|
||||
// the command, which is free text, as far from the end as the header has it: the
|
||||
// simulator adds a new column at the end (the vehicle's speed, 2026-10). The header
|
||||
// says m/s and MPa, the values are km/h and bar.
|
||||
private const int TimeColumn = 0;
|
||||
private const int VelocityColumn = 1;
|
||||
private const int BrakePressColumn = 8;
|
||||
private const int PipePressColumn = 9;
|
||||
private const int MotorCurrentColumn = 10;
|
||||
private const int SecurityFromEnd = 6;
|
||||
private const string SecurityHeading = "Security";
|
||||
private const int SecurityFromEndOf25 = 6; // a log with no header to tell: the columns up to the water's temperature
|
||||
private const int MinimumColumns = 17;
|
||||
|
||||
public HaslerTape(IReadOnlyList<TapeSample> samples)
|
||||
@@ -77,9 +80,16 @@ public sealed class HaslerTape
|
||||
double distance = 0;
|
||||
TapeSample? previous = null;
|
||||
|
||||
int securityFromEnd = SecurityFromEndOf25;
|
||||
foreach (var raw in text.Split('\n'))
|
||||
{
|
||||
var columns = raw.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
|
||||
int heading = Array.IndexOf(columns, SecurityHeading);
|
||||
if (heading >= 0)
|
||||
{
|
||||
securityFromEnd = columns.Length - heading;
|
||||
continue;
|
||||
}
|
||||
if (columns.Length < MinimumColumns
|
||||
|| !Number(columns[TimeColumn], out double time)
|
||||
|| !Number(columns[VelocityColumn], out double velocity))
|
||||
@@ -88,7 +98,7 @@ public sealed class HaslerTape
|
||||
Number(columns[BrakePressColumn], out double brake);
|
||||
Number(columns[PipePressColumn], out double pipe);
|
||||
Number(columns[MotorCurrentColumn], out double current);
|
||||
bool security = columns[^SecurityFromEnd] == "1";
|
||||
bool security = securityFromEnd <= columns.Length && columns[^securityFromEnd] == "1";
|
||||
|
||||
double speed = Math.Abs(velocity);
|
||||
if (previous is { } p)
|
||||
|
||||
Reference in New Issue
Block a user