mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-21 07:44:58 +01:00
fix(tapes): a tape followed live reads only what was added, and a stall, a shared black box or a gap are told right
At a higher time speed the simulator's log grows many times faster, and the live view read and split the whole file every two seconds. A followed tape now keeps its reader and reads only the bytes added; one begun anew (shorter, its end no longer what was read, or its time going back) is read whole. From the review: a gap is over two seconds, above the frame the simulator holds to a second, so a stall is driving or standing; a black box's time ends by the start of the next one, as a downloaded one was last written later; the summary shows what was recorded and what wasn't, and the trace breaks off at a gap; the cab panel's wheels compare signed speeds and stay clear of the gauges; each box's name is parsed once per listing.
This commit is contained in:
@@ -60,13 +60,15 @@ public class BlackBoxListingTests
|
||||
public void Black_boxes_with_no_launch_noted_go_with_the_tapes_written_about_the_same_time()
|
||||
{
|
||||
var early = new DateTime(2026, 3, 1, 12, 0, 0, DateTimeKind.Utc);
|
||||
// named in the local time they started at, whatever the zone the tests run in
|
||||
string first = Box("td", early.AddHours(-1)), second = Box("td", early.AddMinutes(30));
|
||||
var installation = new TestInstallation(new InMemoryFileSystem()
|
||||
.WithFile(Log("a.dat"), "t")
|
||||
.WithFile(Log("td_2026-03-01_11-00-00.blackbox"), "b")
|
||||
.WithFile(Log("td_2026-03-01_12-30-00.blackbox"), "b")
|
||||
.WithFile(Log(first), "b")
|
||||
.WithFile(Log(second), "b")
|
||||
.WrittenAt(Log("a.dat"), early)
|
||||
.WrittenAt(Log("td_2026-03-01_11-00-00.blackbox"), early.AddSeconds(2))
|
||||
.WrittenAt(Log("td_2026-03-01_12-30-00.blackbox"), early.AddHours(1)));
|
||||
.WrittenAt(Log(first), early.AddSeconds(2))
|
||||
.WrittenAt(Log(second), early.AddHours(1)));
|
||||
|
||||
var sessions = installation.Tapes.Sessions();
|
||||
|
||||
@@ -74,9 +76,9 @@ public class BlackBoxListingTests
|
||||
Assert.All(sessions, session => Assert.Null(session.Launch));
|
||||
// Newest first: the black box on its own, then the run with the tape.
|
||||
Assert.Empty(sessions[0].Tapes);
|
||||
Assert.EndsWith("12-30-00.blackbox", Assert.Single(sessions[0].BlackBoxes).Path);
|
||||
Assert.EndsWith(second, Assert.Single(sessions[0].BlackBoxes).Path);
|
||||
Assert.Single(sessions[1].Tapes);
|
||||
Assert.EndsWith("11-00-00.blackbox", Assert.Single(sessions[1].BlackBoxes).Path);
|
||||
Assert.EndsWith(first, Assert.Single(sessions[1].BlackBoxes).Path);
|
||||
Assert.Equal(early, sessions[1].StartedUtc);
|
||||
}
|
||||
|
||||
@@ -102,6 +104,31 @@ public class BlackBoxListingTests
|
||||
Assert.EndsWith(box, Assert.Single(session.BlackBoxes).Path);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_black_box_downloaded_later_takes_in_no_tapes_of_the_runs_after_it()
|
||||
{
|
||||
// Shared and downloaded two weeks later, so last written then; a run of its own with no launch noted since.
|
||||
var shared = new DateTime(2026, 3, 1, 12, 0, 0, DateTimeKind.Utc);
|
||||
var later = shared.AddDays(7);
|
||||
string old = Box("td", shared), own = Box("td", later);
|
||||
var installation = new TestInstallation(new InMemoryFileSystem()
|
||||
.WithFile(Log(old), "b").WrittenAt(Log(old), shared.AddDays(14))
|
||||
.WithFile(Log(own), "b").WrittenAt(Log(own), later.AddMinutes(30))
|
||||
.WithFile(Log("ra.dat"), "t").WrittenAt(Log("ra.dat"), later.AddMinutes(30).AddSeconds(1))
|
||||
.WithFile(Log("left.dat"), "t").WrittenAt(Log("left.dat"), later.AddMinutes(10)));
|
||||
|
||||
var recordings = StarterNG.Application.HaslerTapes.Recordings(new[]
|
||||
{
|
||||
new StarterNG.Application.BlackBoxRecording(Log(old), shared.AddDays(14), 1),
|
||||
new StarterNG.Application.BlackBoxRecording(Log(own), later.AddMinutes(30), 1),
|
||||
});
|
||||
Assert.EndsWith(own, StarterNG.Application.HaslerTapes.RecordingAt(later.AddMinutes(10), recordings)!.Path);
|
||||
|
||||
var mine = Assert.Single(installation.Tapes.Sessions(), session => session.Tapes.Count > 0);
|
||||
Assert.Equal(new[] { "left", "ra" }, mine.Tapes.Select(tape => tape.Vehicle).Order());
|
||||
Assert.EndsWith(own, Assert.Single(mine.BlackBoxes).Path);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_black_box_of_a_running_session_is_listed_while_it_is_written()
|
||||
{
|
||||
|
||||
@@ -111,6 +111,77 @@ public class HaslerTapeTests
|
||||
Assert.Equal(25 / 3.0 * 3.6, tape.AverageWithStopsKmh, 6);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_stall_of_the_simulator_a_little_over_a_second_is_driven_not_a_gap()
|
||||
{
|
||||
// a line every 0.05 s, as at 60 FPS, and one step of 1.017 s: the frame held to a second, and the frame after
|
||||
var text = new System.Text.StringBuilder(Header);
|
||||
double t = 0;
|
||||
for (int i = 0; i < 40; i++, t += 0.05)
|
||||
text.Append(Line(t, 100, 0, 0));
|
||||
t += 1.017 - 0.05;
|
||||
for (int i = 0; i < 40; i++, t += 0.05)
|
||||
text.Append(Line(t, 100, 0, 0));
|
||||
|
||||
var tape = HaslerTape.Parse(text.ToString());
|
||||
|
||||
Assert.Equal(0, tape.GapTime, 6);
|
||||
Assert.Equal(tape.Duration, tape.RunningTime, 6);
|
||||
Assert.Equal(tape.Duration * 100 / 3.6, tape.DistanceM, 6);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_tape_read_in_pieces_cut_anywhere_is_the_tape_read_whole()
|
||||
{
|
||||
string text = Header + Line(0, 18, 0, 0, command: "Set Velocity") + Line(1, 36, 0.45, 0) + Line(2, 36, 0, 400)
|
||||
+ Line(602, 36, 0, 0, security: 1) + Line(603, 0, 0, 0);
|
||||
var whole = HaslerTape.Parse(text);
|
||||
|
||||
for (int cut = 1; cut < text.Length; cut += 7)
|
||||
{
|
||||
var reader = new HaslerTape.Reader();
|
||||
reader.Feed(text[..cut]);
|
||||
reader.Feed(text[cut..]);
|
||||
Assert.Equal(whole.Samples, reader.Tape(final: true).Samples);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_line_not_ended_waits_for_its_end_while_the_tape_is_followed()
|
||||
{
|
||||
var reader = new HaslerTape.Reader();
|
||||
string line = Line(1, 36, 0, 0);
|
||||
reader.Feed(Header + Line(0, 36, 0, 0) + line[..20]);
|
||||
|
||||
Assert.Single(reader.Tape(final: false).Samples);
|
||||
Assert.Single(reader.Tape(final: false).Samples);
|
||||
reader.Feed(line[20..]);
|
||||
Assert.Equal(2, reader.Tape(final: false).Samples.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_followed_tape_reads_what_was_added_and_one_begun_anew_whole()
|
||||
{
|
||||
string path = TestInstallation.At("physicslog", "EU07-424.dat");
|
||||
var files = new InMemoryFileSystem().WithFile(path, Header + Line(0, 36, 0, 0));
|
||||
var tapes = new TestInstallation(files).Tapes;
|
||||
var file = Assert.Single(tapes.List());
|
||||
|
||||
Assert.Single(tapes.Load(file, follow: false)!.Samples);
|
||||
files.WithFile(path, Header + Line(0, 36, 0, 0) + Line(1, 36, 0, 0) + Line(2, 36, 0, 0));
|
||||
Assert.Equal(3, tapes.Load(file, follow: true)!.Samples.Count);
|
||||
|
||||
// begun anew, and already longer than was read: its time goes back
|
||||
files.WithFile(path, Header + Line(0, 72, 0, 0) + Line(1, 72, 0, 0) + Line(2, 72, 0, 0) + Line(3, 72, 0, 0));
|
||||
var tape = tapes.Load(file, follow: true)!;
|
||||
Assert.Equal(4, tape.Samples.Count);
|
||||
Assert.All(tape.Samples, s => Assert.Equal(72, s.SpeedKmh, 6));
|
||||
|
||||
// begun anew, and shorter
|
||||
files.WithFile(path, Header + Line(0, 18, 0, 0));
|
||||
Assert.Equal(18, Assert.Single(tapes.Load(file, follow: true)!.Samples).SpeedKmh, 6);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_sample_under_a_point_of_the_tape_is_found_by_time_and_by_distance()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user